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