* feat: admin add custom plugin * refresh plugins * plugin input box ui * fix: run plugin varialbes error * perf: comment * fix: ts
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { getSystemPlugins } from '@/service/core/app/plugin';
|
|
import { initSystemConfig } from '.';
|
|
import { createDatasetTrainingMongoWatch } from '@/service/core/dataset/training/utils';
|
|
import { MongoSystemConfigs } from '@fastgpt/service/common/system/config/schema';
|
|
import { MongoSystemPluginSchema } from '@fastgpt/service/core/app/plugin/systemPluginSchema';
|
|
|
|
export const startMongoWatch = async () => {
|
|
reloadConfigWatch();
|
|
refetchSystemPlugins();
|
|
createDatasetTrainingMongoWatch();
|
|
};
|
|
|
|
const reloadConfigWatch = () => {
|
|
const changeStream = MongoSystemConfigs.watch();
|
|
|
|
changeStream.on('change', async (change) => {
|
|
try {
|
|
if (change.operationType === 'insert') {
|
|
await initSystemConfig();
|
|
console.log('refresh system config');
|
|
}
|
|
} catch (error) {}
|
|
});
|
|
};
|
|
|
|
const refetchSystemPlugins = () => {
|
|
const changeStream = MongoSystemPluginSchema.watch();
|
|
|
|
changeStream.on('change', async (change) => {
|
|
setTimeout(() => {
|
|
try {
|
|
getSystemPlugins(true);
|
|
} catch (error) {}
|
|
}, 5000);
|
|
});
|
|
};
|