feat(web): paste-a-URL handler — add an arbitrary video + summarize (Feature 2)

POST /paste: parse the video id, fetch metadata via the VideoFetcher port (Data
API, ungated), upsert a subscription-less row scoped to the user (idempotent =
dedup), and — unless already summarized — RequestSummarize + start immediate
processing through the SAME globalFetchGate as the Summarize button. Explicit
paste overrides the recency window; a captionless video degrades to the honest
'no transcript' terminal state via the engine (ADR-010). Invalid URL -> 400,
not-found -> 404, both add nothing. Route mounts only when a Fetcher is wired.

Moves the video-not-found sentinel to domain (shared by adapter + web, no
cross-adapter coupling). Tests: valid add+queue, invalid, not-found, dedup.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-09 21:54:28 +02:00
co-authored by Claude Opus 4.8
parent 2907801aca
commit 62acfee2ed
6 changed files with 214 additions and 8 deletions
+2 -2
View File
@@ -53,7 +53,7 @@ func TestVideoByIDNotFound(t *testing.T) {
_, _ = w.Write([]byte(`{"items":[]}`))
})
_, err := a.VideoByID(context.Background(), "u1", "missingvid0")
if !errors.Is(err, ErrVideoNotFound) {
t.Fatalf("VideoByID for missing id = %v, want ErrVideoNotFound", err)
if !errors.Is(err, domain.ErrVideoNotFound) {
t.Fatalf("VideoByID for missing id = %v, want domain.ErrVideoNotFound", err)
}
}
+1 -6
View File
@@ -18,7 +18,6 @@ package youtube
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
@@ -32,10 +31,6 @@ import (
"gitea.d-ma.be/mathias/tapir/internal/ports"
)
// ErrVideoNotFound is returned by VideoByID when an id resolves to no video
// (deleted, private, or a typo'd paste). Callers map it to an honest user message.
var ErrVideoNotFound = errors.New("youtube: video not found")
// defaultBaseURL is the YouTube Data API v3 root. Overridable via Config.BaseURL
// (tests point it at an httptest server).
const defaultBaseURL = "https://www.googleapis.com/youtube/v3"
@@ -267,7 +262,7 @@ func (a *Adapter) VideoByID(ctx context.Context, userID, videoID string) (domain
return domain.Video{}, fmt.Errorf("video by id %q: %w", videoID, err)
}
if len(resp.Items) == 0 {
return domain.Video{}, fmt.Errorf("video %q: %w", videoID, ErrVideoNotFound)
return domain.Video{}, fmt.Errorf("video %q: %w", videoID, domain.ErrVideoNotFound)
}
it := resp.Items[0]
return domain.Video{