mirror of
https://github.com/kokonect-link/cherrypick
synced 2024-10-31 23:31:48 +09:00
/proxyでemoji, avatarなどの命令がありかつ画像でないなら404を返すように
This commit is contained in:
parent
7651353f39
commit
19035c676c
@ -255,8 +255,21 @@ export class FileServerService {
|
|||||||
const isConvertibleImage = isMimeImage(file.mime, 'sharp-convertible-image');
|
const isConvertibleImage = isMimeImage(file.mime, 'sharp-convertible-image');
|
||||||
const isAnimationConvertibleImage = isMimeImage(file.mime, 'sharp-animation-convertible-image');
|
const isAnimationConvertibleImage = isMimeImage(file.mime, 'sharp-animation-convertible-image');
|
||||||
|
|
||||||
|
if (
|
||||||
|
'emoji' in request.query ||
|
||||||
|
'avatar' in request.query ||
|
||||||
|
'static' in request.query ||
|
||||||
|
'preview' in request.query ||
|
||||||
|
'badge' in request.query
|
||||||
|
) {
|
||||||
|
if (!isConvertibleImage) {
|
||||||
|
// 画像でないなら404でお茶を濁す
|
||||||
|
throw new StatusError('Unexpected mime', 404);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let image: IImageStreamable | null = null;
|
let image: IImageStreamable | null = null;
|
||||||
if (('emoji' in request.query || 'avatar' in request.query) && isConvertibleImage) {
|
if ('emoji' in request.query || 'avatar' in request.query) {
|
||||||
if (!isAnimationConvertibleImage && !('static' in request.query)) {
|
if (!isAnimationConvertibleImage && !('static' in request.query)) {
|
||||||
image = {
|
image = {
|
||||||
data: fs.createReadStream(file.path),
|
data: fs.createReadStream(file.path),
|
||||||
@ -277,16 +290,11 @@ export class FileServerService {
|
|||||||
type: 'image/webp',
|
type: 'image/webp',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else if ('static' in request.query && isConvertibleImage) {
|
} else if ('static' in request.query) {
|
||||||
image = this.imageProcessingService.convertToWebpStream(file.path, 498, 280);
|
image = this.imageProcessingService.convertToWebpStream(file.path, 498, 280);
|
||||||
} else if ('preview' in request.query && isConvertibleImage) {
|
} else if ('preview' in request.query) {
|
||||||
image = this.imageProcessingService.convertToWebpStream(file.path, 200, 200);
|
image = this.imageProcessingService.convertToWebpStream(file.path, 200, 200);
|
||||||
} else if ('badge' in request.query) {
|
} else if ('badge' in request.query) {
|
||||||
if (!isConvertibleImage) {
|
|
||||||
// 画像でないなら404でお茶を濁す
|
|
||||||
throw new StatusError('Unexpected mime', 404);
|
|
||||||
}
|
|
||||||
|
|
||||||
const mask = sharp(file.path)
|
const mask = sharp(file.path)
|
||||||
.resize(96, 96, {
|
.resize(96, 96, {
|
||||||
fit: 'inside',
|
fit: 'inside',
|
||||||
|
Loading…
Reference in New Issue
Block a user