This commit is contained in:
tamaina 2025-09-04 11:30:23 +09:00
parent b398347744
commit 4c21f88209
1 changed files with 19 additions and 5 deletions

View File

@ -332,23 +332,37 @@ export class FileServerService {
type: file.mime, type: file.mime,
size: file.size, size: file.size,
}; };
} else if (!('static' in request.query)) {
// animated
const data = (await sharpBmp(file.path, file.mime, { animated: true }))
.resize({
height: 'emoji' in request.query ? 128 : 320,
withoutEnlargement: true,
});
// byte range requestになる可能性があるので、Content-Lengthを送信するためにbufferにする
image = {
data: await data.webp(webpDefault).toBuffer(),
ext: 'webp',
type: 'image/webp',
};
} else { } else {
const data = (await sharpBmp(file.path, file.mime, { animated: !('static' in request.query) })) const data = (await sharpBmp(file.path, file.mime, { animated: false }))
.resize({ .resize({
height: 'emoji' in request.query ? 128 : 320, height: 'emoji' in request.query ? 128 : 320,
withoutEnlargement: true, withoutEnlargement: true,
}); });
image = { image = {
data: await data.webp(webpDefault).toBuffer(), data: data.webp(webpDefault),
ext: 'webp', ext: 'webp',
type: 'image/webp', type: 'image/webp',
}; };
} }
} else if ('static' in request.query) { } else if ('static' in request.query) {
image = await this.imageProcessingService.convertSharpToWebp(await sharpBmp(file.path, file.mime), 498, 422); image = this.imageProcessingService.convertSharpToWebpStream(await sharpBmp(file.path, file.mime), 498, 422);
} else if ('preview' in request.query) { } else if ('preview' in request.query) {
image = await this.imageProcessingService.convertSharpToWebp(await sharpBmp(file.path, file.mime), 200, 200); image = this.imageProcessingService.convertSharpToWebpStream(await sharpBmp(file.path, file.mime), 200, 200);
} else if ('badge' in request.query) { } else if ('badge' in request.query) {
const mask = (await sharpBmp(file.path, file.mime)) const mask = (await sharpBmp(file.path, file.mime))
.resize(96, 96, { .resize(96, 96, {
@ -381,7 +395,7 @@ export class FileServerService {
type: 'image/png', type: 'image/png',
}; };
} else if (file.mime === 'image/svg+xml') { } else if (file.mime === 'image/svg+xml') {
image = await this.imageProcessingService.convertToWebp(file.path, 2048, 2048); image = this.imageProcessingService.convertToWebpStream(file.path, 2048, 2048);
} else if (!file.mime.startsWith('image/') || !FILE_TYPE_BROWSERSAFE.includes(file.mime)) { } else if (!file.mime.startsWith('image/') || !FILE_TYPE_BROWSERSAFE.includes(file.mime)) {
throw new StatusError('Rejected type', 403, 'Rejected type'); throw new StatusError('Rejected type', 403, 'Rejected type');
} }