]>
Commit | Line | Data |
---|---|---|
69290ab3 | 1 | import { Transaction } from 'sequelize/types' |
69290ab3 C |
2 | import { isAPVideoTrackerUrlObject } from '@server/helpers/custom-validators/activitypub/videos' |
3 | import { isArray } from '@server/helpers/custom-validators/misc' | |
4 | import { REMOTE_SCHEME } from '@server/initializers/constants' | |
5 | import { TrackerModel } from '@server/models/server/tracker' | |
6 | import { MVideo, MVideoWithHost } from '@server/types/models' | |
7 | import { ActivityTrackerUrlObject, VideoObject } from '@shared/models' | |
7e98a7df | 8 | import { buildRemoteVideoBaseUrl } from '../../url' |
69290ab3 C |
9 | |
10 | function getTrackerUrls (object: VideoObject, video: MVideoWithHost) { | |
11 | let wsFound = false | |
12 | ||
13 | const trackers = object.url.filter(u => isAPVideoTrackerUrlObject(u)) | |
14 | .map((u: ActivityTrackerUrlObject) => { | |
15 | if (isArray(u.rel) && u.rel.includes('websocket')) wsFound = true | |
16 | ||
17 | return u.href | |
18 | }) | |
19 | ||
20 | if (wsFound) return trackers | |
21 | ||
22 | return [ | |
23 | buildRemoteVideoBaseUrl(video, '/tracker/socket', REMOTE_SCHEME.WS), | |
24 | buildRemoteVideoBaseUrl(video, '/tracker/announce') | |
25 | ] | |
26 | } | |
27 | ||
28 | async function setVideoTrackers (options: { | |
29 | video: MVideo | |
30 | trackers: string[] | |
28dfb44b | 31 | transaction: Transaction |
69290ab3 C |
32 | }) { |
33 | const { video, trackers, transaction } = options | |
34 | ||
35 | const trackerInstances = await TrackerModel.findOrCreateTrackers(trackers, transaction) | |
36 | ||
37 | await video.$set('Trackers', trackerInstances, { transaction }) | |
38 | } | |
39 | ||
40 | export { | |
41 | getTrackerUrls, | |
42 | setVideoTrackers | |
43 | } |