2023-04-20 14:07:00 +00:00
|
|
|
import type { RegisterServerOptions, VideoObject } from '@peertube/peertube-types'
|
|
|
|
import type { VideoBuildResultContext, RemoteVideoHandlerParams } from './types'
|
|
|
|
import { videoBuildJSONLD } from './outgoing'
|
|
|
|
import { readIncomingAPVideo } from './incoming'
|
2023-04-19 17:07:08 +00:00
|
|
|
|
|
|
|
export async function initFederation (options: RegisterServerOptions): Promise<void> {
|
|
|
|
const logger = options.peertubeHelpers.logger
|
|
|
|
const registerHook = options.registerHook
|
|
|
|
logger.info('Registring federation hooks...')
|
|
|
|
|
|
|
|
registerHook({
|
|
|
|
target: 'filter:activity-pub.video.json-ld.build.result',
|
2023-04-20 14:07:00 +00:00
|
|
|
handler: async (jsonld: VideoObject, context: VideoBuildResultContext) => {
|
|
|
|
return videoBuildJSONLD(options, jsonld, context)
|
2023-04-19 17:07:08 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// TODO: we should also register the context.build hook.
|
|
|
|
// registerHook({
|
|
|
|
// target: 'filter:activity-pub.activity.context.build.result',
|
|
|
|
// handler: (jsonld: any) => {
|
2023-04-20 14:07:00 +00:00
|
|
|
// return videoContectBuildJSONLD(options, jsonld)
|
2023-04-19 17:07:08 +00:00
|
|
|
// }
|
|
|
|
// })
|
|
|
|
|
|
|
|
registerHook({
|
|
|
|
target: 'action:activity-pub.remote-video.created',
|
2023-04-20 14:07:00 +00:00
|
|
|
handler: async (params: RemoteVideoHandlerParams) => {
|
|
|
|
return readIncomingAPVideo(options, params)
|
|
|
|
}
|
2023-04-19 17:07:08 +00:00
|
|
|
})
|
|
|
|
registerHook({
|
|
|
|
target: 'action:activity-pub.remote-video.updated',
|
2023-04-20 14:07:00 +00:00
|
|
|
handler: async (params: RemoteVideoHandlerParams) => {
|
|
|
|
return readIncomingAPVideo(options, params)
|
|
|
|
}
|
2023-04-19 17:07:08 +00:00
|
|
|
})
|
|
|
|
}
|