diff options
| author | kamtschatka <simon.schatka@gmx.at> | 2024-10-28 02:51:00 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-28 01:51:00 +0000 |
| commit | 4a13c36da50f6b3171d817edebefe96ba85dc666 (patch) | |
| tree | 60ff553426493e7ae2460e73c3500a5525ba735c /apps/workers/workerUtils.ts | |
| parent | 3b7451f4d0727d597c0af0e602f0c74cf58999af (diff) | |
| download | karakeep-4a13c36da50f6b3171d817edebefe96ba85dc666.tar.zst | |
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 <me@mbassem.com>
Diffstat (limited to 'apps/workers/workerUtils.ts')
| -rw-r--r-- | apps/workers/workerUtils.ts | 48 |
1 files changed, 48 insertions, 0 deletions
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,
+ };
+}
|
