aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/utils.ts')
-rw-r--r--server/helpers/utils.ts18
1 files changed, 15 insertions, 3 deletions
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts
index 79c3b5858..3b618360b 100644
--- a/server/helpers/utils.ts
+++ b/server/helpers/utils.ts
@@ -27,10 +27,14 @@ function badRequest (req: express.Request, res: express.Response, next: express.
27 return res.type('json').status(400).end() 27 return res.type('json').status(400).end()
28} 28}
29 29
30function createReqFiles (fieldName: string, storageDir: string, mimeTypes: { [ id: string ]: string }) { 30function createReqFiles (
31 fieldNames: string[],
32 mimeTypes: { [ id: string ]: string },
33 destinations: { [ fieldName: string ]: string }
34) {
31 const storage = multer.diskStorage({ 35 const storage = multer.diskStorage({
32 destination: (req, file, cb) => { 36 destination: (req, file, cb) => {
33 cb(null, storageDir) 37 cb(null, destinations[file.fieldname])
34 }, 38 },
35 39
36 filename: async (req, file, cb) => { 40 filename: async (req, file, cb) => {
@@ -48,7 +52,15 @@ function createReqFiles (fieldName: string, storageDir: string, mimeTypes: { [ i
48 } 52 }
49 }) 53 })
50 54
51 return multer({ storage }).fields([{ name: fieldName, maxCount: 1 }]) 55 const fields = []
56 for (const fieldName of fieldNames) {
57 fields.push({
58 name: fieldName,
59 maxCount: 1
60 })
61 }
62
63 return multer({ storage }).fields(fields)
52} 64}
53 65
54async function generateRandomString (size: number) { 66async function generateRandomString (size: number) {