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 dom = new JSDOM(rawData);
|
||||||
const document = dom.window.document;
|
const document = dom.window.document;
|
||||||
|
|
||||||
// console.log(document.querySelectorAll("A").length);
|
|
||||||
|
|
||||||
const bookmarks = document.querySelectorAll("A");
|
const bookmarks = document.querySelectorAll("A");
|
||||||
const totalImports = bookmarks.length;
|
const totalImports = bookmarks.length;
|
||||||
|
|
||||||
|
@ -64,56 +62,7 @@ export default async function importFromHTMLFile(
|
||||||
if (unorganizedCollectionId) {
|
if (unorganizedCollectionId) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
for (const bookmark of bookmarks) {
|
for (const bookmark of bookmarks) {
|
||||||
// Move up to the parent node (<DT>) and then find the next sibling
|
createBookmark(userId, bookmark, unorganizedCollectionId);
|
||||||
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,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -155,6 +104,23 @@ export default async function importFromHTMLFile(
|
||||||
|
|
||||||
const bookmarks = folder.nextElementSibling.querySelectorAll("A");
|
const bookmarks = folder.nextElementSibling.querySelectorAll("A");
|
||||||
for (const bookmark of bookmarks) {
|
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
|
// Move up to the parent node (<DT>) and then find the next sibling
|
||||||
let parentDT = bookmark.parentNode;
|
let parentDT = bookmark.parentNode;
|
||||||
let nextSibling = parentDT ? parentDT.nextSibling : null;
|
let nextSibling = parentDT ? parentDT.nextSibling : null;
|
||||||
|
@ -201,17 +167,8 @@ export default async function importFromHTMLFile(
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
description: description,
|
description,
|
||||||
collectionId: collectionId,
|
collectionId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ timeout: 30000 }
|
|
||||||
)
|
|
||||||
.catch((err) => console.log(err));
|
|
||||||
|
|
||||||
return { response: "Success.", status: 200 };
|
|
||||||
}
|
|
||||||
|
|
Ŝarĝante…
Reference in New Issue