From 299474e8279675adb6c5ce140e7e39c6f3439453 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 2 Aug 2018 16:33:29 +0200 Subject: Add ability to remove a video import --- server/helpers/custom-validators/video-imports.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/video-imports.ts b/server/helpers/custom-validators/video-imports.ts index 36c0559fd..d8b9bfaff 100644 --- a/server/helpers/custom-validators/video-imports.ts +++ b/server/helpers/custom-validators/video-imports.ts @@ -3,6 +3,9 @@ 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' function isVideoImportTargetUrlValid (url: string) { const isURLOptions = { @@ -22,9 +25,25 @@ function isVideoImportStateValid (value: any) { 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 +} + // --------------------------------------------------------------------------- export { isVideoImportStateValid, - isVideoImportTargetUrlValid + isVideoImportTargetUrlValid, + isVideoImportExist } -- cgit v1.2.3