From a770e55520245b7afc2b7a30aa6127eebcb6ea0d Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sun, 22 Sep 2024 14:56:19 +0000 Subject: feature(web): Show attachments and allow users to manipulate them. --- packages/trpc/lib/attachments.ts | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 packages/trpc/lib/attachments.ts (limited to 'packages/trpc/lib') diff --git a/packages/trpc/lib/attachments.ts b/packages/trpc/lib/attachments.ts new file mode 100644 index 00000000..6fe1ef40 --- /dev/null +++ b/packages/trpc/lib/attachments.ts @@ -0,0 +1,42 @@ +import { z } from "zod"; + +import { AssetTypes } from "@hoarder/db/schema"; +import { ZAssetType, zAssetTypesSchema } from "@hoarder/shared/types/bookmarks"; + +export function mapDBAssetTypeToUserType(assetType: AssetTypes): ZAssetType { + const map: Record> = { + [AssetTypes.LINK_SCREENSHOT]: "screenshot", + [AssetTypes.LINK_FULL_PAGE_ARCHIVE]: "fullPageArchive", + [AssetTypes.LINK_BANNER_IMAGE]: "bannerImage", + }; + return map[assetType]; +} + +export function mapSchemaAssetTypeToDB( + assetType: z.infer, +): AssetTypes { + const map: Record = { + screenshot: AssetTypes.LINK_SCREENSHOT, + fullPageArchive: AssetTypes.LINK_FULL_PAGE_ARCHIVE, + bannerImage: AssetTypes.LINK_BANNER_IMAGE, + }; + return map[assetType]; +} + +export function humanFriendlyNameForAssertType(type: ZAssetType) { + const map: Record = { + screenshot: "Screenshot", + fullPageArchive: "Full Page Archive", + bannerImage: "Banner Image", + }; + return map[type]; +} + +export function isAllowedToAttachAsset(type: ZAssetType) { + const map: Record = { + screenshot: true, + fullPageArchive: false, + bannerImage: true, + }; + return map[type]; +} -- cgit v1.2.3-70-g09d2