import { migrateSettings } from './lib/migration/settings' ; import { initSettings } from './lib/settings' ; import { initCustomFields } from './lib/custom-fields' ; import { initRouters } from './lib/routers/index' ; import { ensureProsodyRunning , ensureProsodyNotRunning } from './lib/prosody/ctl' ; import decache from 'decache' ; let OPTIONS ; async function register ( options ) { OPTIONS = options ; if ( ! options . peertubeHelpers . plugin ) { throw new Error ( 'Your peertube version is not correct. This plugin is not compatible with Peertube < 3.2.0.' ) ; } await migrateSettings ( options ) ; await initSettings ( options ) ; await initCustomFields ( options ) ; await initRouters ( options ) ; try { await ensureProsodyRunning ( options ) ; } catch ( error ) { options . peertubeHelpers . logger . error ( 'Error when launching Prosody: ' + ( error as string ) ) ; } } async function unregister ( ) { if ( OPTIONS ) { try { await ensureProsodyNotRunning ( OPTIONS ) ; } catch ( error ) { OPTIONS . peertubeHelpers . logger . error ( 'Error when trying to unload Prosody: ' + ( error as string ) ) ; } } const module = __filename ; OPTIONS ?. peertubeHelpers . logger . info ( `Unloading module ${ module }...` ) ; decache ( module ) ; OPTIONS ?. peertubeHelpers . logger . info ( `Successfully unloaded the module ${ module }` ) ; OPTIONS = undefined ; } module . exports = { register , unregister } ;