Fixed 404 error on rest import routes
MODIFY
src/server/rest/v1/router/api/UserRouter.ts
src/server/rest/v1/router/api/UserRouter.ts
@@ -110,7 +110,7 @@ export default class UserRouter {
}
protected buildRouteUserImport(): void {
- this.router.get(`/${ServerRoute.REST_USERS_IMPORT}`, async (req: Request, res: Response, next: NextFunction) => {
+ this.router.post(`/${ServerRoute.REST_USERS_IMPORT}`, async (req: Request, res: Response, next: NextFunction) => {
await RouterUtils.handleServerAction(UserService.handleImportUsers.bind(this), ServerAction.USERS_IMPORT, req, res, next);
});
}

MODIFY
src/server/rest/v1/service/TagService.ts
src/server/rest/v1/service/TagService.ts
@@ -416,6 +416,7 @@ export default class TagService {
await LockingManager.release(importTagsLock);
}
});
+ await new Promise((resolve) => {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
busboy.on('file', async (fieldname: string, file: any, filename: string, encoding: string, mimetype: string) => {
if (filename.slice(-4) === '.csv') {
@@ -437,6 +438,7 @@ export default class TagService {
if (!res.headersSent) {
res.writeHead(HTTPError.INVALID_FILE_CSV_HEADER_FORMAT);
res.end();
+ resolve();
}
throw new Error(`Missing one of required properties: '${TagRequiredImportProperties.join(', ')}'`);
}
@@ -469,6 +471,7 @@ export default class TagService {
if (!res.headersSent) {
res.writeHead(HTTPError.INVALID_FILE_FORMAT);
res.end();
+ resolve();
}
// Completed
// eslint-disable-next-line @typescript-eslint/no-misused-promises
@@ -503,6 +506,7 @@ export default class TagService {
// Respond
res.json({ ...result, ...Constants.REST_RESPONSE_SUCCESS });
next();
+ resolve();
});
// Start processing the file
void file.pipe(converter);
@@ -540,6 +544,7 @@ export default class TagService {
if (!res.headersSent) {
res.writeHead(HTTPError.INVALID_FILE_FORMAT);
res.end();
+ resolve();
}
});
file.pipe(parser);
@@ -557,9 +562,11 @@ export default class TagService {
if (!res.headersSent) {
res.writeHead(HTTPError.INVALID_FILE_FORMAT);
res.end();
+ resolve();
}
}
});
+ });
} catch (error) {
// Release the lock
await LockingManager.release(importTagsLock);

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -453,6 +453,7 @@ export default class UserService {
await LockingManager.release(importUsersLock);
}
});
+ await new Promise((resolve) => {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
busboy.on('file', async (fieldname, file, filename, encoding, mimetype) => {
if (filename.slice(-4) === '.csv') {
@@ -474,6 +475,7 @@ export default class UserService {
if (!res.headersSent) {
res.writeHead(HTTPError.INVALID_FILE_CSV_HEADER_FORMAT);
res.end();
+ resolve();
}
throw new Error(`Missing one of required properties: '${UserRequiredImportProperties.join(', ')}'`);
}
@@ -506,6 +508,7 @@ export default class UserService {
if (!res.headersSent) {
res.writeHead(HTTPError.INVALID_FILE_FORMAT);
res.end();
+ resolve();
}
// Completed
// eslint-disable-next-line @typescript-eslint/no-misused-promises
@@ -540,6 +543,7 @@ export default class UserService {
// Respond
res.json({ ...result, ...Constants.REST_RESPONSE_SUCCESS });
next();
+ resolve();
});
// Start processing the file
void file.pipe(converter);
@@ -577,6 +581,7 @@ export default class UserService {
if (!res.headersSent) {
res.writeHead(HTTPError.INVALID_FILE_FORMAT);
res.end();
+ resolve();
}
});
file.pipe(parser);
@@ -597,6 +602,7 @@ export default class UserService {
}
}
});
+ });
} catch (error) {
// Release the lock
await LockingManager.release(importUsersLock);

Fixed 404 error on rest import routes