Skip to content

Commit

Permalink
fix: remove multer (#8041)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin9foong authored Jan 13, 2025
1 parent 2d36463 commit 5af937a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const updateFormSettings = async (
// TODO: update this to work with backend
export const updateFormWhitelistSetting: UpdateStorageFormWhitelistSettingFn =
async (formId: string, whitelistCsvString: Promise<string> | null) => {
return ApiService.putForm<FormSettings>(
return ApiService.put<FormSettings>(
`${ADMIN_FORM_ENDPOINT}/${formId}/settings/whitelist`,
{
whitelistCsvString: await whitelistCsvString,
Expand Down
21 changes: 7 additions & 14 deletions src/app/modules/form/admin-form/admin-form.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { celebrate, Joi as BaseJoi, Segments } from 'celebrate'
import { AuthedSessionData } from 'express-session'
import { StatusCodes } from 'http-status-codes'
import JSONStream from 'JSONStream'
import multer from 'multer'
import { ResultAsync } from 'neverthrow'

import {
Expand Down Expand Up @@ -1657,29 +1656,24 @@ export const handleDeleteWorkflowStep: ControllerHandler<
}

const TWENTY_MB_IN_BYTES = 20 * 1024 * 1024
const handleWhitelistSettingMultipartBody = multer({
limits: {
fieldSize: TWENTY_MB_IN_BYTES,
fields: 1, // only allow csv string field
files: 0,
},
})

const _handleUpdateWhitelistSettingValidator = celebrate({
[Segments.PARAMS]: {
[Segments.PARAMS]: Joi.object({
formId: Joi.string()
.required()
.pattern(/^[a-fA-F0-9]{24}$/)
.message('Your form ID is invalid.'),
},
[Segments.BODY]: {
}),
[Segments.BODY]: Joi.object({
whitelistCsvString: Joi.string()
.allow(null) // for removal of whitelist
.max(TWENTY_MB_IN_BYTES)
.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': 'Your csv is too large.',
}),
},
}),
})

const _parseWhitelistCsvString = (whitelistCsvString: string | null) => {
Expand Down Expand Up @@ -1792,7 +1786,6 @@ export const _handleUpdateWhitelistSettingForTest =
_handleUpdateWhitelistSetting

export const handleUpdateWhitelistSetting = [
handleWhitelistSettingMultipartBody.none(), // expecting string field
_handleUpdateWhitelistSettingValidator,
_handleUpdateWhitelistSetting,
] as ControllerHandler[]
Expand Down

0 comments on commit 5af937a

Please sign in to comment.