2024-05-23 09:42:14 +00:00
|
|
|
// SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-04-20 14:07:00 +00:00
|
|
|
import type { RegisterServerOptions, VideoObject } from '@peertube/peertube-types'
|
|
|
|
import type { VideoBuildResultContext, RemoteVideoHandlerParams } from './types'
|
2024-05-05 10:47:33 +00:00
|
|
|
import { videoBuildJSONLD, videoContextBuildJSONLD } from './outgoing'
|
2023-04-20 14:07:00 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-05-05 10:47:33 +00:00
|
|
|
registerHook({
|
|
|
|
target: 'filter:activity-pub.activity.context.build.result',
|
2024-09-07 12:49:27 +00:00
|
|
|
handler: async (jsonld: any[]) => {
|
2024-05-05 10:47:33 +00:00
|
|
|
return videoContextBuildJSONLD(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
|
|
|
})
|
|
|
|
}
|