2018-08-02 08:34:09 -05:00
|
|
|
import 'express-validator'
|
|
|
|
import 'multer'
|
|
|
|
import * as validator from 'validator'
|
|
|
|
import { CONSTRAINTS_FIELDS, VIDEO_IMPORT_STATES } from '../../initializers'
|
|
|
|
import { exists } from './misc'
|
2018-08-02 09:33:29 -05:00
|
|
|
import * as express from 'express'
|
|
|
|
import { VideoChannelModel } from '../../models/video/video-channel'
|
|
|
|
import { VideoImportModel } from '../../models/video/video-import'
|
2018-08-02 08:34:09 -05:00
|
|
|
|
|
|
|
function isVideoImportTargetUrlValid (url: string) {
|
|
|
|
const isURLOptions = {
|
|
|
|
require_host: true,
|
|
|
|
require_tld: true,
|
|
|
|
require_protocol: true,
|
|
|
|
require_valid_protocol: true,
|
|
|
|
protocols: [ 'http', 'https' ]
|
|
|
|
}
|
|
|
|
|
|
|
|
return exists(url) &&
|
|
|
|
validator.isURL('' + url, isURLOptions) &&
|
|
|
|
validator.isLength('' + url, CONSTRAINTS_FIELDS.VIDEO_IMPORTS.URL)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isVideoImportStateValid (value: any) {
|
|
|
|
return exists(value) && VIDEO_IMPORT_STATES[ value ] !== undefined
|
|
|
|
}
|
|
|
|
|
2018-08-02 09:33:29 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-08-02 08:34:09 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
isVideoImportStateValid,
|
2018-08-02 09:33:29 -05:00
|
|
|
isVideoImportTargetUrlValid,
|
|
|
|
isVideoImportExist
|
2018-08-02 08:34:09 -05:00
|
|
|
}
|