Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ginger51011 committed Aug 17, 2022
1 parent 941ba59 commit 49c067c
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/routes/file.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ filesRoute.post('/upload', upload(), verifyAuthenticated, async (req, res) => {
// Check file size (file.size is in bytes)
const maxSize = config.FILES.MAX_FILE_UPLOAD_SIZE_BYTES;
if (file.size > maxSize) {
return res
.status(400)
.send(`File too big, max is ${maxSize / BYTES_PER_MB} MB`);
return res.status(400).send(`File too big, max is ${maxSize / BYTES_PER_MB} MB`);
}

const accessType = body?.accessType ?? AccessType.Public;
Expand All @@ -81,14 +79,9 @@ filesRoute.post('/upload/avatar', upload(), verifyAuthenticated, async (req, res
// Check if file is too big (file.size is in bytes)
const maxAvatarSize = config.FILES.MAX_AVATAR_SIZE_BYTES;
const maxSize = config.FILES.MAX_FILE_UPLOAD_SIZE_BYTES;
if (file.size > maxAvatarSize || file.size > maxSize) {
return res
.status(400)
.send(
`Avatar too big, max is ${
(maxAvatarSize > maxSize ? maxSize : maxAvatarSize) / BYTES_PER_MB
} MB`,
);
const sizeConstraint = Math.min(maxAvatarSize, maxSize);
if (file.size > sizeConstraint) {
return res.status(400).send(`Avatar too big, max is ${sizeConstraint / BYTES_PER_MB} MB`);
}

const { user } = res.locals;
Expand Down

0 comments on commit 49c067c

Please sign in to comment.