]>
Commit | Line | Data |
---|---|---|
304a84d5 | 1 | import { sanitizeAndCheckVideoTorrentObject } from '@server/helpers/custom-validators/activitypub/videos' |
46320694 | 2 | import { logger, loggerTagsFactory } from '@server/helpers/logger' |
304a84d5 C |
3 | import { doJSONRequest } from '@server/helpers/requests' |
4 | import { VideoObject } from '@shared/models' | |
7e98a7df | 5 | import { checkUrlsSameHost } from '../../url' |
304a84d5 | 6 | |
46320694 C |
7 | const lTags = loggerTagsFactory('ap', 'video') |
8 | ||
304a84d5 | 9 | async function fetchRemoteVideo (videoUrl: string): Promise<{ statusCode: number, videoObject: VideoObject }> { |
46320694 | 10 | logger.info('Fetching remote video %s.', videoUrl, lTags(videoUrl)) |
304a84d5 C |
11 | |
12 | const { statusCode, body } = await doJSONRequest<any>(videoUrl, { activityPub: true }) | |
13 | ||
14 | if (sanitizeAndCheckVideoTorrentObject(body) === false || checkUrlsSameHost(body.id, videoUrl) !== true) { | |
46320694 C |
15 | logger.debug('Remote video JSON is not valid.', { body, ...lTags(videoUrl) }) |
16 | ||
304a84d5 C |
17 | return { statusCode, videoObject: undefined } |
18 | } | |
19 | ||
20 | return { statusCode, videoObject: body } | |
21 | } | |
22 | ||
23 | export { | |
24 | fetchRemoteVideo | |
25 | } |