⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
Previous import mechanism is restored to previous behavior, while omnivore uses new binary import path
dereulenspiegel7b4d3248521f
diff --git a/components/ImportDropdown.tsx b/components/ImportDropdown.tsxindex 51e5f068..43fd2705 100644--- a/components/ImportDropdown.tsx+++ b/components/ImportDropdown.tsx@@ -1,11 +1,12 @@import React from "react";import importBookmarks from "@/lib/client/importBookmarks";+import importBookmarksBinary from "@/lib/client/importBookmarksBinary";import { MigrationFormat } from "@/types/global";import { useTranslation } from "next-i18next";import { dropdownTriggerer } from "@/lib/client/utils";type Props = {};-const ImportDropdown = ({}: Props) => {+const ImportDropdown = ({ }: Props) => {const { t } = useTranslation();return (<div className="dropdown dropdown-bottom">@@ -92,7 +93,7 @@ const ImportDropdown = ({}: Props) => {id="import-omnivore-file"accept=".zip"className="hidden"- onChange={(e) => importBookmarks(e, MigrationFormat.omnivore)}+ onChange={(e) => importBookmarksBinary(e, MigrationFormat.omnivore)}/></label></li>diff --git a/lib/client/importBookmarks.ts b/lib/client/importBookmarks.tsindex 7089b00d..1577de14 100644--- a/lib/client/importBookmarks.ts+++ b/lib/client/importBookmarks.ts@@ -1,64 +1,65 @@-import { MigrationFormat } from "@/types/global";+import { MigrationFormat, MigrationRequest } from "@/types/global";import { toast } from "react-hot-toast";const importBookmarks = async (- e: React.ChangeEvent<HTMLInputElement>,- format: MigrationFormat+ e: React.ChangeEvent<HTMLInputElement>,+ format: MigrationFormat) => {- const file: File | null = e.target.files && e.target.files[0];+ const file: File | null = e.target.files && e.target.files[0];- if (file) {- const reader = new FileReader();+ if (file) {+ const reader = new FileReader();+ reader.readAsText(file, "UTF-8");+ reader.onload = async function (e) {+ const load = toast.loading("Importing...");- reader.readAsArrayBuffer(file);- reader.onload = async function (e) {- const load = toast.loading("Importing...");+ const request: string = e.target?.result as string;- try {- const migrationFormatName = MigrationFormat[format];- const response = await fetch(- `/api/v1/migration/${migrationFormatName}`,- {- method: "POST",- body: e.target?.result as ArrayBuffer,- headers: { "Content-Type": "application/octet-stream" },- }- );+ const body: MigrationRequest = {+ format,+ data: request,+ };- if (!response.ok) {- const errorData = await response.json();- toast.dismiss(load);+ try {+ const response = await fetch("/api/v1/migration", {+ method: "POST",+ body: JSON.stringify(body),+ });- toast.error(- errorData.response ||- "Failed to import bookmarks. Please try again."- );- return;- }+ if (!response.ok) {+ const errorData = await response.json();+ toast.dismiss(load);- await response.json();- toast.dismiss(load);- toast.success("Imported the Bookmarks! Reloading the page...");+ toast.error(+ errorData.response ||+ "Failed to import bookmarks. Please try again."+ );+ return;+ }- setTimeout(() => {- location.reload();- }, 2000);- } catch (error) {- console.error("Request failed", error);- toast.dismiss(load);- toast.error(- "An error occurred while importing bookmarks. Please check the logs for more info."- );- }- };+ await response.json();+ toast.dismiss(load);+ toast.success("Imported the Bookmarks! Reloading the page...");- reader.onerror = function (e) {- console.log("Error reading file:", e);- toast.error(- "Failed to read the file. Please make sure the file is correct and try again."- );- };- }+ setTimeout(() => {+ location.reload();+ }, 2000);+ } catch (error) {+ console.error("Request failed", error);+ toast.dismiss(load);+ toast.error(+ "An error occurred while importing bookmarks. Please check the logs for more info."+ );+ }+ };++ reader.onerror = function (e) {+ console.log("Error reading file:", e);+ toast.error(+ "Failed to read the file. Please make sure the file is correct and try again."+ );+ };+ }};-export default importBookmarks;+export default importBookmarks;\ No newline at end of filediff --git a/lib/client/importBookmarksBinary.ts b/lib/client/importBookmarksBinary.tsnew file mode 100644index 00000000..224436d6--- /dev/null+++ b/lib/client/importBookmarksBinary.ts@@ -0,0 +1,64 @@+import { MigrationFormat } from "@/types/global";+import { toast } from "react-hot-toast";++const importBookmarksBinary = async (+ e: React.ChangeEvent<HTMLInputElement>,+ format: MigrationFormat+) => {+ const file: File | null = e.target.files && e.target.files[0];++ if (file) {+ const reader = new FileReader();++ reader.readAsArrayBuffer(file);+ reader.onload = async function (e) {+ const load = toast.loading("Importing...");++ try {+ const migrationFormatName = MigrationFormat[format];+ const response = await fetch(+ `/api/v1/migration/upload/${migrationFormatName}`,+ {+ method: "POST",+ body: e.target?.result as ArrayBuffer,+ headers: { "Content-Type": "application/octet-stream" },+ }+ );++ if (!response.ok) {+ const errorData = await response.json();+ toast.dismiss(load);++ toast.error(+ errorData.response ||+ "Failed to import bookmarks. Please try again."+ );+ return;+ }++ await response.json();+ toast.dismiss(load);+ toast.success("Imported the Bookmarks! Reloading the page...");++ setTimeout(() => {+ location.reload();+ }, 2000);+ } catch (error) {+ console.error("Request failed", error);+ toast.dismiss(load);+ toast.error(+ "An error occurred while importing bookmarks. Please check the logs for more info."+ );+ }+ };++ reader.onerror = function (e) {+ console.log("Error reading file:", e);+ toast.error(+ "Failed to read the file. Please make sure the file is correct and try again."+ );+ };+ }+};++export default importBookmarksBinary;diff --git a/pages/api/v1/migration/upload/[format].ts b/pages/api/v1/migration/upload/[format].tsindex 556e7f60..b5417f87 100644--- a/pages/api/v1/migration/upload/[format].ts+++ b/pages/api/v1/migration/upload/[format].ts@@ -4,6 +4,7 @@ import verifyUser from "@/lib/api/verifyUser";import importFromOmnivore from "@/lib/api/controllers/migration/importFromOmnivore";import { Readable } from "stream";import getSizeTransform from "stream-size";+import formidable from "formidable";export const config = {api: {diff --git a/pages/dashboard.tsx b/pages/dashboard.tsxindex acc18b64..c87be4e2 100644--- a/pages/dashboard.tsx+++ b/pages/dashboard.tsx@@ -3,11 +3,12 @@ import { useEffect, useMemo, useState } from "react";import Link from "next/link";import React from "react";import { toast } from "react-hot-toast";-import { ViewMode } from "@/types/global";+import { MigrationFormat, MigrationRequest, ViewMode } from "@/types/global";import DashboardItem from "@/components/DashboardItem";import NewLinkModal from "@/components/ModalContent/NewLinkModal";import PageHeader from "@/components/PageHeader";import ViewDropdown from "@/components/ViewDropdown";+import { dropdownTriggerer } from "@/lib/client/utils";import getServerSideProps from "@/lib/client/getServerSideProps";import { useTranslation } from "next-i18next";import { useCollections } from "@/hooks/store/collections";@@ -51,7 +52,7 @@ export default function Dashboard() {account.referredBy === null &&// if user is using Linkwarden for more than 3 daysnew Date().getTime() - new Date(account.createdAt).getTime() >- 3 * 24 * 60 * 60 * 1000+ 3 * 24 * 60 * 60 * 1000) {setTimeout(() => {setShowsSurveyModal(true);