From 78ef0a9929a1a4460acdca4f1810f8c0ca08f37f Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Thu, 2 Jan 2020 02:45:05 +0900 Subject: ドライブファイルURL生成などの修正 (#5671) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix: リモートプロキシ時にサムネイルのContent-Typeがおかしい * fix drive --- src/models/repositories/drive-file.ts | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'src/models') diff --git a/src/models/repositories/drive-file.ts b/src/models/repositories/drive-file.ts index 5e3c1e94b8..63b9f60965 100644 --- a/src/models/repositories/drive-file.ts +++ b/src/models/repositories/drive-file.ts @@ -39,25 +39,13 @@ export class DriveFileRepository extends Repository { const key = thumbnail ? file.thumbnailAccessKey : file.webpublicAccessKey; if (key && !key.match('/')) { // 古いものはここにオブジェクトストレージキーが入ってるので除外 - let ext = ''; - - if (file.name) { - [ext] = (file.name.match(/\.(\w+)$/) || ['']); - } - - if (ext === '') { - if (file.type === 'image/jpeg') ext = '.jpg'; - if (file.type === 'image/png') ext = '.png'; - if (file.type === 'image/webp') ext = '.webp'; - if (file.type === 'image/apng') ext = '.apng'; - if (file.type === 'image/vnd.mozilla.apng') ext = '.apng'; - } - - return `/files/${key}/${key}${ext}`; + return `/files/${key}`; } } - return thumbnail ? (file.thumbnailUrl || file.webpublicUrl || null) : (file.webpublicUrl || file.url); + const isImage = file.type && ['image/png', 'image/apng', 'image/gif', 'image/jpeg', 'image/webp', 'image/svg+xml'].includes(file.type); + + return thumbnail ? (file.thumbnailUrl || (isImage ? (file.webpublicUrl || file.url) : null)) : (file.webpublicUrl || file.url); } public async clacDriveUsageOf(user: User['id'] | User): Promise { -- cgit v1.2.3-freya