aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/videos/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-02 15:47:05 +0200
committerChocobozzz <me@florianbigard.com>2021-06-02 16:57:53 +0200
commit304a84d59c3a800b7f7aef48cf55f307534c0926 (patch)
treee099aefd76aa8ee5aacef7ddfc59d79111fe474b /server/lib/activitypub/videos/shared
parentc56faf0d9453490737f283b29a203bb1ca632b95 (diff)
downloadPeerTube-304a84d59c3a800b7f7aef48cf55f307534c0926.tar.gz
PeerTube-304a84d59c3a800b7f7aef48cf55f307534c0926.tar.zst
PeerTube-304a84d59c3a800b7f7aef48cf55f307534c0926.zip
Refactor getOrCreateAPVideo
Diffstat (limited to 'server/lib/activitypub/videos/shared')
-rw-r--r--server/lib/activitypub/videos/shared/index.ts1
-rw-r--r--server/lib/activitypub/videos/shared/url-to-object.ts22
2 files changed, 23 insertions, 0 deletions
diff --git a/server/lib/activitypub/videos/shared/index.ts b/server/lib/activitypub/videos/shared/index.ts
index 208a43705..951403493 100644
--- a/server/lib/activitypub/videos/shared/index.ts
+++ b/server/lib/activitypub/videos/shared/index.ts
@@ -2,4 +2,5 @@ export * from './abstract-builder'
2export * from './creator' 2export * from './creator'
3export * from './object-to-model-attributes' 3export * from './object-to-model-attributes'
4export * from './trackers' 4export * from './trackers'
5export * from './url-to-object'
5export * from './video-sync-attributes' 6export * from './video-sync-attributes'
diff --git a/server/lib/activitypub/videos/shared/url-to-object.ts b/server/lib/activitypub/videos/shared/url-to-object.ts
new file mode 100644
index 000000000..b1ecac8ca
--- /dev/null
+++ b/server/lib/activitypub/videos/shared/url-to-object.ts
@@ -0,0 +1,22 @@
1import { checkUrlsSameHost } from '@server/helpers/activitypub'
2import { sanitizeAndCheckVideoTorrentObject } from '@server/helpers/custom-validators/activitypub/videos'
3import { logger } from '@server/helpers/logger'
4import { doJSONRequest } from '@server/helpers/requests'
5import { VideoObject } from '@shared/models'
6
7async function fetchRemoteVideo (videoUrl: string): Promise<{ statusCode: number, videoObject: VideoObject }> {
8 logger.info('Fetching remote video %s.', videoUrl)
9
10 const { statusCode, body } = await doJSONRequest<any>(videoUrl, { activityPub: true })
11
12 if (sanitizeAndCheckVideoTorrentObject(body) === false || checkUrlsSameHost(body.id, videoUrl) !== true) {
13 logger.debug('Remote video JSON is not valid.', { body })
14 return { statusCode, videoObject: undefined }
15 }
16
17 return { statusCode, videoObject: body }
18}
19
20export {
21 fetchRemoteVideo
22}