mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
Merge pull request #1065 from Hexastack/1063-issue---onapplicationbootstrap-remove-unused-settings
fix(api): resolve CLI removing settings
This commit is contained in:
commit
ef4c61b735
@ -9,7 +9,7 @@
|
|||||||
import { INestApplication } from '@nestjs/common';
|
import { INestApplication } from '@nestjs/common';
|
||||||
|
|
||||||
export class AppInstance {
|
export class AppInstance {
|
||||||
private static app: INestApplication;
|
private static app: INestApplication | null = null;
|
||||||
|
|
||||||
static setApp(app: INestApplication) {
|
static setApp(app: INestApplication) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
@ -21,4 +21,13 @@ export class AppInstance {
|
|||||||
}
|
}
|
||||||
return this.app;
|
return this.app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the application context is initialized.
|
||||||
|
* This may return `false` in environments where the app instance is not set,
|
||||||
|
* such as when running in test env or CLI mode without a full application bootstrap.
|
||||||
|
*/
|
||||||
|
static isReady(): boolean {
|
||||||
|
return this.app !== null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import { Module, OnApplicationBootstrap } from '@nestjs/common';
|
|||||||
import { MongooseModule } from '@nestjs/mongoose';
|
import { MongooseModule } from '@nestjs/mongoose';
|
||||||
import { PassportModule } from '@nestjs/passport';
|
import { PassportModule } from '@nestjs/passport';
|
||||||
|
|
||||||
|
import { AppInstance } from '@/app.instance';
|
||||||
import { config } from '@/config';
|
import { config } from '@/config';
|
||||||
import { UserModule } from '@/user/user.module';
|
import { UserModule } from '@/user/user.module';
|
||||||
|
|
||||||
@ -34,6 +35,10 @@ import { AttachmentService } from './services/attachment.service';
|
|||||||
})
|
})
|
||||||
export class AttachmentModule implements OnApplicationBootstrap {
|
export class AttachmentModule implements OnApplicationBootstrap {
|
||||||
onApplicationBootstrap() {
|
onApplicationBootstrap() {
|
||||||
|
if (!AppInstance.isReady()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure the directories exists
|
// Ensure the directories exists
|
||||||
if (!existsSync(config.parameters.uploadDir)) {
|
if (!existsSync(config.parameters.uploadDir)) {
|
||||||
mkdirSync(config.parameters.uploadDir, { recursive: true });
|
mkdirSync(config.parameters.uploadDir, { recursive: true });
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
import { Global, Module, OnApplicationBootstrap } from '@nestjs/common';
|
import { Global, Module, OnApplicationBootstrap } from '@nestjs/common';
|
||||||
|
|
||||||
|
import { AppInstance } from '@/app.instance';
|
||||||
import { LoggerService } from '@/logger/logger.service';
|
import { LoggerService } from '@/logger/logger.service';
|
||||||
|
|
||||||
import { CleanupService } from './cleanup.service';
|
import { CleanupService } from './cleanup.service';
|
||||||
@ -24,6 +25,11 @@ export class ExtensionModule implements OnApplicationBootstrap {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
async onApplicationBootstrap() {
|
async onApplicationBootstrap() {
|
||||||
|
if (!AppInstance.isReady()) {
|
||||||
|
// bypass in test or CLI env
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.cleanupService.pruneExtensionSettings();
|
await this.cleanupService.pruneExtensionSettings();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -10,6 +10,7 @@ import { Injectable, OnApplicationBootstrap } from '@nestjs/common';
|
|||||||
import { OnEvent } from '@nestjs/event-emitter';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
import Handlebars from 'handlebars';
|
import Handlebars from 'handlebars';
|
||||||
|
|
||||||
|
import { AppInstance } from '@/app.instance';
|
||||||
import { HelperService } from '@/helper/helper.service';
|
import { HelperService } from '@/helper/helper.service';
|
||||||
import BaseNlpHelper from '@/helper/lib/base-nlp-helper';
|
import BaseNlpHelper from '@/helper/lib/base-nlp-helper';
|
||||||
import { HelperType, LLM, NLU } from '@/helper/types';
|
import { HelperType, LLM, NLU } from '@/helper/types';
|
||||||
@ -89,6 +90,11 @@ export default class LlmNluHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
async onApplicationBootstrap() {
|
async onApplicationBootstrap() {
|
||||||
|
if (!AppInstance.isReady()) {
|
||||||
|
// bypass in Test / CLI env
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.logger.log('Initializing LLM NLU helper, building prompts...');
|
this.logger.log('Initializing LLM NLU helper, building prompts...');
|
||||||
// Build prompts for language and trait classifiers
|
// Build prompts for language and trait classifiers
|
||||||
|
Loading…
Reference in New Issue
Block a user