From 2f8cc36d4b6e52f2394a76a6a973660844892cdc Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Tue, 23 Oct 2018 04:37:37 +0900 Subject: [PATCH] Complement file extension from MIME (#2979) --- src/services/drive/add-file.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/services/drive/add-file.ts b/src/services/drive/add-file.ts index 77ee70db5..273b05637 100644 --- a/src/services/drive/add-file.ts +++ b/src/services/drive/add-file.ts @@ -37,7 +37,13 @@ async function save(path: string, name: string, type: string, hash: string, size if (config.drive && config.drive.storage == 'minio') { const minio = new Minio.Client(config.drive.config); - const [ext] = (name.match(/\.([a-zA-Z0-9_-]+)$/) || ['']); + let [ext] = (name.match(/\.([a-zA-Z0-9_-]+)$/) || ['']); + + if (ext === '') { + if (type === 'image/jpeg') ext = '.jpg'; + if (type === 'image/png') ext = '.png'; + if (type === 'image/webp') ext = '.webp'; + } const key = `${config.drive.prefix}/${uuid.v4()}${ext}`; const thumbnailKey = `${config.drive.prefix}/${uuid.v4()}.jpg`;