mirror of
https://github.com/vastxie/99AI.git
synced 2025-11-10 18:53:46 +08:00
v4.1.0
This commit is contained in:
80
AIWebQuickDeploy/dist/modules/plugin/plugin.controller.js
vendored
Normal file
80
AIWebQuickDeploy/dist/modules/plugin/plugin.controller.js
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PluginController = void 0;
|
||||
const superAuth_guard_1 = require("../../common/auth/superAuth.guard");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const plugin_service_1 = require("./plugin.service");
|
||||
let PluginController = class PluginController {
|
||||
constructor(pluginService) {
|
||||
this.pluginService = pluginService;
|
||||
}
|
||||
pluginList(req) {
|
||||
return this.pluginService.pluginList(req);
|
||||
}
|
||||
createPlugin(body) {
|
||||
return this.pluginService.createPlugin(body);
|
||||
}
|
||||
updatePlugin(body) {
|
||||
return this.pluginService.updatePlugin(body);
|
||||
}
|
||||
delPlugin(body) {
|
||||
return this.pluginService.delPlugin(body);
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Get)('pluginList'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '获取Plugin' }),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], PluginController.prototype, "pluginList", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('createPlugin'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '创建Plugin' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], PluginController.prototype, "createPlugin", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('updatePlugin'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '修改插件' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], PluginController.prototype, "updatePlugin", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('delPlugin'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '删除插件' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], PluginController.prototype, "delPlugin", null);
|
||||
PluginController = __decorate([
|
||||
(0, swagger_1.ApiTags)('Plugin'),
|
||||
(0, common_1.Controller)('plugin'),
|
||||
__metadata("design:paramtypes", [plugin_service_1.PluginService])
|
||||
], PluginController);
|
||||
exports.PluginController = PluginController;
|
||||
44
AIWebQuickDeploy/dist/modules/plugin/plugin.entity.js
vendored
Normal file
44
AIWebQuickDeploy/dist/modules/plugin/plugin.entity.js
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PluginEntity = void 0;
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
const typeorm_1 = require("typeorm");
|
||||
let PluginEntity = class PluginEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ unique: true, comment: '插件名称' }),
|
||||
__metadata("design:type", String)
|
||||
], PluginEntity.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '插件封面', nullable: true, type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], PluginEntity.prototype, "pluginImg", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '插件描述' }),
|
||||
__metadata("design:type", String)
|
||||
], PluginEntity.prototype, "description", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '插件是否启用 0:禁用 1:启用', default: 1 }),
|
||||
__metadata("design:type", Number)
|
||||
], PluginEntity.prototype, "isEnabled", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '调用参数', type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], PluginEntity.prototype, "parameters", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '排序值', default: 0 }),
|
||||
__metadata("design:type", Number)
|
||||
], PluginEntity.prototype, "sortOrder", void 0);
|
||||
PluginEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'plugin' })
|
||||
], PluginEntity);
|
||||
exports.PluginEntity = PluginEntity;
|
||||
24
AIWebQuickDeploy/dist/modules/plugin/plugin.module.js
vendored
Normal file
24
AIWebQuickDeploy/dist/modules/plugin/plugin.module.js
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PluginModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const plugin_controller_1 = require("./plugin.controller");
|
||||
const plugin_entity_1 = require("./plugin.entity");
|
||||
const plugin_service_1 = require("./plugin.service");
|
||||
let PluginModule = class PluginModule {
|
||||
};
|
||||
PluginModule = __decorate([
|
||||
(0, common_1.Module)({
|
||||
imports: [typeorm_1.TypeOrmModule.forFeature([plugin_entity_1.PluginEntity])],
|
||||
controllers: [plugin_controller_1.PluginController],
|
||||
providers: [plugin_service_1.PluginService],
|
||||
})
|
||||
], PluginModule);
|
||||
exports.PluginModule = PluginModule;
|
||||
112
AIWebQuickDeploy/dist/modules/plugin/plugin.service.js
vendored
Normal file
112
AIWebQuickDeploy/dist/modules/plugin/plugin.service.js
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PluginService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const typeorm_2 = require("typeorm");
|
||||
const models_service_1 = require("../models/models.service");
|
||||
const plugin_entity_1 = require("./plugin.entity");
|
||||
let PluginService = class PluginService {
|
||||
constructor(PluginEntity, modelsService) {
|
||||
this.PluginEntity = PluginEntity;
|
||||
this.modelsService = modelsService;
|
||||
}
|
||||
async pluginList(query) {
|
||||
const { page = 1, size = 100 } = query;
|
||||
const rows = await this.PluginEntity.find({
|
||||
order: { sortOrder: 'ASC', id: 'DESC' },
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
});
|
||||
const processedRows = await Promise.all(rows.map(async (plugin) => {
|
||||
try {
|
||||
const parameters = await this.modelsService.getCurrentModelKeyInfo(plugin.parameters);
|
||||
const deductType = parameters.deductType;
|
||||
return Object.assign(Object.assign({}, plugin), { deductType });
|
||||
}
|
||||
catch (error) {
|
||||
return Object.assign(Object.assign({}, plugin), { deductType: 0 });
|
||||
}
|
||||
}));
|
||||
const filteredRows = processedRows.filter((plugin) => plugin !== null);
|
||||
return { rows: filteredRows, count: filteredRows.length };
|
||||
}
|
||||
async createPlugin(body) {
|
||||
const { name, pluginImg, description, isEnabled, parameters, sortOrder } = body;
|
||||
const existingPlugin = await this.PluginEntity.findOne({
|
||||
where: { name },
|
||||
});
|
||||
if (existingPlugin) {
|
||||
throw new common_1.HttpException('该插件名称已存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const newPlugin = this.PluginEntity.create({
|
||||
name,
|
||||
pluginImg,
|
||||
description,
|
||||
isEnabled: isEnabled !== undefined ? isEnabled : 1,
|
||||
parameters,
|
||||
sortOrder: sortOrder !== undefined ? sortOrder : 0,
|
||||
});
|
||||
return await this.PluginEntity.save(newPlugin);
|
||||
}
|
||||
async updatePlugin(body) {
|
||||
const { id, name, pluginImg, description, isEnabled, parameters, sortOrder, } = body;
|
||||
const existingPlugin = await this.PluginEntity.findOne({
|
||||
where: { id },
|
||||
});
|
||||
if (!existingPlugin) {
|
||||
throw new common_1.HttpException('插件不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const duplicatePlugin = await this.PluginEntity.findOne({
|
||||
where: { name, id: (0, typeorm_2.Not)(id) },
|
||||
});
|
||||
if (duplicatePlugin) {
|
||||
throw new common_1.HttpException('该插件名称已存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
existingPlugin.name = name;
|
||||
existingPlugin.pluginImg = pluginImg;
|
||||
existingPlugin.description = description;
|
||||
existingPlugin.isEnabled =
|
||||
isEnabled !== undefined ? isEnabled : existingPlugin.isEnabled;
|
||||
existingPlugin.parameters = parameters;
|
||||
existingPlugin.sortOrder =
|
||||
sortOrder !== undefined ? sortOrder : existingPlugin.sortOrder;
|
||||
await this.PluginEntity.save(existingPlugin);
|
||||
return '修改插件信息成功';
|
||||
}
|
||||
async delPlugin(body) {
|
||||
const { id } = body;
|
||||
const existingPlugin = await this.PluginEntity.findOne({
|
||||
where: { id },
|
||||
});
|
||||
if (!existingPlugin) {
|
||||
throw new common_1.HttpException('该插件不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const deleteResult = await this.PluginEntity.delete(id);
|
||||
if (deleteResult.affected > 0) {
|
||||
return '删除插件成功';
|
||||
}
|
||||
else {
|
||||
throw new common_1.HttpException('删除插件失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
};
|
||||
PluginService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__param(0, (0, typeorm_1.InjectRepository)(plugin_entity_1.PluginEntity)),
|
||||
__metadata("design:paramtypes", [typeorm_2.Repository,
|
||||
models_service_1.ModelsService])
|
||||
], PluginService);
|
||||
exports.PluginService = PluginService;
|
||||
Reference in New Issue
Block a user