1
0
Fork 0
peertube/server/helpers/custom-validators/activitypub/cache-file.ts
2020-01-28 11:35:26 +01:00

26 lines
925 B
TypeScript

import { isActivityPubUrlValid } from './misc'
import { isRemoteVideoUrlValid } from './videos'
import { exists, isDateValid } from '../misc'
import { CacheFileObject } from '../../../../shared/models/activitypub/objects'
function isCacheFileObjectValid (object: CacheFileObject) {
return exists(object) &&
object.type === 'CacheFile' &&
(object.expires === null || isDateValid(object.expires)) &&
isActivityPubUrlValid(object.object) &&
(isRemoteVideoUrlValid(object.url) || isPlaylistRedundancyUrlValid(object.url))
}
// ---------------------------------------------------------------------------
export {
isCacheFileObjectValid
}
// ---------------------------------------------------------------------------
function isPlaylistRedundancyUrlValid (url: any) {
return url.type === 'Link' &&
(url.mediaType || url.mimeType) === 'application/x-mpegURL' &&
isActivityPubUrlValid(url.href)
}