2021-06-02 03:35:01 -04:00
|
|
|
import { Transaction } from 'sequelize/types'
|
|
|
|
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'
|
2022-03-23 09:24:50 -04:00
|
|
|
import { buildRemoteVideoBaseUrl } from '../../url'
|
2021-06-02 03:35:01 -04:00
|
|
|
|
|
|
|
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[]
|
2021-06-08 11:29:45 -04:00
|
|
|
transaction: Transaction
|
2021-06-02 03:35:01 -04:00
|
|
|
}) {
|
|
|
|
const { video, trackers, transaction } = options
|
|
|
|
|
|
|
|
const trackerInstances = await TrackerModel.findOrCreateTrackers(trackers, transaction)
|
|
|
|
|
|
|
|
await video.$set('Trackers', trackerInstances, { transaction })
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
getTrackerUrls,
|
|
|
|
setVideoTrackers
|
|
|
|
}
|