カスタム絵文字にプロキシを復活 (#9481)
* wip * Revert "Update ClientServerService.ts" This reverts commit88c64ece78
. * Revert "disable custom emoji proxy temporary" This reverts commit495d513efd
. * ✌️
This commit is contained in:
parent
a42b03c154
commit
5ec89ea0c3
|
@ -3,6 +3,7 @@ import { FILE_TYPE_BROWSERSAFE } from '@/const.js';
|
|||
const dictionary = {
|
||||
'safe-file': FILE_TYPE_BROWSERSAFE,
|
||||
'sharp-convertible-image': ['image/jpeg', 'image/png', 'image/gif', 'image/apng', 'image/vnd.mozilla.apng', 'image/webp', 'image/avif', 'image/svg+xml'],
|
||||
'sharp-animation-convertible-image': ['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/avif', 'image/svg+xml'],
|
||||
};
|
||||
|
||||
export const isMimeImage = (mime: string, type: keyof typeof dictionary): boolean => dictionary[type].includes(mime);
|
||||
|
|
|
@ -79,10 +79,18 @@ export class MediaProxyServerService {
|
|||
|
||||
const { mime, ext } = await this.fileInfoService.detectType(path);
|
||||
const isConvertibleImage = isMimeImage(mime, 'sharp-convertible-image');
|
||||
const isAnimationConvertibleImage = isMimeImage(mime, 'sharp-animation-convertible-image');
|
||||
|
||||
let image: IImage;
|
||||
if ('emoji' in request.query && isConvertibleImage) {
|
||||
const data = await sharp(path, { animated: !('static' in request.query) })
|
||||
if (!isAnimationConvertibleImage && !('static' in request.query)) {
|
||||
image = {
|
||||
data: fs.readFileSync(path),
|
||||
ext,
|
||||
type: mime,
|
||||
};
|
||||
} else {
|
||||
const data = await sharp(path, { animated: !('static' in request.query) })
|
||||
.resize({
|
||||
height: 128,
|
||||
withoutEnlargement: true,
|
||||
|
@ -90,11 +98,12 @@ export class MediaProxyServerService {
|
|||
.webp(webpDefault)
|
||||
.toBuffer();
|
||||
|
||||
image = {
|
||||
data,
|
||||
ext: 'webp',
|
||||
type: 'image/webp',
|
||||
};
|
||||
image = {
|
||||
data,
|
||||
ext: 'webp',
|
||||
type: 'image/webp',
|
||||
};
|
||||
}
|
||||
} else if ('static' in request.query && isConvertibleImage) {
|
||||
image = await this.imageProcessingService.convertToWebp(path, 498, 280);
|
||||
} else if ('preview' in request.query && isConvertibleImage) {
|
||||
|
|
|
@ -251,10 +251,6 @@ export class ClientServerService {
|
|||
|
||||
reply.header('Content-Security-Policy', 'default-src \'none\'; style-src \'unsafe-inline\'');
|
||||
|
||||
// || emoji.originalUrl してるのは後方互換性のため(publicUrlはstringなので??はだめ)
|
||||
return await reply.redirect(301, emoji.publicUrl || emoji.originalUrl);
|
||||
|
||||
/* https://github.com/misskey-dev/misskey/pull/9431#issuecomment-1373006446
|
||||
const url = new URL('/proxy/emoji.webp', this.config.url);
|
||||
// || emoji.originalUrl してるのは後方互換性のため(publicUrlはstringなので??はだめ)
|
||||
url.searchParams.set('url', emoji.publicUrl || emoji.originalUrl);
|
||||
|
@ -265,7 +261,6 @@ export class ClientServerService {
|
|||
301,
|
||||
url.toString(),
|
||||
);
|
||||
*/
|
||||
});
|
||||
|
||||
fastify.get<{ Params: { path: string } }>('/fluent-emoji/:path(.*)', async (request, reply) => {
|
||||
|
|
Loading…
Reference in a new issue