2021-06-02 09:47:05 -04:00
|
|
|
import { checkUrlsSameHost } from '@server/helpers/activitypub'
|
|
|
|
import { sanitizeAndCheckVideoTorrentObject } from '@server/helpers/custom-validators/activitypub/videos'
|
2021-06-02 10:49:59 -04:00
|
|
|
import { logger, loggerTagsFactory } from '@server/helpers/logger'
|
2021-06-02 09:47:05 -04:00
|
|
|
import { doJSONRequest } from '@server/helpers/requests'
|
|
|
|
import { VideoObject } from '@shared/models'
|
|
|
|
|
2021-06-02 10:49:59 -04:00
|
|
|
const lTags = loggerTagsFactory('ap', 'video')
|
|
|
|
|
2021-06-02 09:47:05 -04:00
|
|
|
async function fetchRemoteVideo (videoUrl: string): Promise<{ statusCode: number, videoObject: VideoObject }> {
|
2021-06-02 10:49:59 -04:00
|
|
|
logger.info('Fetching remote video %s.', videoUrl, lTags(videoUrl))
|
2021-06-02 09:47:05 -04:00
|
|
|
|
|
|
|
const { statusCode, body } = await doJSONRequest<any>(videoUrl, { activityPub: true })
|
|
|
|
|
|
|
|
if (sanitizeAndCheckVideoTorrentObject(body) === false || checkUrlsSameHost(body.id, videoUrl) !== true) {
|
2021-06-02 10:49:59 -04:00
|
|
|
logger.debug('Remote video JSON is not valid.', { body, ...lTags(videoUrl) })
|
|
|
|
|
2021-06-02 09:47:05 -04:00
|
|
|
return { statusCode, videoObject: undefined }
|
|
|
|
}
|
|
|
|
|
|
|
|
return { statusCode, videoObject: body }
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
fetchRemoteVideo
|
|
|
|
}
|