can fetch zenshuu with tag
parent
ba429f6028
commit
f95563e849
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,4 +7,5 @@ type Item struct {
|
|||
Links []string
|
||||
Preview string
|
||||
Body string
|
||||
Tag string
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue