X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fvideo-captions.ts;h=9abbce04a110b3e7fae1b1fb5429ae6303b808df;hb=2ad9dcda240ee843c5e4a5b98cc94f7b2aab2c89;hp=177e9e86ed45b475e1e9f007bb3ad2c091a00023;hpb=2769e297ca6703f761f9b57792585eb1fc5aac49;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/video-captions.ts b/server/helpers/custom-validators/video-captions.ts index 177e9e86e..9abbce04a 100644 --- a/server/helpers/custom-validators/video-captions.ts +++ b/server/helpers/custom-validators/video-captions.ts @@ -1,14 +1,11 @@ -import { CONSTRAINTS_FIELDS, VIDEO_CAPTIONS_MIMETYPE_EXT, VIDEO_LANGUAGES } from '../../initializers' +import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_LANGUAGES } from '../../initializers/constants' import { exists, isFileValid } from './misc' -import { Response } from 'express' -import { VideoModel } from '../../models/video/video' -import { VideoCaptionModel } from '../../models/video/video-caption' function isVideoCaptionLanguageValid (value: any) { - return exists(value) && VIDEO_LANGUAGES[ value ] !== undefined + return exists(value) && VIDEO_LANGUAGES[value] !== undefined } -const videoCaptionTypes = Object.keys(VIDEO_CAPTIONS_MIMETYPE_EXT) +const videoCaptionTypes = Object.keys(MIMETYPES.VIDEO_CAPTIONS.MIMETYPE_EXT) .concat([ 'application/octet-stream' ]) // MacOS sends application/octet-stream >< .map(m => `(${m})`) const videoCaptionTypesRegex = videoCaptionTypes.join('|') @@ -16,25 +13,9 @@ function isVideoCaptionFile (files: { [ fieldname: string ]: Express.Multer.File return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) } -async function isVideoCaptionExist (video: VideoModel, language: string, res: Response) { - const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language) - - if (!videoCaption) { - res.status(404) - .json({ error: 'Video caption not found' }) - .end() - - return false - } - - res.locals.videoCaption = videoCaption - return true -} - // --------------------------------------------------------------------------- export { isVideoCaptionFile, - isVideoCaptionLanguageValid, - isVideoCaptionExist + isVideoCaptionLanguageValid }