From 82f342cf451c1fd9652154c007ca72dd64e2ee0f Mon Sep 17 00:00:00 2001 From: cutestnekoaqua Date: Wed, 29 Mar 2023 19:36:23 +0200 Subject: [PATCH] update post job --- packages/backend/src/queue/processors/db/import-posts.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/queue/processors/db/import-posts.ts b/packages/backend/src/queue/processors/db/import-posts.ts index 48ef6371e3..f4868ebbcb 100644 --- a/packages/backend/src/queue/processors/db/import-posts.ts +++ b/packages/backend/src/queue/processors/db/import-posts.ts @@ -31,12 +31,12 @@ export async function importPosts( return; } - const csv = await downloadTextFile(file.url); + const json = await downloadTextFile(file.url); let linenum = 0; - if (file.type.endsWith("json")) { - for (const post of JSON.parse(csv)) { + try { + for (const post of JSON.parse(json)) { try { if (post.replyId != null) { logger.info(`Is reply, skip [${linenum}] ...`); @@ -74,6 +74,9 @@ export async function importPosts( logger.warn(`Error in line:${linenum} ${e}`); } } + } catch (e) { + // handle error + logger.warn(`Error reading: ${e}`); } logger.succ("Imported");