Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

Fixed the unnecessary creation of multiple import collections

dereulenspiegel3d54cc05a4e7
diff --git a/lib/api/controllers/migration/importFromOmnivore.ts b/lib/api/controllers/migration/importFromOmnivore.ts
index 67c00eea..655550ae 100644
--- a/lib/api/controllers/migration/importFromOmnivore.ts
+++ b/lib/api/controllers/migration/importFromOmnivore.ts
@@ -33,42 +33,42 @@ export default async function importFromOmnivore(
const zipEntries = await importArchive.getEntries();
- for (const entry of zipEntries) {
+ await prisma.$transaction(
+ async () => {
+ const omnivoreCollection = await prisma.collection.create({
+ data: {
+ owner: {
+ connect: {
+ id: userId
+ }
+ },
+ name: "Omnivore Imports",
+ createdBy: {
+ connect: {
+ id: userId
+ }
+ }
+ }
+ });
- if (entry.filename.startsWith("metadata_")) {
- console.log(`Getting metadata from ${entry.filename}`);
+ createFolder({ filePath: `archives/${omnivoreCollection.id}` });
- const jsonWriter = new TextWriter();
- const jsonMetadatString: string = await entry.getData(jsonWriter);
- const metadata: OmnivoreMetadata = JSON.parse(jsonMetadatString);
+ for (const entry of zipEntries) {
- const hasTooManyLinks = await hasPassedLimit(userId, metadata.length);
- if (hasTooManyLinks) {
- return {
- response: `Your subscription have reached the maximum number of links allowed.`,
- status: 400,
- };
- }
+ if (entry.filename.startsWith("metadata_")) {
+ console.log(`Getting metadata from ${entry.filename}`);
- await prisma.$transaction(
- async () => {
- const omnivoreCollection = await prisma.collection.create({
- data: {
- owner: {
- connect: {
- id: userId
- }
- },
- name: "Omnivore Imports",
- createdBy: {
- connect: {
- id: userId
- }
- }
- }
- });
+ const jsonWriter = new TextWriter();
+ const jsonMetadatString: string = await entry.getData(jsonWriter);
+ const metadata: OmnivoreMetadata = JSON.parse(jsonMetadatString);
- createFolder({ filePath: `archives/${omnivoreCollection.id}` });
+ const hasTooManyLinks = await hasPassedLimit(userId, metadata.length);
+ if (hasTooManyLinks) {
+ return {
+ response: `Your subscription have reached the maximum number of links allowed.`,
+ status: 400,
+ };
+ }
for (const data of metadata) {
try {
@@ -122,7 +122,7 @@ export default async function importFromOmnivore(
)
}
}
- )
+ }
}
- }
+ )
}