diff options
| author | tamaina <tamaina@hotmail.co.jp> | 2022-01-20 03:03:28 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-20 03:03:28 +0900 |
| commit | 74df9b57ecbf5c2557fe0454f1bed7c27eb6aa2f (patch) | |
| tree | f383db6fbc8847d65cc5d04fd0e5815f4029c422 /packages/backend/src/server/proxy | |
| parent | refactor(server): use named export (diff) | |
| download | sharkey-74df9b57ecbf5c2557fe0454f1bed7c27eb6aa2f.tar.gz sharkey-74df9b57ecbf5c2557fe0454f1bed7c27eb6aa2f.tar.bz2 sharkey-74df9b57ecbf5c2557fe0454f1bed7c27eb6aa2f.zip | |
fix: proxyでsvgをpngに変換するように (#8106)
* wip
* revert send-drive-file change
* fix
* Update packages/backend/src/server/proxy/proxy-media.ts
Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com>
Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com>
Diffstat (limited to 'packages/backend/src/server/proxy')
| -rw-r--r-- | packages/backend/src/server/proxy/proxy-media.ts | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/packages/backend/src/server/proxy/proxy-media.ts b/packages/backend/src/server/proxy/proxy-media.ts index aba08bb805..c234b70c55 100644 --- a/packages/backend/src/server/proxy/proxy-media.ts +++ b/packages/backend/src/server/proxy/proxy-media.ts @@ -19,15 +19,16 @@ export async function proxyMedia(ctx: Koa.Context) { const { mime, ext } = await detectType(path); - if (!mime.startsWith('image/')) throw 403; - if (!FILE_TYPE_BROWSERSAFE.includes(mime)) throw 403; - let image: IImage; - if ('static' in ctx.query && ['image/png', 'image/gif', 'image/apng', 'image/vnd.mozilla.apng', 'image/webp'].includes(mime)) { + if ('static' in ctx.query && ['image/png', 'image/gif', 'image/apng', 'image/vnd.mozilla.apng', 'image/webp', 'image/svg+xml'].includes(mime)) { image = await convertToPng(path, 498, 280); - } else if ('preview' in ctx.query && ['image/jpeg', 'image/png', 'image/gif', 'image/apng', 'image/vnd.mozilla.apng'].includes(mime)) { + } else if ('preview' in ctx.query && ['image/jpeg', 'image/png', 'image/gif', 'image/apng', 'image/vnd.mozilla.apng', 'image/svg+xml'].includes(mime)) { image = await convertToJpeg(path, 200, 200); + } else if (['image/svg+xml'].includes(mime)) { + image = await convertToPng(path, 2048, 2048); + } else if (!mime.startsWith('image/') || !FILE_TYPE_BROWSERSAFE.includes(mime)) { + throw new StatusError('Rejected type', 403, 'Rejected type'); } else { image = { data: fs.readFileSync(path), |