Skip to content

Commit eeec3c6

Browse files
authored
fix(controllers): map not set for chunked backup
1 parent 8eadf74 commit eeec3c6

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/v3/controllers/users_controller.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,15 +1212,16 @@ export const saveUserChunkedBackup = async (req: Request, res: Response) => {
12121212
}
12131213

12141214
// reject if this upload is already in progress and not expired
1215-
if (backupUploadsInProgress.has(cong.id)) {
1215+
let findBackup = backupUploadsInProgress.get(cong.id);
1216+
1217+
if (findBackup && findBackup.userId !== user.id) {
12161218
res.locals.type = 'warn';
12171219
res.status(409).json({ message: 'BACKUP_OUTDATED' });
12181220

12191221
return;
12201222
}
12211223

12221224
// init or reset timer for the upload
1223-
let findBackup = backupUploadsInProgress.get(cong.id);
12241225

12251226
if (!findBackup) {
12261227
const timeout = setTimeout(() => {
@@ -1234,7 +1235,10 @@ export const saveUserChunkedBackup = async (req: Request, res: Response) => {
12341235
totalChunks,
12351236
received: 0,
12361237
timeout,
1238+
userId: user.id,
12371239
};
1240+
1241+
backupUploadsInProgress.set(cong.id, findBackup);
12381242
} else {
12391243
// refresh timeout on activity
12401244
clearTimeout(findBackup.timeout);
@@ -1282,6 +1286,6 @@ export const saveUserChunkedBackup = async (req: Request, res: Response) => {
12821286
}
12831287

12841288
res.locals.type = 'info';
1285-
res.locals.message = `congregation backup chunk ${chunkIndex} out of ${totalChunks} received`;
1289+
res.locals.message = `congregation backup chunk ${chunkIndex + 1} out of ${totalChunks} received`;
12861290
res.status(200).json({ message: 'BACKUP_CHUNK_RECEIVED' });
12871291
};

src/v3/definition/congregation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,5 @@ export type BackupForStorage = {
211211
totalChunks: number;
212212
received: number;
213213
timeout: NodeJS.Timeout;
214+
userId: string;
214215
};

0 commit comments

Comments
 (0)