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