1 import { Transaction } from 'sequelize/types'
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'
8 import { buildRemoteVideoBaseUrl } from '../../url'
10 function getTrackerUrls (object: VideoObject, video: MVideoWithHost) {
13 const trackers = object.url.filter(u => isAPVideoTrackerUrlObject(u))
14 .map((u: ActivityTrackerUrlObject) => {
15 if (isArray(u.rel) && u.rel.includes('websocket')) wsFound = true
20 if (wsFound) return trackers
23 buildRemoteVideoBaseUrl(video, '/tracker/socket', REMOTE_SCHEME.WS),
24 buildRemoteVideoBaseUrl(video, '/tracker/announce')
28 async function setVideoTrackers (options: {
31 transaction: Transaction
33 const { video, trackers, transaction } = options
35 const trackerInstances = await TrackerModel.findOrCreateTrackers(trackers, transaction)
37 await video.$set('Trackers', trackerInstances, { transaction })