diff options
Diffstat (limited to 'apps/workers')
| -rw-r--r-- | apps/workers/workers/feedWorker.ts | 29 |
1 files changed, 29 insertions, 0 deletions
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) |
