diff options
author | Chocobozzz <me@florianbigard.com> | 2021-06-02 15:47:05 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-06-02 16:57:53 +0200 |
commit | 304a84d59c3a800b7f7aef48cf55f307534c0926 (patch) | |
tree | e099aefd76aa8ee5aacef7ddfc59d79111fe474b /server/lib/activitypub/videos/shared | |
parent | c56faf0d9453490737f283b29a203bb1ca632b95 (diff) | |
download | PeerTube-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.ts | 1 | ||||
-rw-r--r-- | server/lib/activitypub/videos/shared/url-to-object.ts | 22 |
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' | |||
2 | export * from './creator' | 2 | export * from './creator' |
3 | export * from './object-to-model-attributes' | 3 | export * from './object-to-model-attributes' |
4 | export * from './trackers' | 4 | export * from './trackers' |
5 | export * from './url-to-object' | ||
5 | export * from './video-sync-attributes' | 6 | export * 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 @@ | |||
1 | import { checkUrlsSameHost } from '@server/helpers/activitypub' | ||
2 | import { sanitizeAndCheckVideoTorrentObject } from '@server/helpers/custom-validators/activitypub/videos' | ||
3 | import { logger } from '@server/helpers/logger' | ||
4 | import { doJSONRequest } from '@server/helpers/requests' | ||
5 | import { VideoObject } from '@shared/models' | ||
6 | |||
7 | async 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 | |||
20 | export { | ||
21 | fetchRemoteVideo | ||
22 | } | ||