X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fvideo-imports.ts;h=33a1fa8ab9ccdd9fffa1d59961a33bf85b395080;hb=3b0bd70aa05ab82fa30fe67ed4899d44652c703a;hp=4d6ab1fa41cf6578300bcb45292808f56ce281cf;hpb=990b6a0b0c4fbebc165e5cf7cec8fbc1cbaa6c66;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/video-imports.ts b/server/helpers/custom-validators/video-imports.ts index 4d6ab1fa4..33a1fa8ab 100644 --- a/server/helpers/custom-validators/video-imports.ts +++ b/server/helpers/custom-validators/video-imports.ts @@ -1,7 +1,6 @@ -import 'express-validator' import 'multer' -import * as validator from 'validator' -import { CONSTRAINTS_FIELDS, TORRENT_MIMETYPE_EXT, VIDEO_IMPORT_STATES } from '../../initializers' +import validator from 'validator' +import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_IMPORT_STATES } from '../../initializers/constants' import { exists, isFileValid } from './misc' import * as express from 'express' import { VideoImportModel } from '../../models/video/video-import' @@ -21,16 +20,18 @@ function isVideoImportTargetUrlValid (url: string) { } function isVideoImportStateValid (value: any) { - return exists(value) && VIDEO_IMPORT_STATES[ value ] !== undefined + return exists(value) && VIDEO_IMPORT_STATES[value] !== undefined } -const videoTorrentImportTypes = Object.keys(TORRENT_MIMETYPE_EXT).map(m => `(${m})`) -const videoTorrentImportRegex = videoTorrentImportTypes.join('|') +const videoTorrentImportRegex = Object.keys(MIMETYPES.TORRENT.MIMETYPE_EXT) + .concat([ 'application/octet-stream' ]) // MacOS sends application/octet-stream + .map(m => `(${m})`) + .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 isVideoImportExist (id: number, res: express.Response) { +async function doesVideoImportExist (id: number, res: express.Response) { const videoImport = await VideoImportModel.loadAndPopulateVideo(id) if (!videoImport) { @@ -50,6 +51,6 @@ async function isVideoImportExist (id: number, res: express.Response) { export { isVideoImportStateValid, isVideoImportTargetUrlValid, - isVideoImportExist, + doesVideoImportExist, isVideoImportTorrentFile }