mirror of
https://github.com/vastxie/99AI.git
synced 2025-09-17 09:16:38 +08:00
104 lines
4.5 KiB
JavaScript
104 lines
4.5 KiB
JavaScript
"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 plugin_entity_1 = require("./plugin.entity");
|
|
let PluginService = class PluginService {
|
|
constructor(PluginEntity) {
|
|
this.PluginEntity = PluginEntity;
|
|
}
|
|
async pluginList(query) {
|
|
const { page = 1, size = 1000 } = query;
|
|
const rows = await this.PluginEntity.find({
|
|
order: { sortOrder: 'ASC', id: 'DESC' },
|
|
skip: (page - 1) * size,
|
|
take: size,
|
|
});
|
|
return { rows, count: rows.length };
|
|
}
|
|
async createPlugin(body) {
|
|
const { name, pluginImg, description, isEnabled, isSystemPlugin, 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,
|
|
isSystemPlugin: isSystemPlugin !== undefined ? isSystemPlugin : 0,
|
|
parameters,
|
|
sortOrder: sortOrder !== undefined ? sortOrder : 0,
|
|
});
|
|
return await this.PluginEntity.save(newPlugin);
|
|
}
|
|
async updatePlugin(body) {
|
|
const { id, name, pluginImg, description, isEnabled, isSystemPlugin, 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.isSystemPlugin =
|
|
isSystemPlugin !== undefined
|
|
? isSystemPlugin
|
|
: existingPlugin.isSystemPlugin;
|
|
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])
|
|
], PluginService);
|
|
exports.PluginService = PluginService;
|