2017-11-09 10:51:58 -06:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2017-11-10 07:34:45 -06:00
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
2017-11-09 10:51:58 -06:00
|
|
|
export {
|
2017-11-10 07:34:45 -06:00
|
|
|
isActivityPubUrlValid,
|
|
|
|
isBaseActivityValid
|
2017-11-09 10:51:58 -06:00
|
|
|
}
|