import { values } from 'lodash'
import 'multer'
import * as validator from 'validator'
-import { UserRight, VideoPrivacy, VideoRateType } from '../../../shared'
+import { UserRight, VideoFilter, VideoPrivacy, VideoRateType } from '../../../shared'
import {
CONSTRAINTS_FIELDS,
VIDEO_CATEGORIES,
import { VideoChannelModel } from '../../models/video/video-channel'
import { UserModel } from '../../models/account/user'
import * as magnetUtil from 'magnet-uri'
+import { fetchVideo, VideoFetchType } from '../video'
const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS
+function isVideoFilterValid (filter: VideoFilter) {
+ return filter === 'local' || filter === 'all-local'
+}
+
function isVideoCategoryValid (value: any) {
return value === null || VIDEO_CATEGORIES[ value ] !== undefined
}
return true
}
-export type VideoFetchType = 'all' | 'only-video' | 'id' | 'none'
async function isVideoExist (id: string, res: Response, fetchType: VideoFetchType = 'all') {
- let video: VideoModel | null
-
- if (fetchType === 'all') {
- video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id)
- } else if (fetchType === 'only-video') {
- video = await VideoModel.load(id)
- } else if (fetchType === 'id' || fetchType === 'none') {
- video = await VideoModel.loadOnlyId(id)
- }
+ const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined
+
+ const video = await fetchVideo(id, fetchType, userId)
if (video === null) {
res.status(404)
isVideoExist,
isVideoImage,
isVideoChannelOfAccountExist,
- isVideoSupportValid
+ isVideoSupportValid,
+ isVideoFilterValid
}