⚡️⚡️⚡️ 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
feat(web): add import from pocket
daniel31x13c9f2799618b4
diff --git a/apps/web/components/ImportDropdown.tsx b/apps/web/components/ImportDropdown.tsxindex f9d4acc9..a51162b6 100644--- a/apps/web/components/ImportDropdown.tsx+++ b/apps/web/components/ImportDropdown.tsx@@ -35,6 +35,11 @@ const ImportDropdown = ({}: Props) => {format: MigrationFormat.htmlFile,label: t("from_html"),},+ {+ id: "import-pocket-file",+ format: MigrationFormat.pocket,+ label: t("from_pocket"),+ },{id: "import-wallabag-file",format: MigrationFormat.wallabag,@@ -61,7 +66,9 @@ const ImportDropdown = ({}: Props) => {? ".html": item.id === "import-omnivore-file"? ".zip"- : ".json"+ : item.id === "import-pocket-file"+ ? ".csv"+ : ".json"}className="hidden"onChange={(e) => importBookmarks(e, item.format)}diff --git a/apps/web/lib/api/controllers/migration/importFromPocket.ts b/apps/web/lib/api/controllers/migration/importFromPocket.tsnew file mode 100644index 00000000..7b5cdcdf--- /dev/null+++ b/apps/web/lib/api/controllers/migration/importFromPocket.ts@@ -0,0 +1,92 @@+import { prisma } from "@linkwarden/prisma";+import { createFolder } from "@linkwarden/filesystem";+import { hasPassedLimit } from "@linkwarden/lib";+import Papa from "papaparse";++type PocketBackup = {+ title: string;+ url: string;+ time_added: string;+ tags: string;+ status: string;+}[];++export default async function importFromPocket(+ userId: number,+ rawData: string+) {+ const data = Papa.parse(rawData, {+ header: true, // Treat first row as header+ skipEmptyLines: true,+ }).data as PocketBackup;++ const backup = data.filter((e) => e.url);++ let totalImports = backup.length;++ const hasTooManyLinks = await hasPassedLimit(userId, totalImports);++ if (hasTooManyLinks) {+ return {+ response: `Your subscription has reached the maximum number of links allowed.`,+ status: 400,+ };+ }++ await prisma+ .$transaction(+ async () => {+ const newCollection = await prisma.collection.create({+ data: {+ owner: {+ connect: {+ id: userId,+ },+ },+ name: "Imports",+ createdBy: {+ connect: {+ id: userId,+ },+ },+ },+ });++ createFolder({ filePath: `archives/${newCollection.id}` });++ for (const link of backup) {+ if (link.url) {+ try {+ new URL(link.url.trim());+ } catch (err) {+ continue;+ }+ }++ await prisma.link.create({+ data: {+ url: link.url?.trim().slice(0, 2047),+ name: link.title?.trim().slice(0, 254) || "",+ importDate: link.time_added+ ? new Date(Number(link.time_added) * 1000).toISOString()+ : null,+ collection: {+ connect: {+ id: newCollection.id,+ },+ },+ createdBy: {+ connect: {+ id: userId,+ },+ },+ },+ });+ }+ },+ { timeout: 30000 }+ )+ .catch((err) => console.log(err));++ return { response: "Success.", status: 200 };+}diff --git a/apps/web/package.json b/apps/web/package.jsonindex 42a371c4..34dc96f1 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -38,6 +38,7 @@"@types/formidable": "^3.4.5","@types/node": "^20.10.4","@types/nodemailer": "^6.4.8",+ "@types/papaparse": "^5.3.16","@types/react": "18.3.20","@types/react-dom": "18.3.7","@types/rss": "^0.0.32",@@ -67,6 +68,7 @@"next-i18next": "^15.3.0","node-fetch": "^2.7.0","nodemailer": "^6.9.3",+ "papaparse": "^5.5.3","playwright": "^1.45.0","react": "18.3.1","react-colorful": "^5.6.1",diff --git a/apps/web/pages/api/v1/migration/index.ts b/apps/web/pages/api/v1/migration/index.tsindex ab758aff..74c1947f 100644--- a/apps/web/pages/api/v1/migration/index.ts+++ b/apps/web/pages/api/v1/migration/index.ts@@ -6,6 +6,7 @@ import { MigrationFormat, MigrationRequest } from "@linkwarden/types";import verifyUser from "@/lib/api/verifyUser";import importFromWallabag from "@/lib/api/controllers/migration/importFromWallabag";import importFromOmnivore from "@/lib/api/controllers/migration/importFromOmnivore";+import importFromPocket from "@/lib/api/controllers/migration/importFromPocket";export const config = {api: {@@ -48,6 +49,8 @@ export default async function users(req: NextApiRequest, res: NextApiResponse) {data = await importFromWallabag(user.id, request.data);else if (request.format === MigrationFormat.omnivore)data = await importFromOmnivore(user.id, request.data);+ else if (request.format === MigrationFormat.pocket)+ data = await importFromPocket(user.id, request.data);if (data) return res.status(data.status).json({ response: data.response });}diff --git a/apps/web/pages/dashboard.tsx b/apps/web/pages/dashboard.tsxindex e2c67662..288e9aac 100644--- a/apps/web/pages/dashboard.tsx+++ b/apps/web/pages/dashboard.tsx@@ -326,59 +326,61 @@ const Section = ({);case DashboardSectionType.COLLECTION:return (- <>- <div className="flex justify-between items-center">- <div className="flex gap-2 items-center">- <div className={clsx("flex items-center gap-3")}>- {collection.icon ? (- <Icon- icon={collection.icon}- color={collection.color || "#0ea5e9"}- className="text-2xl"- />- ) : (- <i- className={`bi-folder-fill text-primary text-2xl drop-shadow`}- style={{ color: collection.color || "#0ea5e9" }}- ></i>- )}- <div>- <p className="text-2xl capitalize font-thin">- {collection.name}- </p>+ collection?.id && (+ <>+ <div className="flex justify-between items-center">+ <div className="flex gap-2 items-center">+ <div className={clsx("flex items-center gap-3")}>+ {collection.icon ? (+ <Icon+ icon={collection.icon}+ color={collection.color || "#0ea5e9"}+ className="text-2xl"+ />+ ) : (+ <i+ className={`bi-folder-fill text-primary text-2xl drop-shadow`}+ style={{ color: collection.color || "#0ea5e9" }}+ ></i>+ )}+ <div>+ <p className="text-2xl capitalize font-thin">+ {collection.name}+ </p>+ </div></div></div>+ <Link+ href={`/collections/${collection.id}`}+ className="flex items-center text-sm text-black/75 dark:text-white/75 gap-2 cursor-pointer whitespace-nowrap"+ >+ {t("view_all")}+ <i className="bi-chevron-right text-sm"></i>+ </Link></div>- <Link- href={`/collections/${collection.id}`}- className="flex items-center text-sm text-black/75 dark:text-white/75 gap-2 cursor-pointer whitespace-nowrap"- >- {t("view_all")}- <i className="bi-chevron-right text-sm"></i>- </Link>- </div>- {dashboardData.isLoading ||- links?.filter((link: any) => link.collection.id === collection.id)- .length > 0 ? (- <DashboardLinks- links={links.filter(- (link: any) => link.collection.id === collection.id- )}- isLoading={dashboardData.isLoading}- />- ) : (- <div className="flex flex-col gap-2 justify-center h-full border border-solid border-neutral-content w-full mx-auto p-10 rounded-xl bg-base-200 bg-gradient-to-tr from-neutral-content/70 to-50% to-base-200">- <i className="bi-folder mx-auto text-6xl text-primary"></i>- <p className="text-center text-xl">- {t("no_link_in_collection")}- </p>- <p className="text-center mx-auto max-w-96 w-fit text-neutral text-sm">- {t("no_link_in_collection_desc")}- </p>- </div>- )}- </>+ {dashboardData.isLoading ||+ links?.filter((link: any) => link.collection.id === collection.id)+ .length > 0 ? (+ <DashboardLinks+ links={links.filter(+ (link: any) => link.collection.id === collection.id+ )}+ isLoading={dashboardData.isLoading}+ />+ ) : (+ <div className="flex flex-col gap-2 justify-center h-full border border-solid border-neutral-content w-full mx-auto p-10 rounded-xl bg-base-200 bg-gradient-to-tr from-neutral-content/70 to-50% to-base-200">+ <i className="bi-folder mx-auto text-6xl text-primary"></i>+ <p className="text-center text-xl">+ {t("no_link_in_collection")}+ </p>+ <p className="text-center mx-auto max-w-96 w-fit text-neutral text-sm">+ {t("no_link_in_collection_desc")}+ </p>+ </div>+ )}+ </>+ ));default:return null;diff --git a/apps/web/public/locales/en/common.json b/apps/web/public/locales/en/common.jsonindex 28d5c361..5e7262b3 100644--- a/apps/web/public/locales/en/common.json+++ b/apps/web/public/locales/en/common.json@@ -43,6 +43,7 @@"from_html": "From Bookmarks HTML file","from_wallabag": "From Wallabag (JSON file)","from_omnivore": "From Omnivore (ZIP file)",+ "from_pocket": "From Pocket (CSV file)","pinned": "Pinned","pinned_links_desc": "Your pinned Links","pin_favorite_links_here": "Pin Your Favorite Links Here!",diff --git a/packages/types/global.ts b/packages/types/global.tsindex eb5b5361..a95b064c 100644--- a/packages/types/global.ts+++ b/packages/types/global.ts@@ -120,6 +120,7 @@ export enum MigrationFormat {htmlFile = 1,wallabag = 2,omnivore = 3,+ pocket = 4,}export enum Plan {diff --git a/yarn.lock b/yarn.lockindex 3842745c..eed33403 100644--- a/yarn.lock+++ b/yarn.lock@@ -4631,6 +4631,13 @@dependencies:"@types/node" "*"+"@types/papaparse@^5.3.16":+ version "5.3.16"+ resolved "https://registry.yarnpkg.com/@types/papaparse/-/papaparse-5.3.16.tgz#320c8f6b8c9be898fe2d0c1b21aee51448bf9dca"+ integrity sha512-T3VuKMC2H0lgsjI9buTB3uuKj3EMD2eap1MOuEQuBQ44EnDx/IkGhU6EwiTf9zG3za4SKlmwKAImdDKdNnCsXg==+ dependencies:+ "@types/node" "*"+"@types/parse-json@^4.0.0":version "4.0.0"resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"@@ -10599,6 +10606,11 @@ pako@^1.0.11, pako@~1.0.2:resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==+papaparse@^5.5.3:+ version "5.5.3"+ resolved "https://registry.yarnpkg.com/papaparse/-/papaparse-5.5.3.tgz#07f8994dec516c6dab266e952bed68e1de59fa9a"+ integrity sha512-5QvjGxYVjxO59MGU2lHVYpRWBBtKHnlIAcSe1uNFCkkptUh63NFRj0FJQm7nR67puEruUci/ZkjmEFrjCAyP4A==+parent-module@^1.0.0:version "1.0.1"resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2"