From 551d208385aa904cfd56898b30a5d45abcc9880d Mon Sep 17 00:00:00 2001 From: Nicolas Thouvenin Date: Fri, 29 Nov 2024 15:54:14 +0100 Subject: [PATCH 1/2] we make sure the object is usable --- src/api/controller/api/upload.js | 7 ++++++- src/api/services/progress.js | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/api/controller/api/upload.js b/src/api/controller/api/upload.js index 4470cd404..4534afef4 100644 --- a/src/api/controller/api/upload.js +++ b/src/api/controller/api/upload.js @@ -154,6 +154,7 @@ export const uploadUrl = async (ctx) => { export const uploadText = async (ctx) => { const { text, loaderName, customLoader } = ctx.request.body; + try { await workerQueues[ctx.tenant].add( IMPORT, // Name of the job { @@ -164,7 +165,11 @@ export const uploadText = async (ctx) => { jobType: IMPORT, }, { jobId: uuid() }, - ); + ) + } catch(e) { + console.error(e) + ctx.status = 500; + } }; export const checkChunkMiddleware = async (ctx, loaderName) => { diff --git a/src/api/services/progress.js b/src/api/services/progress.js index 02a1fda30..aa54fffe4 100644 --- a/src/api/services/progress.js +++ b/src/api/services/progress.js @@ -23,6 +23,9 @@ export class Progress { } start(tenant, { status, target, symbol, label, subLabel, type }) { + if (!this[tenant]) { + this.initialize(tenant); + } this[tenant].status = status; this[tenant].target = target; this[tenant].progress = 0; @@ -35,7 +38,7 @@ export class Progress { } finish(tenant) { - if (this[tenant].status === ERROR) { + if (!this[tenant] || this[tenant].status === ERROR) { return; } this[tenant].status = PENDING; From 0cf18d5117c54414f79a75a3116bd3cff016da64 Mon Sep 17 00:00:00 2001 From: Nicolas Thouvenin Date: Fri, 29 Nov 2024 16:08:09 +0100 Subject: [PATCH 2/2] Update upload.js --- src/api/controller/api/upload.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/api/controller/api/upload.js b/src/api/controller/api/upload.js index 4534afef4..4470cd404 100644 --- a/src/api/controller/api/upload.js +++ b/src/api/controller/api/upload.js @@ -154,7 +154,6 @@ export const uploadUrl = async (ctx) => { export const uploadText = async (ctx) => { const { text, loaderName, customLoader } = ctx.request.body; - try { await workerQueues[ctx.tenant].add( IMPORT, // Name of the job { @@ -165,11 +164,7 @@ export const uploadText = async (ctx) => { jobType: IMPORT, }, { jobId: uuid() }, - ) - } catch(e) { - console.error(e) - ctx.status = 500; - } + ); }; export const checkChunkMiddleware = async (ctx, loaderName) => {