aboutsummaryrefslogtreecommitdiffstats
path: root/packages/shared
diff options
context:
space:
mode:
authorkamtschatka <simon.schatka@gmx.at>2024-07-01 13:03:53 +0200
committerGitHub <noreply@github.com>2024-07-01 12:03:53 +0100
commite6486465decd612f7e437abe904960a47ff359ce (patch)
treef36fd7efbcf2a083905061d8c5f1310f36350ced /packages/shared
parentccbff18a9763e458c07f46cb3a331062df14a9b9 (diff)
downloadkarakeep-e6486465decd612f7e437abe904960a47ff359ce.tar.zst
refactor: added the bookmark type to the database (#256)
* refactoring asset types Extracted out functions to silently delete assets and to update them after crawling Generalized the mapping of assets to bookmark fields to make extending them easier * Added the bookmark type to the database Introduced an enum to have better type safety cleaned up the code and based some code on the type directly * add BookmarkType.UNKNWON * lint and remove unused function --------- Co-authored-by: MohamedBassem <me@mbassem.com>
Diffstat (limited to 'packages/shared')
-rw-r--r--packages/shared/types/bookmarks.ts15
1 files changed, 11 insertions, 4 deletions
diff --git a/packages/shared/types/bookmarks.ts b/packages/shared/types/bookmarks.ts
index c9e3e1a5..c0c12b56 100644
--- a/packages/shared/types/bookmarks.ts
+++ b/packages/shared/types/bookmarks.ts
@@ -4,8 +4,15 @@ import { zBookmarkTagSchema } from "./tags";
const MAX_TITLE_LENGTH = 100;
+export const enum BookmarkTypes {
+ LINK = "link",
+ TEXT = "text",
+ ASSET = "asset",
+ UNKNWON = "unknown",
+}
+
export const zBookmarkedLinkSchema = z.object({
- type: z.literal("link"),
+ type: z.literal(BookmarkTypes.LINK),
url: z.string().url(),
title: z.string().nullish(),
description: z.string().nullish(),
@@ -20,13 +27,13 @@ export const zBookmarkedLinkSchema = z.object({
export type ZBookmarkedLink = z.infer<typeof zBookmarkedLinkSchema>;
export const zBookmarkedTextSchema = z.object({
- type: z.literal("text"),
+ type: z.literal(BookmarkTypes.TEXT),
text: z.string(),
});
export type ZBookmarkedText = z.infer<typeof zBookmarkedTextSchema>;
export const zBookmarkedAssetSchema = z.object({
- type: z.literal("asset"),
+ type: z.literal(BookmarkTypes.ASSET),
assetType: z.enum(["image", "pdf"]),
assetId: z.string(),
fileName: z.string().nullish(),
@@ -38,7 +45,7 @@ export const zBookmarkContentSchema = z.discriminatedUnion("type", [
zBookmarkedLinkSchema,
zBookmarkedTextSchema,
zBookmarkedAssetSchema,
- z.object({ type: z.literal("unknown") }),
+ z.object({ type: z.literal(BookmarkTypes.UNKNWON) }),
]);
export type ZBookmarkContent = z.infer<typeof zBookmarkContentSchema>;