From 7ec5746192ac59b38f7666643bad5e68ef4b46d7 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 3 Nov 2024 19:49:04 +0000 Subject: feature: Add support for importing bookmarks from Omnivore. Fixes #602 --- apps/web/components/settings/ImportExport.tsx | 17 ++++++++++++++- apps/web/lib/importBookmarkParser.ts | 31 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) (limited to 'apps/web') diff --git a/apps/web/components/settings/ImportExport.tsx b/apps/web/components/settings/ImportExport.tsx index b6fa6e03..7889b4d8 100644 --- a/apps/web/components/settings/ImportExport.tsx +++ b/apps/web/components/settings/ImportExport.tsx @@ -11,6 +11,7 @@ import { ParsedBookmark, parseHoarderBookmarkFile, parseNetscapeBookmarkFile, + parseOmnivoreBookmarkFile, parsePocketBookmarkFile, } from "@/lib/importBookmarkParser"; import { cn } from "@/lib/utils"; @@ -128,7 +129,7 @@ export function ImportExportRow() { source, }: { file: File; - source: "html" | "pocket" | "hoarder"; + source: "html" | "pocket" | "omnivore" | "hoarder"; }) => { if (source === "html") { return await parseNetscapeBookmarkFile(file); @@ -136,6 +137,8 @@ export function ImportExportRow() { return await parsePocketBookmarkFile(file); } else if (source === "hoarder") { return await parseHoarderBookmarkFile(file); + } else if (source === "omnivore") { + return await parseOmnivoreBookmarkFile(file); } else { throw new Error("Unknown source"); } @@ -223,6 +226,18 @@ export function ImportExportRow() {

Import Bookmarks from Pocket export

+ + runUploadBookmarkFile({ file, source: "omnivore" }) + } + > + +

Import Bookmarks from Omnivore export

+
{ + const textContent = await file.text(); + const zOmnivoreExportSchema = z.array( + z.object({ + title: z.string(), + url: z.string(), + labels: z.array(z.string()), + savedAt: z.coerce.date(), + }), + ); + + const parsed = zOmnivoreExportSchema.safeParse(JSON.parse(textContent)); + if (!parsed.success) { + throw new Error( + `The uploaded JSON file contains an invalid omnivore bookmark file: ${parsed.error.toString()}`, + ); + } + + return parsed.data.map((bookmark) => { + return { + title: bookmark.title ?? "", + content: { type: BookmarkTypes.LINK as const, url: bookmark.url }, + tags: bookmark.labels, + addDate: bookmark.savedAt.getTime() / 1000, + }; + }); +} -- cgit v1.2.3-70-g09d2