diff options
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/web/components/settings/FeedSettings.tsx | 47 | ||||
| -rw-r--r-- | apps/workers/workers/feedWorker.ts | 29 |
2 files changed, 76 insertions, 0 deletions
diff --git a/apps/web/components/settings/FeedSettings.tsx b/apps/web/components/settings/FeedSettings.tsx index f14e0841..23b639e4 100644 --- a/apps/web/components/settings/FeedSettings.tsx +++ b/apps/web/components/settings/FeedSettings.tsx @@ -71,6 +71,7 @@ export function FeedsEditorDialog() { name: "", url: "", enabled: true, + importTags: false, }, }); @@ -142,6 +143,28 @@ export function FeedsEditorDialog() { ); }} /> + <FormField + control={form.control} + name="importTags" + render={({ field }) => { + return ( + <FormItem className="flex flex-row items-center justify-between rounded-lg border p-3"> + <div className="space-y-0.5"> + <FormLabel>Import Tags</FormLabel> + <div className="text-sm text-muted-foreground"> + Automatically import categories from RSS feed as tags + </div> + </div> + <FormControl> + <Switch + checked={field.value} + onCheckedChange={field.onChange} + /> + </FormControl> + </FormItem> + ); + }} + /> </form> </Form> <DialogFooter> @@ -177,6 +200,7 @@ export function EditFeedDialog({ feed }: { feed: ZFeed }) { feedId: feed.id, name: feed.name, url: feed.url, + importTags: feed.importTags, }); } }, [open]); @@ -196,6 +220,7 @@ export function EditFeedDialog({ feed }: { feed: ZFeed }) { feedId: feed.id, name: feed.name, url: feed.url, + importTags: feed.importTags, }, }); return ( @@ -266,6 +291,28 @@ export function EditFeedDialog({ feed }: { feed: ZFeed }) { ); }} /> + <FormField + control={form.control} + name="importTags" + render={({ field }) => { + return ( + <FormItem className="flex flex-row items-center justify-between rounded-lg border p-3"> + <div className="space-y-0.5"> + <FormLabel>Import Tags</FormLabel> + <div className="text-sm text-muted-foreground"> + Automatically import categories from RSS feed as tags + </div> + </div> + <FormControl> + <Switch + checked={field.value} + onCheckedChange={field.onChange} + /> + </FormControl> + </FormItem> + ); + }} + /> </form> </Form> <DialogFooter> diff --git a/apps/workers/workers/feedWorker.ts b/apps/workers/workers/feedWorker.ts index f86e7424..0dfc5399 100644 --- a/apps/workers/workers/feedWorker.ts +++ b/apps/workers/workers/feedWorker.ts @@ -154,6 +154,8 @@ async function run(req: DequeuedJob<ZFeedRequestSchema>) { id: z.coerce.string(), link: z.string().optional(), guid: z.string().optional(), + title: z.string().optional(), + categories: z.array(z.string()).optional(), }); const feedItems = unparseFeedData.items @@ -209,11 +211,38 @@ async function run(req: DequeuedJob<ZFeedRequestSchema>) { trpcClient.bookmarks.createBookmark({ type: BookmarkTypes.LINK, url: item.link!, + title: item.title, source: "rss", }), ), ); + // If importTags is enabled, attach categories as tags to the created bookmarks + if (feed.importTags) { + await Promise.allSettled( + newEntries.map(async (item, idx) => { + const bookmark = createdBookmarks[idx]; + if ( + bookmark.status === "fulfilled" && + item.categories && + item.categories.length > 0 + ) { + try { + await trpcClient.bookmarks.updateTags({ + bookmarkId: bookmark.value.id, + attach: item.categories.map((tagName) => ({ tagName })), + detach: [], + }); + } catch (error) { + logger.warn( + `[feed][${jobId}] Failed to attach tags to bookmark ${bookmark.value.id}: ${error}`, + ); + } + } + }), + ); + } + // It's ok if this is not transactional as the bookmarks will get linked in the next iteration. await db .insert(rssFeedImportsTable) |
