]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/videos/shared/url-to-object.ts
Support more plugin helpers in embed
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / videos / shared / url-to-object.ts
CommitLineData
304a84d5
C
1import { checkUrlsSameHost } from '@server/helpers/activitypub'
2import { sanitizeAndCheckVideoTorrentObject } from '@server/helpers/custom-validators/activitypub/videos'
46320694 3import { logger, loggerTagsFactory } from '@server/helpers/logger'
304a84d5
C
4import { doJSONRequest } from '@server/helpers/requests'
5import { VideoObject } from '@shared/models'
6
46320694
C
7const lTags = loggerTagsFactory('ap', 'video')
8
304a84d5 9async 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
23export {
24 fetchRemoteVideo
25}