From f95563e84973f55aecdc1517f14d0ec405d3cc41 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Sun, 27 Apr 2025 12:56:33 -0600 Subject: [PATCH] can fetch zenshuu with tag --- src/feeds/db.go | 17 +++++++++++------ src/feeds/db_test.go | 5 ++++- src/feeds/http.go | 4 ++++ src/feeds/http_integration_test.go | 8 ++++++-- src/feeds/item.go | 1 + 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/feeds/db.go b/src/feeds/db.go index 78cfa2c..750d36b 100644 --- a/src/feeds/db.go +++ b/src/feeds/db.go @@ -30,6 +30,7 @@ type ( URL string Cron string Pattern string + Tag string } Execution struct { @@ -97,6 +98,7 @@ func Get(ctx context.Context, id string) (Feed, error) { versions.url AS "Version.URL", versions.cron AS "Version.Cron", versions.pattern AS "Version.Pattern", + versions.tag AS "Version.Tag", ( SELECT executed_at FROM "feed.executions" @@ -134,7 +136,8 @@ func oldGet(ctx context.Context, id string) (Feed, error) { "feed.current_versions".versions_created_at AS Created, "feed.current_versions".url AS URL, "feed.current_versions".cron AS Cron, - "feed.current_versions".pattern AS Pattern + "feed.current_versions".pattern AS Pattern, + "feed.current_versions".tag AS Tag FROM "feed.current_versions" JOIN @@ -187,7 +190,7 @@ func (feed Feed) Executed(ctx context.Context) error { ) } -func Insert(ctx context.Context, url, cron, pattern string) (string, error) { +func Insert(ctx context.Context, url, cron, pattern, tag string) (string, error) { if err := initDB(ctx); err != nil { return "", err } @@ -206,16 +209,17 @@ func Insert(ctx context.Context, url, cron, pattern string) (string, error) { created_at, url, cron, - pattern - ) VALUES ($4, $5, $6, $7, $8); + pattern, + tag + ) VALUES ($4, $5, $6, $7, $8, $9); COMMIT; `, id, now, now, - id, now, url, cron, pattern, + id, now, url, cron, pattern, tag, ) } -func (feed Feed) Update(ctx context.Context, url, cron, pattern *string) error { +func (feed Feed) Update(ctx context.Context, url, cron, pattern, tag *string) error { return io.EOF } @@ -276,6 +280,7 @@ func initDB(ctx context.Context) error { `ALTER TABLE "feed.versions" ADD COLUMN url TEXT NOT NULL`, `ALTER TABLE "feed.versions" ADD COLUMN cron TEXT NOT NULL DEFAULT '0 0 * * *'`, `ALTER TABLE "feed.versions" ADD COLUMN pattern TEXT NOT NULL DEFAULT ''`, + `ALTER TABLE "feed.versions" ADD COLUMN tag TEXT NOT NULL DEFAULT ''`, `CREATE TABLE "feed.executions" ( entries_id TEXT, diff --git a/src/feeds/db_test.go b/src/feeds/db_test.go index 05fa5ea..8840669 100644 --- a/src/feeds/db_test.go +++ b/src/feeds/db_test.go @@ -15,7 +15,7 @@ func TestFeeds(t *testing.T) { t.Run("crud", func(t *testing.T) { ctx := db.Test(t, ctx) - id, err := feeds.Insert(ctx, "url", "cron", "pattern") + id, err := feeds.Insert(ctx, "url", "cron", "pattern", "tag") if err != nil { t.Fatal("cannot insert:", err) } @@ -51,6 +51,9 @@ func TestFeeds(t *testing.T) { if got.Version.Pattern != "pattern" { t.Error("bad version.pattern") } + if got.Version.Tag != "tag" { + t.Error("bad version.tag") + } if !got.Execution.Executed.IsZero() { t.Error("execution.executed") diff --git a/src/feeds/http.go b/src/feeds/http.go index 31f7cdd..6f8cf64 100644 --- a/src/feeds/http.go +++ b/src/feeds/http.go @@ -64,6 +64,9 @@ func (feed Feed) Fetch(ctx context.Context) (Items, error) { result := make(Items, 0, len(gfeed.Items)) for _, gitem := range gfeed.Items { + if gitem.Author == nil { + gitem.Author = &gofeed.Person{} + } if matches := slices.DeleteFunc(append([]string{ gitem.Title, gitem.Description, @@ -97,6 +100,7 @@ func (feed Feed) Fetch(ctx context.Context) (Items, error) { Links: links, Preview: preview, Body: body, + Tag: feed.Version.Tag, }) } diff --git a/src/feeds/http_integration_test.go b/src/feeds/http_integration_test.go index 0923aec..5779b7c 100644 --- a/src/feeds/http_integration_test.go +++ b/src/feeds/http_integration_test.go @@ -28,9 +28,10 @@ func TestIntegrationFeedFetchProxy(t *testing.T) { }, Version: feeds.Version{ Created: created, - URL: "http://rss.slashdot.org/Slashdot/slashdotMain?format=usm", + URL: "https://nyaa.si/?f=0&c=0_0&q=Zenshuu.+WEB+ToonsHub+AMZN&page=rss", Cron: "* * * * *", - Pattern: ".*", + Pattern: `\.torrent$`, + Tag: `outdir:/data/completed-rss/Zenshuu`, }, Execution: feeds.Execution{ Executed: created.Add(-2 * time.Second), @@ -44,5 +45,8 @@ func TestIntegrationFeedFetchProxy(t *testing.T) { } for i, item := range items { t.Logf("[%d] %+v", i, item) + if item.Tag != "outdir:/data/completed-rss/Zenshuu" { + t.Errorf("[%d] wrong tag: %s", i, item.Tag) + } } } diff --git a/src/feeds/item.go b/src/feeds/item.go index 6c9f33d..228de64 100644 --- a/src/feeds/item.go +++ b/src/feeds/item.go @@ -7,4 +7,5 @@ type Item struct { Links []string Preview string Body string + Tag string }