async function initCustomFields ( options ) { const registerHook = options . registerHook ; const storageManager = options . storageManager ; const logger = options . peertubeHelpers . logger ; registerHook ( { target : 'action:api.video.updated' , handler : async ( params ) => { logger . debug ( 'Saving a video, checking for custom fields' ) ; const body = params . body ; const video = params . video ; if ( ! video || ! video . id ) { return ; } if ( ! body . pluginData ) return ; const value = body . pluginData [ 'livechat-active' ] ; if ( value === true || value === 'true' ) { logger . info ( `Saving livechat-active=true for video ${ video . id }` ) ; await storageManager . storeData ( `livechat-active-${ video . id }` , true ) ; } else if ( value === false || value === 'false' || value === 'null' ) { logger . info ( `Saving livechat-active=false for video ${ video . id }` ) ; await storageManager . storeData ( `livechat-active-${ video . id }` , false ) ; } else { logger . error ( 'Unknown value ' + JSON . stringify ( value ) + ' for livechat-active field.' ) ; } } } ) ; registerHook ( { target : 'filter:api.video.get.result' , handler : async ( video ) : Promise < MVideoThumbnail > => { logger . debug ( 'Getting a video, searching for custom fields' ) ; await fillVideoCustomFields ( options , video ) ; return video ; } } ) ; } async function fillVideoCustomFields ( options , video ) { if ( ! video ) return video ; if ( ! video . pluginData ) video . pluginData = { } ; if ( ! video . id ) return ; const storageManager = options . storageManager ; const logger = options . peertubeHelpers . logger ; if ( video . isLive ) { const result = await storageManager . getData ( `livechat-active-${ video . id }` ) ; logger . debug ( `Video ${ video . id } has livechat-active=` + JSON . stringify ( result ) ) ; if ( result === true || result === 'true' ) { video . pluginData [ 'livechat-active' ] = true ; } else if ( result === false || result === 'false' || result === 'null' ) { video . pluginData [ 'livechat-active' ] = false ; } } } export { initCustomFields , fillVideoCustomFields } ;