Skip to content

Commit

Permalink
Adress requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Saphs authored and DanielLiebler committed Nov 5, 2023
1 parent 2ff7826 commit b8fcde1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/controller/assets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class AssetsController {

private static multerLimits = {
fileSize: 10 * 1024 * 1024, // 10MB
files: 5,
files: 1,
parts: 10,
};

Expand Down
20 changes: 13 additions & 7 deletions src/module/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,30 @@ export class Authentication {

// If the header exists check the JWT token.
const validToken: JwtToken = await Authentication.verifyJwtToken(jwtToken);
if (validToken === null) {
new APIResponse(res, 401, {}, [
{
userMessage: 'Permission not granted.',
internalMessage: 'Token not valid.',
},
]).send();
return;
}

try {
const userRepository = getRepository(User);
const user = await userRepository.findOneOrFail({
where: [{ login_name: validToken.username }],
});

if (validToken === null || !user.is_dev) {
const user = await userRepository.findOneOrFail({ where: [{ login_name: validToken.username }] });
if (!user.is_dev) {
new APIResponse(res, 401, {}, [
{
userMessage: 'Permission not granted.',
internalMessage: 'Wrong JWT token was provided or user was not a development account.',
internalMessage: 'Wrong JWT token, user was not a development account.',
},
]).send();
return;
}
} catch (error) {
console.log('There is no user with username ' + validToken.username);
console.log('There is no user with username ' + validToken?.username);
new APIResponse(res, 404, {}, ['There is no user with given username.']).send();
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/router/assets.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ assetsRouter.get('/texture', AssetsController.getTextures);
assetsRouter.put('/texture', Authentication.grantDevAccess, AssetsController.multipartData.single('asset'), AssetsController.uploadTexture);

assetsRouter.get('/gltf', AssetsController.getGltf);
assetsRouter.put('/gltf', AssetsController.multipartGltfData.single('asset'), AssetsController.uploadGltf);
assetsRouter.put('/gltf', Authentication.grantDevAccess, AssetsController.multipartGltfData.single('asset'), AssetsController.uploadGltf);

assetsRouter.post('/cubemap', AssetsController.defineCubeMap);
assetsRouter.post('/cubemap', Authentication.grantDevAccess, AssetsController.defineCubeMap);
assetsRouter.get('/cubemap', AssetsController.getCubeMaps);

assetsRouter.use('/static', express.static(path.join(__dirname, '../../storage/dynamicAssets')));
Expand Down

0 comments on commit b8fcde1

Please sign in to comment.