mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-29 09:58:36 +01:00
add mimetype check
This commit is contained in:
parent
9bb1e79c83
commit
c88c8af8d9
2 changed files with 19 additions and 0 deletions
|
@ -24,6 +24,18 @@ export const DB_MAX_NOTE_TEXT_LENGTH = 8192;
|
|||
export const DB_MAX_IMAGE_COMMENT_LENGTH = 512;
|
||||
//#endregion
|
||||
|
||||
export const FILE_TYPE_IMAGE = [
|
||||
'image/png',
|
||||
'image/gif',
|
||||
'image/jpeg',
|
||||
'image/webp',
|
||||
'image/avif',
|
||||
'image/apng',
|
||||
'image/bmp',
|
||||
'image/tiff',
|
||||
'image/x-icon',
|
||||
];
|
||||
|
||||
// ブラウザで直接表示することを許可するファイルの種類のリスト
|
||||
// ここに含まれないものは application/octet-stream としてレスポンスされる
|
||||
// SVGはXSSを生むので許可しない
|
||||
|
|
|
@ -9,6 +9,7 @@ import type { DriveFilesRepository } from '@/models/_.js';
|
|||
import { DI } from '@/di-symbols.js';
|
||||
import { CustomEmojiService } from '@/core/CustomEmojiService.js';
|
||||
import { EmojiEntityService } from '@/core/entities/EmojiEntityService.js';
|
||||
import { FILE_TYPE_IMAGE } from '@/const.js';
|
||||
import { ApiError } from '../../../error.js';
|
||||
|
||||
export const meta = {
|
||||
|
@ -24,6 +25,11 @@ export const meta = {
|
|||
code: 'NO_SUCH_FILE',
|
||||
id: 'fc46b5a4-6b92-4c33-ac66-b806659bb5cf',
|
||||
},
|
||||
notSupportFileType: {
|
||||
message: 'Not support file type.',
|
||||
code: 'NOT_SUPPORT_FILE_TYPE',
|
||||
id: 'f7599d96-8750-af68-1633-9575d625c1a7',
|
||||
},
|
||||
duplicateName: {
|
||||
message: 'Duplicate name.',
|
||||
code: 'DUPLICATE_NAME',
|
||||
|
@ -78,6 +84,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
if (driveFile == null) throw new ApiError(meta.errors.noSuchFile);
|
||||
const isDuplicate = await this.customEmojiService.checkDuplicate(ps.name);
|
||||
if (isDuplicate) throw new ApiError(meta.errors.duplicateName);
|
||||
if (!FILE_TYPE_IMAGE.includes(driveFile.type)) throw new ApiError(meta.errors.notSupportFileType);
|
||||
|
||||
const emoji = await this.customEmojiService.add({
|
||||
driveFile,
|
||||
|
|
Loading…
Reference in a new issue