From 91bfcb875f1ab58aa5855bcad1104c3540becf5b Mon Sep 17 00:00:00 2001 From: rijkvanzanten Date: Mon, 26 Oct 2020 19:38:36 +0100 Subject: [PATCH] Don't auto convert `,` to arrays in env Fixes #782 --- api/src/controllers/files.ts | 5 +++-- api/src/env.ts | 5 ----- api/src/utils/to-array.ts | 7 ++++++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/api/src/controllers/files.ts b/api/src/controllers/files.ts index d33beb55e5..15e154fd66 100644 --- a/api/src/controllers/files.ts +++ b/api/src/controllers/files.ts @@ -12,6 +12,7 @@ import url from 'url'; import path from 'path'; import useCollection from '../middleware/use-collection'; import { respond } from '../middleware/respond'; +import { toArray } from '../utils/to-array'; const router = express.Router(); @@ -32,7 +33,7 @@ const multipartHandler = asyncHandler(async (req, res, next) => { * the row in directus_files async during the upload of the actual file. */ - let disk: string = (env.STORAGE_LOCATIONS as string).split(',')[0].trim(); + let disk: string = toArray(env.STORAGE_LOCATIONS)[0]; let payload: Partial = {}; let fileCount = 0; @@ -155,7 +156,7 @@ router.post( const payload = { filename_download: filename, - storage: (env.STORAGE_LOCATIONS as string).split(',')[0].trim(), + storage: toArray(env.STORAGE_LOCATIONS)[0], type: fileResponse.headers['content-type'], title: formatTitle(filename), ...(req.body.data || {}), diff --git a/api/src/env.ts b/api/src/env.ts index 520e6c2e7e..d1cf1d1520 100644 --- a/api/src/env.ts +++ b/api/src/env.ts @@ -63,11 +63,6 @@ function processValues(env: Record) { if (value === 'false') env[key] = false; if (value === 'null') env[key] = null; if (isNaN(value) === false && value.length > 0) env[key] = Number(value); - if (typeof value === 'string' && value.includes(',')) - env[key] = value - .split(',') - .map((val) => val.trim()) - .filter((val) => val); } return env; diff --git a/api/src/utils/to-array.ts b/api/src/utils/to-array.ts index 77cf11fae2..94ad5b83e6 100644 --- a/api/src/utils/to-array.ts +++ b/api/src/utils/to-array.ts @@ -1,3 +1,8 @@ -export function toArray(val: T | T[]): T[] { +export function toArray(val: string): string[]; +export function toArray(val: any | any[]): any[] { + if (typeof val === 'string') { + return val.split(','); + } + return Array.isArray(val) ? val : [val]; }