Skip to content

Commit

Permalink
feat: increase whitelist limit to 3mb
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin9foong committed Jan 14, 2025
1 parent e96eb9b commit 4d2d364
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { useParams } from 'react-router'
import { Box, Skeleton } from '@chakra-ui/react'

import { KB } from '~shared/constants'
import { MB } from '~shared/constants'
import { StorageFormSettings } from '~shared/types'
import { VALID_WHITELIST_FILE_EXTENSIONS } from '~shared/utils/file-validation'

Expand All @@ -25,7 +25,7 @@ interface FormWhitelistAttachmentFieldProps {
isDisabled: boolean
}

const MAX_SIZE_IN_BYTES = 250 * KB
const MAX_SIZE_IN_BYTES = 3 * MB
const FormWhitelistAttachmentFieldContainerName =
'whitelist-csv-attachment-field-container'
const FormWhitelistAttachmentFieldName = 'whitelist-csv-attachment-field'
Expand Down
4 changes: 2 additions & 2 deletions shared/constants/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/** File types that can be uploaded for form image/logo */
export const VALID_UPLOAD_FILE_TYPES = ['image/jpeg', 'image/png', 'image/gif']

export const KB = 1000
export const MB = 1000 * KB
export const KB = 1024
export const MB = 1024 * KB

// Define max file size as 2MB
export const MAX_UPLOAD_FILE_SIZE = 2 * MB // 2 Million/Mega Bytes, or 2 MB
Expand Down
10 changes: 5 additions & 5 deletions src/app/modules/form/admin-form/admin-form.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import JSONStream from 'JSONStream'
import { ResultAsync } from 'neverthrow'

import {
KB,
MAX_UPLOAD_FILE_SIZE,
MB,
VALID_UPLOAD_FILE_TYPES,
} from '../../../../../shared/constants/file'
import {
Expand Down Expand Up @@ -1656,8 +1656,8 @@ export const handleDeleteWorkflowStep: ControllerHandler<
)
}

const TWO_HUNDRED_FIFTY = 250
const TWO_HUNDRED_FIFTY_KB_IN_BYTES = TWO_HUNDRED_FIFTY * KB
const LIMIT_IN_MB = 3
const STRING_MAX_LENGTH = LIMIT_IN_MB * MB
const _handleUpdateWhitelistSettingValidator = celebrate({
[Segments.PARAMS]: Joi.object({
formId: Joi.string()
Expand All @@ -1668,12 +1668,12 @@ const _handleUpdateWhitelistSettingValidator = celebrate({
[Segments.BODY]: Joi.object({
whitelistCsvString: Joi.string()
.allow(null) // for removal of whitelist
.max(TWO_HUNDRED_FIFTY_KB_IN_BYTES)
.max(STRING_MAX_LENGTH)
.pattern(/^[a-zA-Z0-9,\r\n]+$/)
.messages({
'string.empty': 'Your csv is empty.',
'string.pattern.base': 'Your csv has one or more invalid characters.',
'string.max': `You have exceeded the file size limit, please upload a file below ${TWO_HUNDRED_FIFTY} kB.`,
'string.max': `You have exceeded the file size limit, please upload a file below ${LIMIT_IN_MB} MB.`,
}),
}),
})
Expand Down

0 comments on commit 4d2d364

Please sign in to comment.