1
0
Fork 0
peertube/server/helpers/custom-validators/activitypub/misc.ts
2017-11-27 19:40:51 +01:00

27 lines
673 B
TypeScript

import { exists } from '../misc'
function isActivityPubUrlValid (url: string) {
const isURLOptions = {
require_host: true,
require_tld: true,
require_protocol: true,
require_valid_protocol: true,
protocols: [ 'http', 'https' ]
}
return exists(url) && validator.isURL(url, isURLOptions)
}
function isBaseActivityValid (activity: any, type: string) {
return Array.isArray(activity['@context']) &&
activity.type === type &&
validator.isURL(activity.id) &&
validator.isURL(activity.actor) &&
Array.isArray(activity.to) &&
activity.to.every(t => validator.isURL(t))
}
export {
isActivityPubUrlValid,
isBaseActivityValid
}