aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc/lib/attachments.ts
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-09-22 14:56:19 +0000
committerMohamedBassem <me@mbassem.com>2024-09-22 15:04:20 +0000
commita770e55520245b7afc2b7a30aa6127eebcb6ea0d (patch)
tree7a2e4041e2d16413ee0e8dd060be41b58253c995 /packages/trpc/lib/attachments.ts
parent55f5c7f40d6569d0769a3b7a9060db5ec1d3b93b (diff)
downloadkarakeep-a770e55520245b7afc2b7a30aa6127eebcb6ea0d.tar.zst
feature(web): Show attachments and allow users to manipulate them.
Diffstat (limited to 'packages/trpc/lib/attachments.ts')
-rw-r--r--packages/trpc/lib/attachments.ts42
1 files changed, 42 insertions, 0 deletions
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, z.infer<typeof zAssetTypesSchema>> = {
+ [AssetTypes.LINK_SCREENSHOT]: "screenshot",
+ [AssetTypes.LINK_FULL_PAGE_ARCHIVE]: "fullPageArchive",
+ [AssetTypes.LINK_BANNER_IMAGE]: "bannerImage",
+ };
+ return map[assetType];
+}
+
+export function mapSchemaAssetTypeToDB(
+ assetType: z.infer<typeof zAssetTypesSchema>,
+): AssetTypes {
+ const map: Record<ZAssetType, AssetTypes> = {
+ 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<ZAssetType, string> = {
+ screenshot: "Screenshot",
+ fullPageArchive: "Full Page Archive",
+ bannerImage: "Banner Image",
+ };
+ return map[type];
+}
+
+export function isAllowedToAttachAsset(type: ZAssetType) {
+ const map: Record<ZAssetType, boolean> = {
+ screenshot: true,
+ fullPageArchive: false,
+ bannerImage: true,
+ };
+ return map[type];
+}