2021-04-08 02:43:13 +02:00
|
|
|
import { initSettings } from './lib/settings'
|
|
|
|
import { initRouters } from './lib/routers'
|
2021-04-08 03:47:55 +02:00
|
|
|
import type { Logger } from 'winston'
|
|
|
|
|
|
|
|
const decache = require('decache')
|
|
|
|
let logger: Logger | undefined
|
2021-04-07 16:52:38 +02:00
|
|
|
|
2019-07-26 14:56:58 +02:00
|
|
|
async function register ({
|
|
|
|
registerSetting,
|
2021-02-20 20:42:41 +01:00
|
|
|
settingsManager,
|
2021-02-20 18:31:21 +01:00
|
|
|
getRouter,
|
|
|
|
peertubeHelpers
|
2021-04-07 16:52:38 +02:00
|
|
|
}: RegisterServerOptions): Promise<any> {
|
2021-04-08 03:47:55 +02:00
|
|
|
logger = peertubeHelpers.logger
|
|
|
|
|
2021-04-08 02:43:13 +02:00
|
|
|
await initSettings({ registerSetting })
|
|
|
|
await initRouters({
|
|
|
|
settingsManager,
|
|
|
|
getRouter,
|
|
|
|
peertubeHelpers
|
2021-02-20 18:31:21 +01:00
|
|
|
})
|
2019-07-16 16:39:36 +02:00
|
|
|
}
|
|
|
|
|
2021-04-07 17:20:28 +02:00
|
|
|
async function unregister (): Promise<any> {
|
2021-04-08 03:47:55 +02:00
|
|
|
const module = __filename
|
|
|
|
logger?.info(`Unloading module ${module}...`)
|
2021-04-09 10:54:51 +02:00
|
|
|
// In peertube <= 3.1.0 sub modules are not removed from require.cache
|
2021-04-08 03:47:55 +02:00
|
|
|
decache(module)
|
|
|
|
logger?.info(`Successfully unloaded the module ${module}`)
|
2021-04-09 10:54:51 +02:00
|
|
|
logger = undefined
|
2019-07-16 16:39:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
register,
|
|
|
|
unregister
|
|
|
|
}
|