aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/lib')
-rw-r--r--apps/web/lib/i18n/locales/en/translation.json1
-rw-r--r--apps/web/lib/importBookmarkParser.ts36
2 files changed, 37 insertions, 0 deletions
diff --git a/apps/web/lib/i18n/locales/en/translation.json b/apps/web/lib/i18n/locales/en/translation.json
index 0236b1c3..92f6e956 100644
--- a/apps/web/lib/i18n/locales/en/translation.json
+++ b/apps/web/lib/i18n/locales/en/translation.json
@@ -99,6 +99,7 @@
"import_bookmarks_from_html_file": "Import Bookmarks from HTML file",
"import_bookmarks_from_pocket_export": "Import Bookmarks from Pocket export",
"import_bookmarks_from_omnivore_export": "Import Bookmarks from Omnivore export",
+ "import_bookmarks_from_linkwarden_export": "Import Bookmarks from Linkwarden export",
"import_bookmarks_from_hoarder_export": "Import Bookmarks from Hoarder export",
"export_links_and_notes": "Export Links and Notes",
"imported_bookmarks": "Imported Bookmarks"
diff --git a/apps/web/lib/importBookmarkParser.ts b/apps/web/lib/importBookmarkParser.ts
index f3819e79..69b8a78c 100644
--- a/apps/web/lib/importBookmarkParser.ts
+++ b/apps/web/lib/importBookmarkParser.ts
@@ -140,3 +140,39 @@ export async function parseOmnivoreBookmarkFile(
};
});
}
+
+export async function parseLinkwardenBookmarkFile(
+ file: File,
+): Promise<ParsedBookmark[]> {
+ const textContent = await file.text();
+ const zLinkwardenExportSchema = z.object({
+ collections: z.array(
+ z.object({
+ links: z.array(
+ z.object({
+ name: z.string(),
+ url: z.string(),
+ tags: z.array(z.object({ name: z.string() })),
+ createdAt: z.coerce.date(),
+ }),
+ ),
+ }),
+ ),
+ });
+
+ const parsed = zLinkwardenExportSchema.safeParse(JSON.parse(textContent));
+ if (!parsed.success) {
+ throw new Error(
+ `The uploaded JSON file contains an invalid Linkwarden bookmark file: ${parsed.error.toString()}`,
+ );
+ }
+
+ return parsed.data.collections.flatMap((collection) => {
+ return collection.links.map((bookmark) => ({
+ title: bookmark.name ?? "",
+ content: { type: BookmarkTypes.LINK as const, url: bookmark.url },
+ tags: bookmark.tags.map((tag) => tag.name),
+ addDate: bookmark.createdAt.getTime() / 1000,
+ }));
+ });
+}