minor cleanup
This commit is contained in:
parent
e3d9912378
commit
c3f72c4be8
|
@ -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-ignore
|
||||
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: unorganizedCollectionId,
|
||||
},
|
||||
});
|
||||
createBookmark(userId, bookmark, unorganizedCollectionId);
|
||||
}
|
||||
} else {
|
||||
// @ts-ignore
|
||||
|
@ -155,6 +104,23 @@ export default async function importFromHTMLFile(
|
|||
|
||||
const bookmarks = folder.nextElementSibling.querySelectorAll("A");
|
||||
for (const bookmark of bookmarks) {
|
||||
createBookmark(userId, bookmark, collectionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{ timeout: 30000 }
|
||||
)
|
||||
.catch((err) => console.log(err));
|
||||
|
||||
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;
|
||||
|
@ -201,17 +167,8 @@ export default async function importFromHTMLFile(
|
|||
),
|
||||
}
|
||||
: undefined,
|
||||
description: description,
|
||||
collectionId: collectionId,
|
||||
description,
|
||||
collectionId,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{ timeout: 30000 }
|
||||
)
|
||||
.catch((err) => console.log(err));
|
||||
|
||||
return { response: "Success.", status: 200 };
|
||||
}
|
||||
};
|
||||
|
|
Ŝarĝante…
Reference in New Issue