From e6486465decd612f7e437abe904960a47ff359ce Mon Sep 17 00:00:00 2001 From: kamtschatka Date: Mon, 1 Jul 2024 13:03:53 +0200 Subject: 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 --- apps/cli/src/commands/bookmarks.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'apps/cli') diff --git a/apps/cli/src/commands/bookmarks.ts b/apps/cli/src/commands/bookmarks.ts index 40442ec1..6efb41d9 100644 --- a/apps/cli/src/commands/bookmarks.ts +++ b/apps/cli/src/commands/bookmarks.ts @@ -9,7 +9,10 @@ import { getAPIClient } from "@/lib/trpc"; import { Command } from "@commander-js/extra-typings"; import type { ZBookmark } from "@hoarder/shared/types/bookmarks"; -import { MAX_NUM_BOOKMARKS_PER_PAGE } from "@hoarder/shared/types/bookmarks"; +import { + BookmarkTypes, + MAX_NUM_BOOKMARKS_PER_PAGE, +} from "@hoarder/shared/types/bookmarks"; export const bookmarkCmd = new Command() .name("bookmarks") @@ -26,7 +29,7 @@ function normalizeBookmark(bookmark: ZBookmark) { tags: bookmark.tags.map((t) => t.name), }; - if (ret.content.type == "link" && ret.content.htmlContent) { + if (ret.content.type == BookmarkTypes.LINK && ret.content.htmlContent) { if (ret.content.htmlContent.length > 10) { ret.content.htmlContent = ret.content.htmlContent.substring(0, 10) + "... "; @@ -63,7 +66,7 @@ bookmarkCmd const promises = [ ...opts.link.map((url) => api.bookmarks.createBookmark - .mutate({ type: "link", url }) + .mutate({ type: BookmarkTypes.LINK, url }) .then((bookmark: ZBookmark) => { results.push(normalizeBookmark(bookmark)); }) @@ -71,7 +74,7 @@ bookmarkCmd ), ...opts.note.map((text) => api.bookmarks.createBookmark - .mutate({ type: "text", text }) + .mutate({ type: BookmarkTypes.TEXT, text }) .then((bookmark: ZBookmark) => { results.push(normalizeBookmark(bookmark)); }) @@ -87,7 +90,7 @@ bookmarkCmd const text = fs.readFileSync(0, "utf-8"); promises.push( api.bookmarks.createBookmark - .mutate({ type: "text", text }) + .mutate({ type: BookmarkTypes.TEXT, text }) .then((bookmark: ZBookmark) => { results.push(normalizeBookmark(bookmark)); }) -- cgit v1.2.3-70-g09d2