2017-11-10 14:34:45 +01:00
|
|
|
import * as validator from 'validator'
|
2017-05-15 22:22:03 +02:00
|
|
|
|
|
|
|
import {
|
2017-11-10 14:34:45 +01:00
|
|
|
ACTIVITY_PUB
|
2017-05-15 22:22:03 +02:00
|
|
|
} from '../../../initializers'
|
2017-11-10 14:34:45 +01:00
|
|
|
import { isDateValid, isUUIDValid } from '../misc'
|
2017-05-15 22:22:03 +02:00
|
|
|
import {
|
|
|
|
isVideoViewsValid,
|
|
|
|
isVideoNSFWValid,
|
2017-10-30 10:16:27 +01:00
|
|
|
isVideoTruncatedDescriptionValid,
|
2017-05-15 22:22:03 +02:00
|
|
|
isVideoDurationValid,
|
|
|
|
isVideoNameValid,
|
2017-11-14 10:57:56 +01:00
|
|
|
isVideoTagValid,
|
|
|
|
isVideoUrlValid
|
2017-05-15 22:22:03 +02:00
|
|
|
} from '../videos'
|
2017-10-24 19:41:09 +02:00
|
|
|
import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels'
|
2017-11-10 14:34:45 +01:00
|
|
|
import { isBaseActivityValid } from './misc'
|
|
|
|
|
|
|
|
function isVideoTorrentAddActivityValid (activity: any) {
|
|
|
|
return isBaseActivityValid(activity, 'Add') &&
|
|
|
|
isVideoTorrentObjectValid(activity.object)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isVideoTorrentUpdateActivityValid (activity: any) {
|
|
|
|
return isBaseActivityValid(activity, 'Update') &&
|
|
|
|
isVideoTorrentObjectValid(activity.object)
|
2017-05-15 22:22:03 +02:00
|
|
|
}
|
|
|
|
|
2017-11-10 14:34:45 +01:00
|
|
|
function isVideoTorrentObjectValid (video: any) {
|
|
|
|
return video.type === 'Video' &&
|
|
|
|
isVideoNameValid(video.name) &&
|
|
|
|
isVideoDurationValid(video.duration) &&
|
|
|
|
isUUIDValid(video.uuid) &&
|
|
|
|
setValidRemoteTags(video) &&
|
|
|
|
isRemoteIdentifierValid(video.category) &&
|
|
|
|
isRemoteIdentifierValid(video.licence) &&
|
|
|
|
isRemoteIdentifierValid(video.language) &&
|
|
|
|
isVideoViewsValid(video.video) &&
|
|
|
|
isVideoNSFWValid(video.nsfw) &&
|
|
|
|
isDateValid(video.published) &&
|
|
|
|
isDateValid(video.updated) &&
|
|
|
|
isRemoteVideoContentValid(video.mediaType, video.content) &&
|
|
|
|
isRemoteVideoIconValid(video.icon) &&
|
|
|
|
setValidRemoteVideoUrls(video.url)
|
2017-05-15 22:22:03 +02:00
|
|
|
}
|
|
|
|
|
2017-11-10 14:34:45 +01:00
|
|
|
function isVideoChannelCreateActivityValid (activity: any) {
|
|
|
|
return isBaseActivityValid(activity, 'Create') &&
|
|
|
|
isVideoChannelObjectValid(activity.object)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isVideoChannelUpdateActivityValid (activity: any) {
|
|
|
|
return isBaseActivityValid(activity, 'Update') &&
|
|
|
|
isVideoChannelObjectValid(activity.object)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isVideoChannelObjectValid (videoChannel: any) {
|
|
|
|
return videoChannel.type === 'VideoChannel' &&
|
|
|
|
isVideoChannelNameValid(videoChannel.name) &&
|
|
|
|
isVideoChannelDescriptionValid(videoChannel.description) &&
|
|
|
|
isUUIDValid(videoChannel.uuid)
|
2017-05-15 22:22:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2017-11-10 14:34:45 +01:00
|
|
|
isVideoTorrentAddActivityValid,
|
|
|
|
isVideoChannelCreateActivityValid,
|
|
|
|
isVideoTorrentUpdateActivityValid,
|
|
|
|
isVideoChannelUpdateActivityValid
|
2017-05-15 22:22:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-11-10 14:34:45 +01:00
|
|
|
function setValidRemoteTags (video: any) {
|
|
|
|
if (Array.isArray(video.tag) === false) return false
|
2017-05-15 22:22:03 +02:00
|
|
|
|
2017-11-10 14:34:45 +01:00
|
|
|
const newTag = video.tag.filter(t => {
|
|
|
|
return t.type === 'Hashtag' &&
|
|
|
|
isVideoTagValid(t.name)
|
|
|
|
})
|
2017-10-24 19:41:09 +02:00
|
|
|
|
2017-11-10 14:34:45 +01:00
|
|
|
video.tag = newTag
|
|
|
|
return true
|
2017-10-24 19:41:09 +02:00
|
|
|
}
|
|
|
|
|
2017-11-10 14:34:45 +01:00
|
|
|
function isRemoteIdentifierValid (data: any) {
|
|
|
|
return validator.isInt(data.identifier, { min: 0 })
|
2017-10-24 19:41:09 +02:00
|
|
|
}
|
|
|
|
|
2017-11-10 14:34:45 +01:00
|
|
|
function isRemoteVideoContentValid (mediaType: string, content: string) {
|
|
|
|
return mediaType === 'text/markdown' && isVideoTruncatedDescriptionValid(content)
|
2017-10-24 19:41:09 +02:00
|
|
|
}
|
|
|
|
|
2017-11-10 14:34:45 +01:00
|
|
|
function isRemoteVideoIconValid (icon: any) {
|
|
|
|
return icon.type === 'Image' &&
|
2017-11-14 10:57:56 +01:00
|
|
|
isVideoUrlValid(icon.url) &&
|
2017-11-10 14:34:45 +01:00
|
|
|
icon.mediaType === 'image/jpeg' &&
|
|
|
|
validator.isInt(icon.width, { min: 0 }) &&
|
|
|
|
validator.isInt(icon.height, { min: 0 })
|
2017-10-24 19:41:09 +02:00
|
|
|
}
|
|
|
|
|
2017-11-10 14:34:45 +01:00
|
|
|
function setValidRemoteVideoUrls (video: any) {
|
|
|
|
if (Array.isArray(video.url) === false) return false
|
2017-05-15 22:22:03 +02:00
|
|
|
|
2017-11-10 14:34:45 +01:00
|
|
|
const newUrl = video.url.filter(u => isRemoteVideoUrlValid(u))
|
|
|
|
video.url = newUrl
|
2017-05-15 22:22:03 +02:00
|
|
|
|
2017-11-10 14:34:45 +01:00
|
|
|
return true
|
2017-05-15 22:22:03 +02:00
|
|
|
}
|
|
|
|
|
2017-11-10 14:34:45 +01:00
|
|
|
function isRemoteVideoUrlValid (url: any) {
|
|
|
|
return url.type === 'Link' &&
|
|
|
|
ACTIVITY_PUB.VIDEO_URL_MIME_TYPES.indexOf(url.mimeType) !== -1 &&
|
2017-11-14 10:57:56 +01:00
|
|
|
isVideoUrlValid(url.url) &&
|
2017-11-10 14:34:45 +01:00
|
|
|
validator.isInt(url.width, { min: 0 }) &&
|
|
|
|
validator.isInt(url.size, { min: 0 })
|
2017-05-15 22:22:03 +02:00
|
|
|
}
|