aboutsummaryrefslogtreecommitdiffstats
path: root/apps/cli
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 /apps/cli
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 'apps/cli')
-rw-r--r--apps/cli/src/commands/bookmarks.ts13
1 files changed, 8 insertions, 5 deletions
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) + "... <CROPPED>";
@@ -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));
})