X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fvideo-captions.ts;h=528edf60ce6810a01a19b1491eb42f7438e38b8d;hb=de6310b2fcbb8a6b79c546b23dfa1920724faaa7;hp=6a9c6d75ce5492dc84926c31a3c80a1c8f668edd;hpb=f4001cf408a99049d01a356bfb20a62342de06ea;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/video-captions.ts b/server/helpers/custom-validators/video-captions.ts index 6a9c6d75c..528edf60c 100644 --- a/server/helpers/custom-validators/video-captions.ts +++ b/server/helpers/custom-validators/video-captions.ts @@ -1,38 +1,21 @@ -import { CONSTRAINTS_FIELDS, VIDEO_CAPTIONS_MIMETYPE_EXT, VIDEO_LANGUAGES, VIDEO_MIMETYPE_EXT } 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).map(m => `(${m})`) -const videoCaptionTypesRegex = videoCaptionTypes.join('|') +const videoCaptionTypesRegex = Object.keys(MIMETYPES.VIDEO_CAPTIONS.MIMETYPE_EXT) + .concat([ 'application/octet-stream' ]) // MacOS sends application/octet-stream + .map(m => `(${m})`) + .join('|') function isVideoCaptionFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], field: string) { 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 }