refactor
This commit is contained in:
@ -14,7 +14,7 @@ import { detectType } from '@/misc/get-file-info';
|
||||
import { convertToJpeg, convertToPngOrJpeg } from '@/services/drive/image-processor';
|
||||
import { GenerateVideoThumbnail } from '@/services/drive/generate-video-thumbnail';
|
||||
import { StatusError } from '@/misc/fetch';
|
||||
import { FILE_TYPE_WHITELIST } from '@/const';
|
||||
import { FILE_TYPE_BROWSERSAFE } from '@/const';
|
||||
|
||||
//const _filename = fileURLToPath(import.meta.url);
|
||||
const _filename = __filename;
|
||||
@ -83,7 +83,7 @@ export default async function(ctx: Koa.Context) {
|
||||
|
||||
const image = await convertFile();
|
||||
ctx.body = image.data;
|
||||
ctx.set('Content-Type', FILE_TYPE_WHITELIST.includes(image.type) ? image.type : 'application/octet-stream');
|
||||
ctx.set('Content-Type', FILE_TYPE_BROWSERSAFE.includes(image.type) ? image.type : 'application/octet-stream');
|
||||
ctx.set('Cache-Control', 'max-age=31536000, immutable');
|
||||
} catch (e) {
|
||||
serverLogger.error(`${e}`);
|
||||
@ -114,14 +114,14 @@ export default async function(ctx: Koa.Context) {
|
||||
}).toString();
|
||||
|
||||
ctx.body = InternalStorage.read(key);
|
||||
ctx.set('Content-Type', FILE_TYPE_WHITELIST.includes(mime) ? mime : 'application/octet-stream');
|
||||
ctx.set('Content-Type', FILE_TYPE_BROWSERSAFE.includes(mime) ? mime : 'application/octet-stream');
|
||||
ctx.set('Cache-Control', 'max-age=31536000, immutable');
|
||||
ctx.set('Content-Disposition', contentDisposition('inline', filename));
|
||||
} else {
|
||||
const readable = InternalStorage.read(file.accessKey!);
|
||||
readable.on('error', commonReadableHandlerGenerator(ctx));
|
||||
ctx.body = readable;
|
||||
ctx.set('Content-Type', FILE_TYPE_WHITELIST.includes(file.type) ? file.type : 'application/octet-stream');
|
||||
ctx.set('Content-Type', FILE_TYPE_BROWSERSAFE.includes(file.type) ? file.type : 'application/octet-stream');
|
||||
ctx.set('Cache-Control', 'max-age=31536000, immutable');
|
||||
ctx.set('Content-Disposition', contentDisposition('inline', file.name));
|
||||
}
|
||||
|
@ -6,7 +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';
|
||||
import { FILE_TYPE_BROWSERSAFE } from '@/const';
|
||||
|
||||
export async function proxyMedia(ctx: Koa.Context) {
|
||||
const url = 'url' in ctx.query ? ctx.query.url : 'https://' + ctx.params.url;
|
||||
@ -19,7 +19,7 @@ export async function proxyMedia(ctx: Koa.Context) {
|
||||
|
||||
const { mime, ext } = await detectType(path);
|
||||
|
||||
if (!FILE_TYPE_WHITELIST.includes(mime)) throw 403;
|
||||
if (!FILE_TYPE_BROWSERSAFE.includes(mime)) throw 403;
|
||||
|
||||
let image: IImage;
|
||||
|
||||
|
Reference in New Issue
Block a user