From 4a13c36da50f6b3171d817edebefe96ba85dc666 Mon Sep 17 00:00:00 2001 From: kamtschatka Date: Mon, 28 Oct 2024 02:51:00 +0100 Subject: feature: Archive videos using yt-dlp. Fixes #215 (#525) * Allow downloading more content from a webpage and index it #215 Added a worker that allows downloading videos depending on the environment variables refactored the code a bit added new video asset updated documentation * Some tweaks * Drop the dependency on the yt-dlp wrapper * Update openapi specs * Dont log an error when the url is not supported * Better handle supported websites that dont download anything --------- Co-authored-by: Mohamed Bassem --- apps/workers/workerUtils.ts | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 apps/workers/workerUtils.ts (limited to 'apps/workers/workerUtils.ts') diff --git a/apps/workers/workerUtils.ts b/apps/workers/workerUtils.ts new file mode 100644 index 00000000..e93d241b --- /dev/null +++ b/apps/workers/workerUtils.ts @@ -0,0 +1,48 @@ +import { eq } from "drizzle-orm"; + +import { db, HoarderDBTransaction } from "@hoarder/db"; +import { assets, AssetTypes, bookmarks } from "@hoarder/db/schema"; + +type DBAssetType = typeof assets.$inferInsert; + +export async function updateAsset( + oldAssetId: string | undefined, + newAsset: DBAssetType, + txn: HoarderDBTransaction, +) { + if (oldAssetId) { + await txn.delete(assets).where(eq(assets.id, oldAssetId)); + } + + await txn.insert(assets).values(newAsset); +} + +export async function getBookmarkDetails(bookmarkId: string) { + const bookmark = await db.query.bookmarks.findFirst({ + where: eq(bookmarks.id, bookmarkId), + with: { + link: true, + assets: true, + }, + }); + + if (!bookmark || !bookmark.link) { + throw new Error("The bookmark either doesn't exist or is not a link"); + } + return { + url: bookmark.link.url, + userId: bookmark.userId, + screenshotAssetId: bookmark.assets.find( + (a) => a.assetType == AssetTypes.LINK_SCREENSHOT, + )?.id, + imageAssetId: bookmark.assets.find( + (a) => a.assetType == AssetTypes.LINK_BANNER_IMAGE, + )?.id, + fullPageArchiveAssetId: bookmark.assets.find( + (a) => a.assetType == AssetTypes.LINK_FULL_PAGE_ARCHIVE, + )?.id, + videoAssetId: bookmark.assets.find( + (a) => a.assetType == AssetTypes.LINK_VIDEO, + )?.id, + }; +} -- cgit v1.2.3-70-g09d2