待ち行列への登録と状態表示を追加(新着からの登録、/queue、DATABASE_URL)

This commit is contained in:
2026-10-03 19:07:53 +09:00
parent a71b915c81
commit 4a02526e76
20 changed files with 1146 additions and 14 deletions
+23 -3
View File
@@ -1,6 +1,7 @@
package web
import (
"context"
"embed"
"html/template"
"io/fs"
@@ -8,6 +9,8 @@ import (
"net/http"
"sync"
"time"
"gitea.kazu634.com/kazu634/tver/internal/store"
)
//go:embed templates/*.html static/*
@@ -16,10 +19,22 @@ var assets embed.FS
type page struct {
Title string
Newer *newerView
Queue *queueView
}
type JobStore interface {
Enqueue(context.Context, store.Episode, string) (store.Job, bool, error)
EpisodeStatuses(context.Context, []string) (map[string]string, error)
ListJobs(context.Context, string, int) ([]store.Job, error)
GetJob(context.Context, int64) (store.Job, error)
Retry(context.Context, int64) error
RetryEpisode(context.Context, string) error
CancelQueued(context.Context, int64) error
}
type server struct {
fetcher NewerFetcher
jobs JobStore
now func() time.Time
logger *log.Logger
zone *time.Location
@@ -28,7 +43,7 @@ type server struct {
cache map[string]cacheEntry
}
func NewHandler(fetcher NewerFetcher, now func() time.Time, logger *log.Logger) http.Handler {
func NewHandler(fetcher NewerFetcher, jobs JobStore, now func() time.Time, logger *log.Logger) http.Handler {
tmpl := template.Must(template.ParseFS(assets, "templates/*.html"))
staticFiles, err := fs.Sub(assets, "static")
if err != nil {
@@ -38,7 +53,7 @@ func NewHandler(fetcher NewerFetcher, now func() time.Time, logger *log.Logger)
if err != nil {
panic(err)
}
s := &server{fetcher: fetcher, now: now, logger: logger, zone: zone, tmpl: tmpl, cache: make(map[string]cacheEntry)}
s := &server{fetcher: fetcher, jobs: jobs, now: now, logger: logger, zone: zone, tmpl: tmpl, cache: make(map[string]cacheEntry)}
mux := http.NewServeMux()
mux.Handle("GET /static/", http.StripPrefix("/static/", http.FileServerFS(staticFiles)))
mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, _ *http.Request) {
@@ -47,8 +62,13 @@ func NewHandler(fetcher NewerFetcher, now func() time.Time, logger *log.Logger)
})
mux.HandleFunc("GET /{$}", s.home)
mux.HandleFunc("GET /newer", s.newerFragment)
mux.HandleFunc("POST /episodes/enqueue", s.enqueue)
mux.HandleFunc("POST /episodes/retry", s.retryEpisode)
mux.HandleFunc("GET /queue", s.queuePage)
mux.HandleFunc("GET /queue/list", s.queueFragment)
mux.HandleFunc("POST /jobs/{id}/retry", s.retryJob)
mux.HandleFunc("POST /jobs/{id}/cancel", s.cancelJob)
for path, title := range map[string]string{
"GET /queue": "待ち行列",
"GET /subscriptions": "登録番組",
"GET /library": "ライブラリ",
} {