]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/videos/shared/url-to-object.ts
Remove activitypub helper
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / videos / shared / url-to-object.ts
CommitLineData
304a84d5 1import { sanitizeAndCheckVideoTorrentObject } from '@server/helpers/custom-validators/activitypub/videos'
46320694 2import { logger, loggerTagsFactory } from '@server/helpers/logger'
304a84d5
C
3import { doJSONRequest } from '@server/helpers/requests'
4import { VideoObject } from '@shared/models'
7e98a7df 5import { checkUrlsSameHost } from '../../url'
304a84d5 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}