wish i could preview items but too lazy

main
bel 2025-05-05 22:10:04 -06:00
parent 0271f84948
commit bf23d6a9cf
3 changed files with 29 additions and 12 deletions

View File

@ -8,10 +8,10 @@
<div>
{{ range feeds }}
<div>
<h4><a href="?edit={{.Entry.ID}}">{{ .Version.URL }}</a></h4>
<div>{{ .Version.Created }} (last {{ .Execution.Executed }})</div>
<div>@{{ .Version.Cron }} ~"{{ .Version.Pattern }}"</div>
<div>{{ .Version.WebhookMethod }} {{ .Version.WebhookURL }} | {{ .Version.WebhookBody }}</div>
<h3><code><a href="?edit={{.Entry.ID}}">{{ .Version.URL }}</a></code></h3>
<div>@<code>{{ .Version.Cron }}</code> ~<code>{{ .Version.Pattern }}</code></div>
<div><code>{{ .Version.WebhookMethod }} {{ .Version.WebhookURL }} | {{ .Version.WebhookBody }}</code></div>
<div>(last run {{ ago .Execution.Executed }} ago)</div>
</div>
{{ end }}
</div>
@ -20,17 +20,24 @@
<div>
<h3>
{{ if eq "" .editing.ID }}
New
{{ else }}
Update (<a href="?">clear</a>)
{{ end }}
{{ if eq "" .editing.ID }}
New
{{ else }}
Update <code><a target="_blank" href="{{ .editing_url }}">{{ .editing.URL }}</a></code> (<a href="?">clear</a>)
{{ end }}
</h3>
<form method="POST" action="/v1/feeds">
{{ range $k, $v := .editing }}
{{ if not (in $k "Created" "Deleted" "Updated" "ID") }}
<div>
<label for="{{ $k }}">{{ $k }}</label>
<label for="{{ $k }}">
{{ $k }}
{{- if eq $k "URL" }}
(hint: nyaa://?q=show)
{{ else if eq $k "WebhookURL" }}
(hint: vpntor:///outdir)
{{ end }}
</label>
<input name="{{ $k }}" type="text" value="{{ $v }}"/>
</div>
{{ end }}

View File

@ -8,6 +8,7 @@ import (
"show-rss/src/feeds"
"slices"
"text/template"
"time"
)
var dir = func() string {
@ -65,6 +66,9 @@ func (h Handler) uiIndex(w http.ResponseWriter, r *http.Request) error {
"in": func(k string, v ...string) bool {
return slices.Contains(v, k)
},
"ago": func(t time.Time) time.Duration {
return time.Since(t)
},
})
tmpl, err := tmpl.Parse(string(b))
@ -79,6 +83,8 @@ func (h Handler) uiIndex(w http.ResponseWriter, r *http.Request) error {
var m map[string]any
json.Unmarshal(b, &m)
args["editing"] = m
args["editing_url"], _ = editing.FetchURL()
}
return tmpl.Execute(w, args)

View File

@ -139,7 +139,11 @@ func proxyFetch(ctx context.Context, u string) (string, error) {
}
func (feed Feed) FetchURL() (*url.URL, error) {
u, err := url.Parse(feed.Version.URL)
return feed.Version.FetchURL()
}
func (version Version) FetchURL() (*url.URL, error) {
u, err := url.Parse(version.URL)
if err != nil {
return nil, err
}
@ -148,7 +152,7 @@ func (feed Feed) FetchURL() (*url.URL, error) {
case "nyaa": // `nyaa://?q=A B` to `https://nyaa.si/?page=rss&q=A%20B&c=0_0&f=0`
q := u.Query()
if q.Get("q") == "" {
return nil, fmt.Errorf("invalid nyaa:// (%s): no ?q", feed.Version.URL)
return nil, fmt.Errorf("invalid nyaa:// (%s): no ?q", version.URL)
}
q.Set("page", "rss")