Compare commits
No commits in common. "9748d89079350921255f5e1b932dad33e08bf495" and "5c7682c13108c5bb40bfbd821b6c70478975351c" have entirely different histories.
9748d89079
...
5c7682c131
|
|
@ -22,16 +22,15 @@
|
||||||
"pg": "^8.16.0",
|
"pg": "^8.16.0",
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
"rxjs": "^7.8.2",
|
"rxjs": "^7.8.2",
|
||||||
|
"typeorm": "^0.3.24",
|
||||||
"uid": "^2.0.2"
|
"uid": "^2.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bcrypt": "^5.0.0",
|
"@types/bcrypt": "^5.0.0",
|
||||||
"@types/node": "^22.15.30",
|
|
||||||
"@types/passport-jwt": "^4.0.1",
|
"@types/passport-jwt": "^4.0.1",
|
||||||
"rimraf": "^6.0.1",
|
"rimraf": "^6.0.1",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"tsconfig-paths": "^4.2.0",
|
"tsconfig-paths": "^4.2.0",
|
||||||
"typeorm": "^0.3.24",
|
|
||||||
"typescript": "^5.8.3"
|
"typescript": "^5.8.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,8 @@
|
||||||
"build": "rimraf dist && tsc",
|
"build": "rimraf dist && tsc",
|
||||||
"start": "npm run build && node dist/main.js",
|
"start": "npm run build && node dist/main.js",
|
||||||
"dev": "ts-node -r tsconfig-paths/register src/main.ts",
|
"dev": "ts-node -r tsconfig-paths/register src/main.ts",
|
||||||
"typeorma": "typeorm-ts-node-commonjs -d dist/data-source.js",
|
"typeorm": "typeorm-ts-node-commonjs -d dist/data-source.js",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
"typeorm": "ts-node -r ts-node/register ./node_modules/typeorm/cli.js",
|
|
||||||
"migration:generate": "npm run typeorm migration:generate -d dist/data-source.js",
|
|
||||||
"migration:run": "npm run typeorm migration:run -- --dataSource dist/data-source.js"
|
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
|
|
@ -30,16 +27,15 @@
|
||||||
"pg": "^8.16.0",
|
"pg": "^8.16.0",
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
"rxjs": "^7.8.2",
|
"rxjs": "^7.8.2",
|
||||||
|
"typeorm": "^0.3.24",
|
||||||
"uid": "^2.0.2"
|
"uid": "^2.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bcrypt": "^5.0.0",
|
"@types/bcrypt": "^5.0.0",
|
||||||
"@types/node": "^22.15.30",
|
|
||||||
"@types/passport-jwt": "^4.0.1",
|
"@types/passport-jwt": "^4.0.1",
|
||||||
"rimraf": "^6.0.1",
|
"rimraf": "^6.0.1",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"tsconfig-paths": "^4.2.0",
|
"tsconfig-paths": "^4.2.0",
|
||||||
"typeorm": "^0.3.24",
|
|
||||||
"typescript": "^5.8.3"
|
"typescript": "^5.8.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
||||||
|
|
||||||
export class AddForeignKeys1690 implements MigrationInterface {
|
|
||||||
async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
// 1. User与Workspace的关联
|
|
||||||
await queryRunner.query(`
|
|
||||||
ALTER TABLE "user"
|
|
||||||
ADD CONSTRAINT "fk_user_workspace"
|
|
||||||
FOREIGN KEY ("workspaceId")
|
|
||||||
REFERENCES "workspace"("id")
|
|
||||||
ON DELETE CASCADE
|
|
||||||
`);
|
|
||||||
|
|
||||||
// 2. AiConfig与Workspace的关联
|
|
||||||
await queryRunner.query(`
|
|
||||||
ALTER TABLE "ai_config"
|
|
||||||
ADD CONSTRAINT "fk_ai_config_workspace"
|
|
||||||
FOREIGN KEY ("workspaceId")
|
|
||||||
REFERENCES "workspace"("id")
|
|
||||||
ON DELETE CASCADE
|
|
||||||
`);
|
|
||||||
|
|
||||||
// 3. Project与Workspace的关联
|
|
||||||
await queryRunner.query(`
|
|
||||||
ALTER TABLE "project"
|
|
||||||
ADD CONSTRAINT "fk_project_workspace"
|
|
||||||
FOREIGN KEY ("workspaceId")
|
|
||||||
REFERENCES "workspace"("id")
|
|
||||||
ON DELETE CASCADE
|
|
||||||
`);
|
|
||||||
|
|
||||||
// 4. PluginConfig与Workspace的关联
|
|
||||||
await queryRunner.query(`
|
|
||||||
ALTER TABLE "plugin_config"
|
|
||||||
ADD CONSTRAINT "fk_plugin_config_workspace"
|
|
||||||
FOREIGN KEY ("workspaceId")
|
|
||||||
REFERENCES "workspace"("id")
|
|
||||||
ON DELETE CASCADE
|
|
||||||
`);
|
|
||||||
}
|
|
||||||
|
|
||||||
async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
// 删除外键约束
|
|
||||||
const foreignKeys = [
|
|
||||||
'fk_user_workspace',
|
|
||||||
'fk_ai_config_workspace',
|
|
||||||
'fk_project_workspace',
|
|
||||||
'fk_plugin_config_workspace'
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const fk of foreignKeys) {
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE ${fk.split('_').slice(2).join('_')} DROP CONSTRAINT ${fk}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
import { Controller, Post, Body, Param } from '@nestjs/common';
|
|
||||||
import { PluginService } from './plugin.service';
|
|
||||||
|
|
||||||
@Controller('plugins')
|
|
||||||
export class PluginController {
|
|
||||||
constructor(private readonly pluginService: PluginService) {}
|
|
||||||
|
|
||||||
|
|
||||||
@Post(':id/execute')
|
|
||||||
async execute(
|
|
||||||
@Param('id') pluginId: string,
|
|
||||||
@Body() executionArgs: Record<string, any>
|
|
||||||
) {
|
|
||||||
return this.pluginService.executePlugin(pluginId, executionArgs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
|
||||||
import { PluginConfig } from './plugin-config.entity';
|
|
||||||
|
|
||||||
@EntityRepository(PluginConfig)
|
|
||||||
export class PluginRepository extends Repository<PluginConfig> {
|
|
||||||
// 可以在这里添加自定义查询方法
|
|
||||||
}
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
||||||
import { PluginConfig } from './plugin-config.entity';
|
|
||||||
import { PluginRepository } from './plugin.repository';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class PluginService {
|
|
||||||
constructor(private readonly pluginRepository: PluginRepository) {}
|
|
||||||
|
|
||||||
async executePlugin(pluginId: string, args: Record<string, any>): Promise<any> {
|
|
||||||
// 1. 获取插件配置
|
|
||||||
const pluginConfig = await this.pluginRepository.findOne({ where: { pluginId } });
|
|
||||||
|
|
||||||
if (!pluginConfig) {
|
|
||||||
throw new NotFoundException(`Plugin ${pluginId} not found`);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 2. 动态加载插件模块(假设插件以npm包形式安装)
|
|
||||||
const pluginModule = require.resolve(pluginId);
|
|
||||||
const plugin = require(pluginModule);
|
|
||||||
|
|
||||||
// 3. 验证插件接口(假设插件必须实现execute方法)
|
|
||||||
if (typeof plugin.execute !== 'function') {
|
|
||||||
throw new Error(`Plugin ${pluginId} missing required execute method`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. 执行插件并返回结果
|
|
||||||
return await plugin.execute({
|
|
||||||
...args,
|
|
||||||
config: pluginConfig.settings // 传递插件配置
|
|
||||||
});
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
throw new Error(`Failed to execute plugin ${pluginId}: ${error}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue