From 1e5c575e16c8a9e6bd7592e83bea53af7f359e15 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sun, 6 Oct 2024 14:33:40 +0000 Subject: refactor: Start tracking bookmark assets in the assets table --- apps/web/app/api/assets/route.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'apps/web/app/api/assets/route.ts') diff --git a/apps/web/app/api/assets/route.ts b/apps/web/app/api/assets/route.ts index 9028f556..0e52ff93 100644 --- a/apps/web/app/api/assets/route.ts +++ b/apps/web/app/api/assets/route.ts @@ -2,6 +2,7 @@ import { createContextFromRequest } from "@/server/api/client"; import { TRPCError } from "@trpc/server"; import type { ZUploadResponse } from "@hoarder/shared/types/uploads"; +import { assets, AssetTypes } from "@hoarder/db/schema"; import { newAssetId, saveAsset, @@ -43,8 +44,22 @@ export async function POST(request: Request) { return Response.json({ error: "Bad request" }, { status: 400 }); } - const assetId = newAssetId(); const fileName = data.name; + const [assetDb] = await ctx.db + .insert(assets) + .values({ + id: newAssetId(), + // Initially, uploads are uploaded for unknown purpose + // And without an attached bookmark. + assetType: AssetTypes.UNKNOWN, + bookmarkId: null, + userId: ctx.user.id, + contentType, + size: data.size, + fileName, + }) + .returning(); + const assetId = assetDb.id; await saveAsset({ userId: ctx.user.id, -- cgit v1.2.3-70-g09d2