X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fvideo-imports.ts;h=8820c4c0aa47f2a27ca75124b9c0383f8d5994c3;hb=6aa541481390980f9c85d2e66514ba0e6ce77a35;hp=d8b9bfaff09ba6274e00e79975a0ba6536192671;hpb=9a12f169c15b638fe78cf6e85a1993550a25e404;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/video-imports.ts b/server/helpers/custom-validators/video-imports.ts index d8b9bfaff..8820c4c0a 100644 --- a/server/helpers/custom-validators/video-imports.ts +++ b/server/helpers/custom-validators/video-imports.ts @@ -1,10 +1,8 @@ -import 'express-validator' import 'multer' import * as validator from 'validator' -import { CONSTRAINTS_FIELDS, VIDEO_IMPORT_STATES } from '../../initializers' -import { exists } from './misc' +import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_IMPORT_STATES } from '../../initializers/constants' +import { exists, isFileValid } from './misc' import * as express from 'express' -import { VideoChannelModel } from '../../models/video/video-channel' import { VideoImportModel } from '../../models/video/video-import' function isVideoImportTargetUrlValid (url: string) { @@ -25,7 +23,13 @@ function isVideoImportStateValid (value: any) { return exists(value) && VIDEO_IMPORT_STATES[ value ] !== undefined } -async function isVideoImportExist (id: number, res: express.Response) { +const videoTorrentImportTypes = Object.keys(MIMETYPES.TORRENT.MIMETYPE_EXT).map(m => `(${m})`) +const videoTorrentImportRegex = videoTorrentImportTypes.join('|') +function isVideoImportTorrentFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) { + return isFileValid(files, videoTorrentImportRegex, 'torrentfile', CONSTRAINTS_FIELDS.VIDEO_IMPORTS.TORRENT_FILE.FILE_SIZE.max, true) +} + +async function doesVideoImportExist (id: number, res: express.Response) { const videoImport = await VideoImportModel.loadAndPopulateVideo(id) if (!videoImport) { @@ -45,5 +49,6 @@ async function isVideoImportExist (id: number, res: express.Response) { export { isVideoImportStateValid, isVideoImportTargetUrlValid, - isVideoImportExist + doesVideoImportExist, + isVideoImportTorrentFile }