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