import type { RegisterServerOptions, Video } from '@peertube/peertube-types' async function initCustomFields (options: RegisterServerOptions): Promise { const registerHook = options.registerHook const storageManager = options.storageManager const logger = options.peertubeHelpers.logger registerHook({ target: 'action:api.video.updated', handler: async (params: any) => { logger.debug('Saving a video, checking for custom fields') const body: any = params.body const video: Video | undefined = params.video if (!video || !video.id) { return } if (!body.pluginData) return const value = body.pluginData['livechat-active'] // NB: on Peertube 3.2.1, value is "true", "false", or "null", as strings. if (value === true || value === 'true') { logger.info(`Saving livechat-active=true for video ${video.id.toString()}`) await storageManager.storeData(`livechat-active-${video.id.toString()}`, true) } else if (value === false || value === 'false' || value === 'null') { logger.info(`Saving livechat-active=false for video ${video.id.toString()}`) await storageManager.storeData(`livechat-active-${video.id.toString()}`, false) } else { logger.error('Unknown value ' + JSON.stringify(value) + ' for livechat-active field.') } } }) registerHook({ target: 'filter:api.video.get.result', handler: async (video: Video): Promise