mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-22 02:41:23 +02:00
feat: add diff, fix: configurable url
This commit is contained in:
parent
7adf624e95
commit
aa04904a72
@ -4,9 +4,10 @@
|
|||||||
<ul class="list list-gap-14 list-collapsible">
|
<ul class="list list-gap-14 list-collapsible">
|
||||||
{{ range $i, $watch := .ChangeDetections }}
|
{{ range $i, $watch := .ChangeDetections }}
|
||||||
<li {{ if shouldCollapse $i $.CollapseAfter }}class="list-collapsible-item" style="--animation-delay: {{ itemAnimationDelay $i $.CollapseAfter }};"{{ end }}>
|
<li {{ if shouldCollapse $i $.CollapseAfter }}class="list-collapsible-item" style="--animation-delay: {{ itemAnimationDelay $i $.CollapseAfter }};"{{ end }}>
|
||||||
<a class="size-h4 block text-truncate color-primary-if-not-visited" href="{{ $watch.Url }}" target="_blank" rel="noreferrer">{{ .Name }}</a>
|
<a class="size-h4 block text-truncate color-primary-if-not-visited" href="{{ $watch.URL }}" target="_blank" rel="noreferrer">{{ .Name }}</a>
|
||||||
<ul class="list-horizontal-text">
|
<ul class="list-horizontal-text">
|
||||||
<li title="{{ $watch.LastChanged | formatTime }}" {{ dynamicRelativeTimeAttrs $watch.LastChanged }}>{{ $watch.LastChanged | relativeTime }}</li>
|
<li title="{{ $watch.LastChanged | formatTime }}" {{ dynamicRelativeTimeAttrs $watch.LastChanged }}>{{ $watch.LastChanged | relativeTime }}</li>
|
||||||
|
<li class="shrink min-width-0"><a class="visited-indicator text-truncate block" href="{{ $watch.DiffURL }}" target="_blank" rel="noreferrer">diff: {{ $watch.DiffDisplay | }}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
@ -4,25 +4,29 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type changeDetectionResponseJson struct {
|
type changeDetectionResponseJson struct {
|
||||||
Name string `json:"title"`
|
Name string `json:"title"`
|
||||||
Url string `json:"url"`
|
URL string `json:"url"`
|
||||||
LastChanged int `json:"last_changed"`
|
LastChanged int `json:"last_changed"`
|
||||||
|
UUID string `json:"uuid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func parseLastChangeTime(t int) time.Time {
|
func parseLastChangeTime(t int) time.Time {
|
||||||
parsedTime := time.Unix(int64(t), 0)
|
parsedTime := time.Unix(int64(t), 0)
|
||||||
return parsedTime
|
return parsedTime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FetchLatestDetectedChanges(request_url string, watches []string, token string) (ChangeWatches, error) {
|
||||||
func FetchLatestDetectedChanges(watches []string, token string) (ChangeWatches, error) {
|
|
||||||
changeWatches := make(ChangeWatches, 0, len(watches))
|
changeWatches := make(ChangeWatches, 0, len(watches))
|
||||||
|
|
||||||
|
if request_url == "" {
|
||||||
|
request_url = "https://www.changedetection.io"
|
||||||
|
}
|
||||||
|
|
||||||
if len(watches) == 0 {
|
if len(watches) == 0 {
|
||||||
return changeWatches, nil
|
return changeWatches, nil
|
||||||
}
|
}
|
||||||
@ -30,7 +34,7 @@ func FetchLatestDetectedChanges(watches []string, token string) (ChangeWatches,
|
|||||||
requests := make([]*http.Request, len(watches))
|
requests := make([]*http.Request, len(watches))
|
||||||
|
|
||||||
for i, repository := range watches {
|
for i, repository := range watches {
|
||||||
request, _ := http.NewRequest("GET", fmt.Sprintf("https://changedetection.knhash.in/api/v1/watch/%s", repository), nil)
|
request, _ := http.NewRequest("GET", fmt.Sprintf("%s/api/v1/watch/%s", request_url, repository), nil)
|
||||||
|
|
||||||
if token != "" {
|
if token != "" {
|
||||||
request.Header.Add("x-api-key", token)
|
request.Header.Add("x-api-key", token)
|
||||||
@ -60,8 +64,10 @@ func FetchLatestDetectedChanges(watches []string, token string) (ChangeWatches,
|
|||||||
|
|
||||||
changeWatches = append(changeWatches, ChangeWatch{
|
changeWatches = append(changeWatches, ChangeWatch{
|
||||||
Name: watch.Name,
|
Name: watch.Name,
|
||||||
Url: watch.Url,
|
URL: watch.URL,
|
||||||
LastChanged: parseLastChangeTime(watch.LastChanged),
|
LastChanged: parseLastChangeTime(watch.LastChanged),
|
||||||
|
DiffURL: request_url + "/diff/" + watch.UUID,
|
||||||
|
DiffDisplay: strings.Split(watch.UUID, "-")[len(strings.Split(watch.UUID, "-"))-1],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +50,10 @@ type AppReleases []AppRelease
|
|||||||
|
|
||||||
type ChangeWatch struct {
|
type ChangeWatch struct {
|
||||||
Name string
|
Name string
|
||||||
Url string
|
URL string
|
||||||
LastChanged time.Time
|
LastChanged time.Time
|
||||||
|
DiffURL string
|
||||||
|
DiffDisplay string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChangeWatches []ChangeWatch
|
type ChangeWatches []ChangeWatch
|
||||||
|
@ -11,11 +11,12 @@ import (
|
|||||||
|
|
||||||
type ChangeDetections struct {
|
type ChangeDetections struct {
|
||||||
widgetBase `yaml:",inline"`
|
widgetBase `yaml:",inline"`
|
||||||
ChangeDetections feed.ChangeWatches `yaml:"-"`
|
ChangeDetections feed.ChangeWatches `yaml:"-"`
|
||||||
Watches []string `yaml:"watches"`
|
RequestURL string `yaml:"request_url"`
|
||||||
Token OptionalEnvString `yaml:"token"`
|
Watches []string `yaml:"watches"`
|
||||||
Limit int `yaml:"limit"`
|
Token OptionalEnvString `yaml:"token"`
|
||||||
CollapseAfter int `yaml:"collapse-after"`
|
Limit int `yaml:"limit"`
|
||||||
|
CollapseAfter int `yaml:"collapse-after"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *ChangeDetections) Initialize() error {
|
func (widget *ChangeDetections) Initialize() error {
|
||||||
@ -33,7 +34,7 @@ func (widget *ChangeDetections) Initialize() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *ChangeDetections) Update(ctx context.Context) {
|
func (widget *ChangeDetections) Update(ctx context.Context) {
|
||||||
watches, err := feed.FetchLatestDetectedChanges(widget.Watches, string(widget.Token))
|
watches, err := feed.FetchLatestDetectedChanges(widget.RequestURL, widget.Watches, string(widget.Token))
|
||||||
|
|
||||||
if !widget.canContinueUpdateAfterHandlingErr(err) {
|
if !widget.canContinueUpdateAfterHandlingErr(err) {
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user