1
0
Fork 0
peertube/server/helpers/custom-validators/activitypub/cache-file.ts

27 lines
925 B
TypeScript
Raw Normal View History

import { isActivityPubUrlValid } from './misc'
2018-09-11 10:27:07 -04:00
import { isRemoteVideoUrlValid } from './videos'
import { exists, isDateValid } from '../misc'
2018-09-11 10:27:07 -04:00
import { CacheFileObject } from '../../../../shared/models/activitypub/objects'
function isCacheFileObjectValid (object: CacheFileObject) {
return exists(object) &&
object.type === 'CacheFile' &&
2020-01-10 04:11:28 -05:00
(object.expires === null || isDateValid(object.expires)) &&
2018-09-11 10:27:07 -04:00
isActivityPubUrlValid(object.object) &&
2019-01-29 02:37:25 -05:00
(isRemoteVideoUrlValid(object.url) || isPlaylistRedundancyUrlValid(object.url))
2018-09-11 10:27:07 -04:00
}
2019-01-29 02:37:25 -05:00
// ---------------------------------------------------------------------------
2018-09-11 10:27:07 -04:00
export {
isCacheFileObjectValid
}
2019-01-29 02:37:25 -05:00
// ---------------------------------------------------------------------------
function isPlaylistRedundancyUrlValid (url: any) {
return url.type === 'Link' &&
(url.mediaType || url.mimeType) === 'application/x-mpegURL' &&
isActivityPubUrlValid(url.href)
}