X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fvideo-imports.ts;h=0063d3337fd96749c65396f3514363577e9587e1;hb=e62f03ae0412f4efa62917d8741bc1a39e8ed7fc;hp=ce9e9193cebf5b0d9fc977067a2ca2ed327a3919;hpb=73471b1a52f242e86364ffb077ea6cadb3b07ae2;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/video-imports.ts b/server/helpers/custom-validators/video-imports.ts index ce9e9193c..0063d3337 100644 --- a/server/helpers/custom-validators/video-imports.ts +++ b/server/helpers/custom-validators/video-imports.ts @@ -1,10 +1,10 @@ -import 'express-validator' import 'multer' -import * as validator from 'validator' -import { CONSTRAINTS_FIELDS, MIMETYPES, 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' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' function isVideoImportTargetUrlValid (url: string) { const isURLOptions = { @@ -21,20 +21,22 @@ 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(MIMETYPES.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) { - res.status(404) + res.status(HttpStatusCode.NOT_FOUND_404) .json({ error: 'Video import not found' }) .end() @@ -50,6 +52,6 @@ async function isVideoImportExist (id: number, res: express.Response) { export { isVideoImportStateValid, isVideoImportTargetUrlValid, - isVideoImportExist, + doesVideoImportExist, isVideoImportTorrentFile }