2021-06-02 15:47:05 +02:00
|
|
|
import { sanitizeAndCheckVideoTorrentObject } from '@server/helpers/custom-validators/activitypub/videos'
|
2021-06-02 16:49:59 +02:00
|
|
|
import { logger, loggerTagsFactory } from '@server/helpers/logger'
|
2021-06-02 15:47:05 +02:00
|
|
|
import { VideoObject } from '@shared/models'
|
2023-07-27 17:01:15 +02:00
|
|
|
import { fetchAP } from '../../activity'
|
2022-03-23 14:24:50 +01:00
|
|
|
import { checkUrlsSameHost } from '../../url'
|
2021-06-02 15:47:05 +02:00
|
|
|
|
2021-06-02 16:49:59 +02:00
|
|
|
const lTags = loggerTagsFactory('ap', 'video')
|
|
|
|
|
2021-06-02 15:47:05 +02:00
|
|
|
async function fetchRemoteVideo (videoUrl: string): Promise<{ statusCode: number, videoObject: VideoObject }> {
|
2021-06-02 16:49:59 +02:00
|
|
|
logger.info('Fetching remote video %s.', videoUrl, lTags(videoUrl))
|
2021-06-02 15:47:05 +02:00
|
|
|
|
2023-07-27 17:01:15 +02:00
|
|
|
const { statusCode, body } = await fetchAP<any>(videoUrl)
|
2021-06-02 15:47:05 +02:00
|
|
|
|
|
|
|
if (sanitizeAndCheckVideoTorrentObject(body) === false || checkUrlsSameHost(body.id, videoUrl) !== true) {
|
2021-06-02 16:49:59 +02:00
|
|
|
logger.debug('Remote video JSON is not valid.', { body, ...lTags(videoUrl) })
|
|
|
|
|
2021-06-02 15:47:05 +02:00
|
|
|
return { statusCode, videoObject: undefined }
|
|
|
|
}
|
|
|
|
|
|
|
|
return { statusCode, videoObject: body }
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
fetchRemoteVideo
|
|
|
|
}
|