enhance(server): better content type detection
This commit is contained in:
parent
fe3609451e
commit
d53795184c
4 changed files with 40 additions and 4 deletions
|
|
@ -6,6 +6,7 @@ import { createTemp } from '@/misc/create-temp';
|
|||
import { downloadUrl } from '@/misc/download-url';
|
||||
import { detectType } from '@/misc/get-file-info';
|
||||
import { StatusError } from '@/misc/fetch';
|
||||
import { FILE_TYPE_WHITELIST } from '@/const';
|
||||
|
||||
export async function proxyMedia(ctx: Koa.Context) {
|
||||
const url = 'url' in ctx.query ? ctx.query.url : 'https://' + ctx.params.url;
|
||||
|
|
@ -18,7 +19,7 @@ export async function proxyMedia(ctx: Koa.Context) {
|
|||
|
||||
const { mime, ext } = await detectType(path);
|
||||
|
||||
if (!mime.startsWith('image/')) throw 403;
|
||||
if (!FILE_TYPE_WHITELIST.includes(mime)) throw 403;
|
||||
|
||||
let image: IImage;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue