PeerTube/server/helpers/custom-validators/activitypub/cache-file.ts

29 lines
904 B
TypeScript
Raw Normal View History

2018-09-11 16:27:07 +02:00
import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
import { isRemoteVideoUrlValid } from './videos'
import { isDateValid, exists } from '../misc'
import { CacheFileObject } from '../../../../shared/models/activitypub/objects'
function isCacheFileCreateActivityValid (activity: any) {
return isBaseActivityValid(activity, 'Create') &&
isCacheFileObjectValid(activity.object)
}
function isCacheFileUpdateActivityValid (activity: any) {
return isBaseActivityValid(activity, 'Update') &&
isCacheFileObjectValid(activity.object)
}
function isCacheFileObjectValid (object: CacheFileObject) {
return exists(object) &&
object.type === 'CacheFile' &&
isDateValid(object.expires) &&
isActivityPubUrlValid(object.object) &&
isRemoteVideoUrlValid(object.url)
}
export {
isCacheFileUpdateActivityValid,
isCacheFileCreateActivityValid,
isCacheFileObjectValid
}