⚡️⚡️⚡️ 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
minor cleanup
daniel31x13c3f72c4be896
diff --git a/lib/api/controllers/migration/importFromHTMLFile.ts b/lib/api/controllers/migration/importFromHTMLFile.tsindex d47af913..6a8b2988 100644--- a/lib/api/controllers/migration/importFromHTMLFile.ts+++ b/lib/api/controllers/migration/importFromHTMLFile.ts@@ -11,8 +11,6 @@ export default async function importFromHTMLFile(const dom = new JSDOM(rawData);const document = dom.window.document;- // console.log(document.querySelectorAll("A").length);-const bookmarks = document.querySelectorAll("A");const totalImports = bookmarks.length;@@ -64,56 +62,7 @@ export default async function importFromHTMLFile(if (unorganizedCollectionId) {// @ts-ignorefor (const bookmark of bookmarks) {- // Move up to the parent node (<DT>) and then find the next sibling- let parentDT = bookmark.parentNode;- let nextSibling = parentDT ? parentDT.nextSibling : null;- let description = "";-- // Loop through siblings to skip any potential text nodes or whitespace- while (nextSibling && nextSibling.nodeType !== 1) {- nextSibling = nextSibling.nextSibling;- }-- // Check if the next sibling element is a <DD> tag and use its content as the description- if (nextSibling && nextSibling.tagName === "DD") {- description = nextSibling.textContent.trim();- }-- await prisma.link.create({- data: {- name: bookmark.textContent.trim(),- url: bookmark.getAttribute("HREF"),- tags: bookmark.getAttribute("TAGS")- ? {- connectOrCreate: bookmark- .getAttribute("TAGS")- .split(",")- .map((tag: string) =>- tag- ? {- where: {- name_ownerId: {- name: tag.trim(),- ownerId: userId,- },- },- create: {- name: tag.trim(),- owner: {- connect: {- id: userId,- },- },- },- }- : undefined- ),- }- : undefined,- description: description,- collectionId: unorganizedCollectionId,- },- });+ createBookmark(userId, bookmark, unorganizedCollectionId);}} else {// @ts-ignore@@ -155,56 +104,7 @@ export default async function importFromHTMLFile(const bookmarks = folder.nextElementSibling.querySelectorAll("A");for (const bookmark of bookmarks) {- // Move up to the parent node (<DT>) and then find the next sibling- let parentDT = bookmark.parentNode;- let nextSibling = parentDT ? parentDT.nextSibling : null;- let description = "";-- // Loop through siblings to skip any potential text nodes or whitespace- while (nextSibling && nextSibling.nodeType !== 1) {- nextSibling = nextSibling.nextSibling;- }-- // Check if the next sibling element is a <DD> tag and use its content as the description- if (nextSibling && nextSibling.tagName === "DD") {- description = nextSibling.textContent.trim();- }-- await prisma.link.create({- data: {- name: bookmark.textContent.trim(),- url: bookmark.getAttribute("HREF"),- tags: bookmark.getAttribute("TAGS")- ? {- connectOrCreate: bookmark- .getAttribute("TAGS")- .split(",")- .map((tag: string) =>- tag- ? {- where: {- name_ownerId: {- name: tag.trim(),- ownerId: userId,- },- },- create: {- name: tag.trim(),- owner: {- connect: {- id: userId,- },- },- },- }- : undefined- ),- }- : undefined,- description: description,- collectionId: collectionId,- },- });+ createBookmark(userId, bookmark, collectionId);}}}@@ -215,3 +115,60 @@ export default async function importFromHTMLFile(return { response: "Success.", status: 200 };}++const createBookmark = async (+ userId: number,+ bookmark: any,+ collectionId: number+) => {+ // Move up to the parent node (<DT>) and then find the next sibling+ let parentDT = bookmark.parentNode;+ let nextSibling = parentDT ? parentDT.nextSibling : null;+ let description = "";++ // Loop through siblings to skip any potential text nodes or whitespace+ while (nextSibling && nextSibling.nodeType !== 1) {+ nextSibling = nextSibling.nextSibling;+ }++ // Check if the next sibling element is a <DD> tag and use its content as the description+ if (nextSibling && nextSibling.tagName === "DD") {+ description = nextSibling.textContent.trim();+ }++ await prisma.link.create({+ data: {+ name: bookmark.textContent.trim(),+ url: bookmark.getAttribute("HREF"),+ tags: bookmark.getAttribute("TAGS")+ ? {+ connectOrCreate: bookmark+ .getAttribute("TAGS")+ .split(",")+ .map((tag: string) =>+ tag+ ? {+ where: {+ name_ownerId: {+ name: tag.trim(),+ ownerId: userId,+ },+ },+ create: {+ name: tag.trim(),+ owner: {+ connect: {+ id: userId,+ },+ },+ },+ }+ : undefined+ ),+ }+ : undefined,+ description,+ collectionId,+ },+ });+};