X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fvideo-imports.ts;h=af93aea56062a86ca17b1e441c8b9593de123632;hb=b8598d40f650a31fe09a4a5426dcdc2c5c0d566c;hp=d8b9bfaff09ba6274e00e79975a0ba6536192671;hpb=299474e8279675adb6c5ce140e7e39c6f3439453;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..af93aea56 100644 --- a/server/helpers/custom-validators/video-imports.ts +++ b/server/helpers/custom-validators/video-imports.ts @@ -1,11 +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 * as express from 'express' -import { VideoChannelModel } from '../../models/video/video-channel' -import { VideoImportModel } from '../../models/video/video-import' +import { UploadFilesForCheck } from 'express' +import validator from 'validator' +import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_IMPORT_STATES } from '../../initializers/constants' +import { exists, isFileValid } from './misc' function isVideoImportTargetUrlValid (url: string) { const isURLOptions = { @@ -22,22 +19,21 @@ function isVideoImportTargetUrlValid (url: string) { } function isVideoImportStateValid (value: any) { - return exists(value) && VIDEO_IMPORT_STATES[ value ] !== undefined + return exists(value) && VIDEO_IMPORT_STATES[value] !== undefined } -async function isVideoImportExist (id: number, res: express.Response) { - const videoImport = await VideoImportModel.loadAndPopulateVideo(id) - - if (!videoImport) { - res.status(404) - .json({ error: 'Video import not found' }) - .end() - - return false - } - - res.locals.videoImport = videoImport - return true +const videoTorrentImportRegex = Object.keys(MIMETYPES.TORRENT.MIMETYPE_EXT) + .concat([ 'application/octet-stream' ]) // MacOS sends application/octet-stream + .map(m => `(${m})`) + .join('|') +function isVideoImportTorrentFile (files: UploadFilesForCheck) { + return isFileValid({ + files, + mimeTypeRegex: videoTorrentImportRegex, + field: 'torrentfile', + maxSize: CONSTRAINTS_FIELDS.VIDEO_IMPORTS.TORRENT_FILE.FILE_SIZE.max, + optional: true + }) } // --------------------------------------------------------------------------- @@ -45,5 +41,5 @@ async function isVideoImportExist (id: number, res: express.Response) { export { isVideoImportStateValid, isVideoImportTargetUrlValid, - isVideoImportExist + isVideoImportTorrentFile }