| 24 | } |
| 25 | |
| 26 | public async onModuleInit() { |
| 27 | if (this.config.ENABLED) { |
| 28 | const url = `http://${this.config.HOST}:${this.config.PORT}`; |
| 29 | try { |
| 30 | const response = await axios.options(url + '/ping'); |
| 31 | if (response?.data != 'pong') { |
| 32 | throw new Error('Offline file provider.'); |
| 33 | } |
| 34 | |
| 35 | await axios.post(`${url}/session`, { group: this.config.PREFIX }, { headers: { apikey: this.globalApiToken } }); |
| 36 | } catch (error) { |
| 37 | this.logger.error(['Failed to connect to the file server', error?.message, error?.stack]); |
| 38 | const pid = process.pid; |
| 39 | execFileSync('kill', ['-9', `${pid}`]); |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | public async onModuleDestroy() { |
| 45 | // |