mirror of
https://github.com/vastxie/99AI.git
synced 2026-04-11 21:04:26 +08:00
v4.1.0
This commit is contained in:
44
AIWebQuickDeploy/dist/modules/ai/aiPPT.js
vendored
Normal file
44
AIWebQuickDeploy/dist/modules/ai/aiPPT.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);
|
||||
};
|
||||
var AiPptService_1;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AiPptService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const chatLog_service_1 = require("../chatLog/chatLog.service");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const models_service_1 = require("../models/models.service");
|
||||
const upload_service_1 = require("../upload/upload.service");
|
||||
const openaiChat_service_1 = require("./openaiChat.service");
|
||||
let AiPptService = AiPptService_1 = class AiPptService {
|
||||
constructor(uploadService, globalConfigService, chatLogService, openAIChatService, modelsService) {
|
||||
this.uploadService = uploadService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
this.chatLogService = chatLogService;
|
||||
this.openAIChatService = openAIChatService;
|
||||
this.modelsService = modelsService;
|
||||
this.logger = new common_1.Logger(AiPptService_1.name);
|
||||
}
|
||||
async aiPPT(inputs) {
|
||||
return;
|
||||
}
|
||||
async pptCover(inputs) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
AiPptService = AiPptService_1 = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [upload_service_1.UploadService,
|
||||
globalConfig_service_1.GlobalConfigService,
|
||||
chatLog_service_1.ChatLogService,
|
||||
openaiChat_service_1.OpenAIChatService,
|
||||
models_service_1.ModelsService])
|
||||
], AiPptService);
|
||||
exports.AiPptService = AiPptService;
|
||||
214
AIWebQuickDeploy/dist/modules/ai/cogVideo.service.js
vendored
Normal file
214
AIWebQuickDeploy/dist/modules/ai/cogVideo.service.js
vendored
Normal file
@@ -0,0 +1,214 @@
|
||||
"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.CogVideoService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const axios_1 = require("axios");
|
||||
const chatLog_service_1 = require("../chatLog/chatLog.service");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const upload_service_1 = require("../upload/upload.service");
|
||||
let CogVideoService = class CogVideoService {
|
||||
constructor(chatLogService, globalConfigService, uploadService) {
|
||||
this.chatLogService = chatLogService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
this.uploadService = uploadService;
|
||||
}
|
||||
async cogVideo(inputs) {
|
||||
var _a, _b, _c;
|
||||
const { apiKey, proxyUrl, fileInfo, prompt, timeout, assistantLogId } = inputs;
|
||||
let result = {
|
||||
text: '',
|
||||
fileInfo: '',
|
||||
taskId: '',
|
||||
taskData: '',
|
||||
status: 2,
|
||||
};
|
||||
let response = null;
|
||||
let url = '';
|
||||
let payloadJson = {};
|
||||
const headers = { Authorization: `Bearer ${apiKey}` };
|
||||
url = `${proxyUrl}/cogvideox/v4/videos/generations`;
|
||||
payloadJson = {
|
||||
model: 'cogvideox',
|
||||
prompt: prompt,
|
||||
};
|
||||
if (fileInfo) {
|
||||
payloadJson['image_url'] = fileInfo;
|
||||
}
|
||||
common_1.Logger.log(`正在准备发送请求到 ${url},payload: ${JSON.stringify(payloadJson)}, headers: ${JSON.stringify(headers)}`, 'CogService');
|
||||
try {
|
||||
response = await axios_1.default.post(url, payloadJson, { headers });
|
||||
common_1.Logger.debug(`任务提交结果,状态码: ${response.status}, 状态消息: ${response.statusText}, 数据: ${JSON.stringify(response.data)}`);
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`任务提交失败: ${error.message}`, 'CogService');
|
||||
throw new Error('任务提交失败');
|
||||
}
|
||||
if ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.id) {
|
||||
result.taskId = (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.id;
|
||||
common_1.Logger.log(`任务提交成功, 任务ID: ${(_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.id}`, 'CogService');
|
||||
}
|
||||
else {
|
||||
throw new Error('未能获取结果数据, 即将重试');
|
||||
}
|
||||
try {
|
||||
await this.pollCogVideoResult({
|
||||
proxyUrl,
|
||||
apiKey,
|
||||
taskId: response.data.id,
|
||||
timeout,
|
||||
prompt,
|
||||
onSuccess: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
videoUrl: data === null || data === void 0 ? void 0 : data.videoUrl,
|
||||
audioUrl: data === null || data === void 0 ? void 0 : data.audioUrl,
|
||||
fileInfo: data === null || data === void 0 ? void 0 : data.fileInfo,
|
||||
answer: (data === null || data === void 0 ? void 0 : data.answer) || prompt,
|
||||
progress: '100%',
|
||||
status: 3,
|
||||
taskId: data === null || data === void 0 ? void 0 : data.taskId,
|
||||
taskData: data === null || data === void 0 ? void 0 : data.taskData,
|
||||
});
|
||||
common_1.Logger.log('视频任务已完成', 'CogService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'CogService');
|
||||
}
|
||||
},
|
||||
onGenerating: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
videoUrl: data === null || data === void 0 ? void 0 : data.videoUrl,
|
||||
audioUrl: data === null || data === void 0 ? void 0 : data.audioUrl,
|
||||
fileInfo: data === null || data === void 0 ? void 0 : data.fileInfo,
|
||||
answer: (data === null || data === void 0 ? void 0 : data.answer) || '视频生成中...',
|
||||
progress: data === null || data === void 0 ? void 0 : data.progress,
|
||||
status: data.status,
|
||||
});
|
||||
common_1.Logger.log('视频生成中...', 'CogService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'CogService');
|
||||
}
|
||||
},
|
||||
onFailure: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
answer: '视频生成失败',
|
||||
status: data.status,
|
||||
});
|
||||
common_1.Logger.log('生成失败', 'Lum aService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'CogService');
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error('查询生成结果时发生错误:', error.message, 'CogService');
|
||||
throw new Error('查询生成结果时发生错误');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async pollCogVideoResult(inputs) {
|
||||
const { proxyUrl, apiKey, taskId, timeout, onSuccess, onFailure, onGenerating, prompt, action, } = inputs;
|
||||
let result = {
|
||||
videoUrl: '',
|
||||
audioUrl: '',
|
||||
fileInfo: '',
|
||||
drawId: '',
|
||||
taskData: '',
|
||||
status: 2,
|
||||
progress: 0,
|
||||
answer: '',
|
||||
};
|
||||
const headers = { Authorization: `Bearer ${apiKey}` };
|
||||
const url = `${proxyUrl}/cogvideox/v4/async-result/${taskId}`;
|
||||
const startTime = Date.now();
|
||||
const totalDuration = 300000;
|
||||
const POLL_INTERVAL = 5000;
|
||||
let retryCount = 0;
|
||||
try {
|
||||
while (Date.now() - startTime < timeout) {
|
||||
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
|
||||
try {
|
||||
const res = await axios_1.default.get(url, { headers });
|
||||
const interval = setInterval(() => {
|
||||
const elapsed = Date.now() - startTime;
|
||||
let percentage = Math.floor((elapsed / totalDuration) * 100);
|
||||
if (percentage >= 99)
|
||||
percentage = 99;
|
||||
result.answer = `视频生成中 (${percentage}%)`;
|
||||
}, 1000);
|
||||
const responses = res.data;
|
||||
common_1.Logger.debug(`轮询结果: ${JSON.stringify(responses)}`, 'CogService');
|
||||
if (responses.task_status === 'SUCCESS') {
|
||||
result.taskId = responses.request_id;
|
||||
result.taskData = JSON.stringify(responses);
|
||||
common_1.Logger.log('视频生成成功', 'CogService');
|
||||
result.fileInfo = responses.video_result[0].url;
|
||||
common_1.Logger.log(result.fileInfo, 'CogService');
|
||||
try {
|
||||
const localStorageStatus = await this.globalConfigService.getConfigs([
|
||||
'localStorageStatus',
|
||||
]);
|
||||
if (Number(localStorageStatus)) {
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const currentDate = `${year}${month}/${day}`;
|
||||
result.fileInfo = await this.uploadService.uploadFileFromUrl({
|
||||
url: responses.video_result[0].url,
|
||||
dir: `video/cog/${currentDate}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`上传文件失败: ${error.message}`, 'CogService');
|
||||
}
|
||||
result.answer = `提示词: "${prompt}"`;
|
||||
onSuccess(result);
|
||||
clearInterval(interval);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
onGenerating(result);
|
||||
}
|
||||
if (result.progress) {
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
retryCount++;
|
||||
common_1.Logger.error(`轮询失败,重试次数: ${retryCount}`, 'CogService');
|
||||
}
|
||||
}
|
||||
common_1.Logger.error('轮询超时,请稍后再试!', 'CogService');
|
||||
result.status = 4;
|
||||
onFailure(result);
|
||||
throw new Error('查询超时,请稍后再试!');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`轮询过程中发生错误: ${error}`, 'CogService');
|
||||
result.status = 5;
|
||||
onFailure(result);
|
||||
}
|
||||
}
|
||||
};
|
||||
CogVideoService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [chatLog_service_1.ChatLogService,
|
||||
globalConfig_service_1.GlobalConfigService,
|
||||
upload_service_1.UploadService])
|
||||
], CogVideoService);
|
||||
exports.CogVideoService = CogVideoService;
|
||||
148
AIWebQuickDeploy/dist/modules/ai/fluxDraw.service.js
vendored
Normal file
148
AIWebQuickDeploy/dist/modules/ai/fluxDraw.service.js
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
"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 FluxDrawService_1;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FluxDrawService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const axios_1 = require("axios");
|
||||
const chatLog_service_1 = require("../chatLog/chatLog.service");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const upload_service_1 = require("../upload/upload.service");
|
||||
const openaiChat_service_1 = require("./openaiChat.service");
|
||||
let FluxDrawService = FluxDrawService_1 = class FluxDrawService {
|
||||
constructor(uploadService, globalConfigService, chatLogService, openAIChatService) {
|
||||
this.uploadService = uploadService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
this.chatLogService = chatLogService;
|
||||
this.openAIChatService = openAIChatService;
|
||||
this.logger = new common_1.Logger(FluxDrawService_1.name);
|
||||
}
|
||||
async fluxDraw(inputs, buildMessageFromParentMessageId) {
|
||||
var _a, _b, _c, _d;
|
||||
common_1.Logger.log('开始提交 Flux 绘图任务 ', 'DrawService');
|
||||
const { apiKey, model, proxyUrl, prompt, extraParam, timeout, onSuccess, onFailure, groupId, } = inputs;
|
||||
const isDalleChat = await this.globalConfigService.getConfigs([
|
||||
'isDalleChat',
|
||||
]);
|
||||
let drawPrompt;
|
||||
if (isDalleChat === '1') {
|
||||
try {
|
||||
common_1.Logger.log('已开启连续绘画模式', 'FluxDraw');
|
||||
const { messagesHistory } = await buildMessageFromParentMessageId(`参考上文,结合我的需求,给出绘画描述。我的需求是:${prompt}`, {
|
||||
groupId,
|
||||
systemMessage: '你是一个绘画提示词生成工具,请根据用户的要求,结合上下文,用一段文字,描述用户需要的绘画需求,不用包含任何礼貌性的寒暄,只需要场景的描述,可以适当联想',
|
||||
maxModelTokens: 8000,
|
||||
maxRounds: 5,
|
||||
fileInfo: '',
|
||||
}, this.chatLogService);
|
||||
drawPrompt = await this.openAIChatService.chatFree(prompt, undefined, messagesHistory);
|
||||
}
|
||||
catch (error) {
|
||||
console.error('调用chatFree失败:', error);
|
||||
drawPrompt = prompt;
|
||||
}
|
||||
}
|
||||
else {
|
||||
drawPrompt = prompt;
|
||||
}
|
||||
const size = (extraParam === null || extraParam === void 0 ? void 0 : extraParam.size) || '1024x1024';
|
||||
let result = { answer: '', fileInfo: '', status: 2 };
|
||||
try {
|
||||
const options = {
|
||||
method: 'POST',
|
||||
url: `${proxyUrl}/v1/images/generations`,
|
||||
timeout: timeout,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
},
|
||||
data: {
|
||||
model: model,
|
||||
prompt: drawPrompt,
|
||||
size,
|
||||
},
|
||||
};
|
||||
common_1.Logger.log(`正在准备发送请求到 ${options.url},payload: ${JSON.stringify(options.data)}, headers: ${JSON.stringify(options.headers)}`, 'FluxDrawService');
|
||||
const response = await (0, axios_1.default)(options);
|
||||
common_1.Logger.debug(`请求成功${JSON.stringify(response.data.data[0])}`);
|
||||
common_1.Logger.debug(`请求状态${JSON.stringify(response.status)}`);
|
||||
const url = response.data.data[0].url;
|
||||
try {
|
||||
common_1.Logger.log(`------> 开始上传图片!!!`, 'DrawService');
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const currentDate = `${year}${month}/${day}`;
|
||||
result.fileInfo = await this.uploadService.uploadFileFromUrl({
|
||||
url: url,
|
||||
dir: `images/dalle/${currentDate}`,
|
||||
});
|
||||
common_1.Logger.log(`图片上传成功,URL: ${result.fileInfo}`, 'DrawService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`上传图片过程中出现错误: ${error}`, 'DrawService');
|
||||
}
|
||||
let revised_prompt_cn;
|
||||
try {
|
||||
revised_prompt_cn = await this.openAIChatService.chatFree(`根据提示词{${drawPrompt}}, 模拟AI绘画机器人的语气,用中文回复,告诉用户已经画好了`);
|
||||
}
|
||||
catch (error) {
|
||||
revised_prompt_cn = `${prompt} 绘制成功`;
|
||||
common_1.Logger.error('翻译失败: ', error);
|
||||
}
|
||||
result.answer = revised_prompt_cn;
|
||||
result.status = 3;
|
||||
onSuccess(result);
|
||||
return;
|
||||
}
|
||||
catch (error) {
|
||||
result.status = 5;
|
||||
onFailure(result);
|
||||
const status = ((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status) || 500;
|
||||
console.log('draw error: ', JSON.stringify(error), status);
|
||||
const message = (_d = (_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.message;
|
||||
if (status === 429) {
|
||||
result.text = '当前请求已过载、请稍等会儿再试试吧!';
|
||||
return result;
|
||||
}
|
||||
if (status === 400 &&
|
||||
message.includes('This request has been blocked by our content filters')) {
|
||||
result.text = '您的请求已被系统拒绝。您的提示可能存在一些非法的文本。';
|
||||
return result;
|
||||
}
|
||||
if (status === 400 &&
|
||||
message.includes('Billing hard limit has been reached')) {
|
||||
result.text =
|
||||
'当前模型key已被封禁、已冻结当前调用Key、尝试重新对话试试吧!';
|
||||
return result;
|
||||
}
|
||||
if (status === 500) {
|
||||
result.text = '绘制图片失败,请检查你的提示词是否有非法描述!';
|
||||
return result;
|
||||
}
|
||||
if (status === 401) {
|
||||
result.text = '绘制图片失败,此次绘画被拒绝了!';
|
||||
return result;
|
||||
}
|
||||
result.text = '绘制图片失败,请稍后试试吧!';
|
||||
return result;
|
||||
}
|
||||
}
|
||||
};
|
||||
FluxDrawService = FluxDrawService_1 = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [upload_service_1.UploadService,
|
||||
globalConfig_service_1.GlobalConfigService,
|
||||
chatLog_service_1.ChatLogService,
|
||||
openaiChat_service_1.OpenAIChatService])
|
||||
], FluxDrawService);
|
||||
exports.FluxDrawService = FluxDrawService;
|
||||
213
AIWebQuickDeploy/dist/modules/ai/lumaVideo.service.js
vendored
Normal file
213
AIWebQuickDeploy/dist/modules/ai/lumaVideo.service.js
vendored
Normal file
@@ -0,0 +1,213 @@
|
||||
"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.LumaVideoService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const axios_1 = require("axios");
|
||||
const chatLog_service_1 = require("../chatLog/chatLog.service");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const upload_service_1 = require("../upload/upload.service");
|
||||
let LumaVideoService = class LumaVideoService {
|
||||
constructor(chatLogService, globalConfigService, uploadService) {
|
||||
this.chatLogService = chatLogService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
this.uploadService = uploadService;
|
||||
}
|
||||
async lumaVideo(inputs) {
|
||||
var _a, _b, _c;
|
||||
const { apiKey, proxyUrl, fileInfo, prompt, timeout, assistantLogId, extraParam, } = inputs;
|
||||
let result = {
|
||||
text: '',
|
||||
fileInfo: '',
|
||||
taskId: '',
|
||||
taskData: '',
|
||||
status: 2,
|
||||
};
|
||||
let response = null;
|
||||
let url = '';
|
||||
let payloadJson = {};
|
||||
const headers = { Authorization: `Bearer ${apiKey}` };
|
||||
url = `${proxyUrl}/luma/generations/`;
|
||||
const aspectRatio = extraParam.size || '16:9';
|
||||
payloadJson = {
|
||||
user_prompt: prompt,
|
||||
aspect_ratio: aspectRatio,
|
||||
expand_prompt: true,
|
||||
};
|
||||
if (fileInfo) {
|
||||
payloadJson['image_url'] = fileInfo;
|
||||
}
|
||||
common_1.Logger.log(`正在准备发送请求到 ${url},payload: ${JSON.stringify(payloadJson)}, headers: ${JSON.stringify(headers)}`, 'LumaService');
|
||||
try {
|
||||
response = await axios_1.default.post(url, payloadJson, { headers });
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`任务提交失败: ${error.message}`, 'LumaService');
|
||||
throw new Error('任务提交失败');
|
||||
}
|
||||
if ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.id) {
|
||||
result.taskId = (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.id;
|
||||
common_1.Logger.log(`任务提交成功, 任务ID: ${(_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.id}`, 'LumaService');
|
||||
}
|
||||
else {
|
||||
throw new Error('未能获取结果数据, 即将重试');
|
||||
}
|
||||
try {
|
||||
await this.pollLumaVideoResult({
|
||||
proxyUrl,
|
||||
apiKey,
|
||||
taskId: response.data.id,
|
||||
timeout,
|
||||
prompt,
|
||||
onSuccess: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
videoUrl: data === null || data === void 0 ? void 0 : data.videoUrl,
|
||||
audioUrl: data === null || data === void 0 ? void 0 : data.audioUrl,
|
||||
fileInfo: data === null || data === void 0 ? void 0 : data.fileInfo,
|
||||
answer: (data === null || data === void 0 ? void 0 : data.answer) || prompt,
|
||||
progress: '100%',
|
||||
status: 3,
|
||||
taskId: data === null || data === void 0 ? void 0 : data.taskId,
|
||||
taskData: data === null || data === void 0 ? void 0 : data.taskData,
|
||||
});
|
||||
common_1.Logger.log('视频任务已完成', 'LumaService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'LumaService');
|
||||
}
|
||||
},
|
||||
onGenerating: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
videoUrl: data === null || data === void 0 ? void 0 : data.videoUrl,
|
||||
audioUrl: data === null || data === void 0 ? void 0 : data.audioUrl,
|
||||
fileInfo: data === null || data === void 0 ? void 0 : data.fileInfo,
|
||||
answer: (data === null || data === void 0 ? void 0 : data.answer) || '视频生成中...',
|
||||
progress: data === null || data === void 0 ? void 0 : data.progress,
|
||||
status: data.status,
|
||||
});
|
||||
common_1.Logger.log('视频生成中...', 'LumaService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'LumaService');
|
||||
}
|
||||
},
|
||||
onFailure: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
answer: '视频生成失败',
|
||||
status: data.status,
|
||||
});
|
||||
common_1.Logger.log('生成失败', 'Lum aService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'LumaService');
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error('查询生成结果时发生错误:', error.message, 'LumaService');
|
||||
throw new Error('查询生成结果时发生错误');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async pollLumaVideoResult(inputs) {
|
||||
const { proxyUrl, apiKey, taskId, timeout, onSuccess, onFailure, onGenerating, action, } = inputs;
|
||||
let result = {
|
||||
videoUrl: '',
|
||||
audioUrl: '',
|
||||
fileInfo: '',
|
||||
drawId: '',
|
||||
taskData: '',
|
||||
status: 2,
|
||||
progress: 0,
|
||||
answer: '',
|
||||
};
|
||||
const headers = { Authorization: `Bearer ${apiKey}` };
|
||||
const url = `${proxyUrl}/luma/generations/${taskId}`;
|
||||
const startTime = Date.now();
|
||||
const totalDuration = 300000;
|
||||
const POLL_INTERVAL = 5000;
|
||||
let retryCount = 0;
|
||||
try {
|
||||
while (Date.now() - startTime < timeout) {
|
||||
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
|
||||
try {
|
||||
const res = await axios_1.default.get(url, { headers });
|
||||
const interval = setInterval(() => {
|
||||
const elapsed = Date.now() - startTime;
|
||||
let percentage = Math.floor((elapsed / totalDuration) * 100);
|
||||
if (percentage >= 99)
|
||||
percentage = 99;
|
||||
result.answer = `视频生成中 (${percentage}%)`;
|
||||
}, 1000);
|
||||
const responses = res.data;
|
||||
common_1.Logger.debug(`轮询结果: ${JSON.stringify(responses)}`, 'LumaService');
|
||||
if (responses.state === 'completed') {
|
||||
result.taskId = responses.id;
|
||||
result.taskData = JSON.stringify(responses);
|
||||
result.fileInfo = responses.video.url;
|
||||
try {
|
||||
const localStorageStatus = await this.globalConfigService.getConfigs([
|
||||
'localStorageStatus',
|
||||
]);
|
||||
if (Number(localStorageStatus)) {
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const currentDate = `${year}${month}/${day}`;
|
||||
result.fileInfo = await this.uploadService.uploadFileFromUrl({
|
||||
url: responses.video.download_url,
|
||||
dir: `video/luma/${currentDate}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`上传文件失败: ${error.message}`, 'LumaService');
|
||||
}
|
||||
result.answer = `提示词: "${responses.prompt}"`;
|
||||
onSuccess(result);
|
||||
clearInterval(interval);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
onGenerating(result);
|
||||
}
|
||||
if (result.progress) {
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
retryCount++;
|
||||
common_1.Logger.error(`轮询失败,重试次数: ${retryCount}`, 'LumaService');
|
||||
}
|
||||
}
|
||||
common_1.Logger.error('轮询超时,请稍后再试!', 'LumaService');
|
||||
result.status = 4;
|
||||
onFailure(result);
|
||||
throw new Error('查询超时,请稍后再试!');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`轮询过程中发生错误: ${error}`, 'LumaService');
|
||||
result.status = 5;
|
||||
onFailure(result);
|
||||
}
|
||||
}
|
||||
};
|
||||
LumaVideoService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [chatLog_service_1.ChatLogService,
|
||||
globalConfig_service_1.GlobalConfigService,
|
||||
upload_service_1.UploadService])
|
||||
], LumaVideoService);
|
||||
exports.LumaVideoService = LumaVideoService;
|
||||
237
AIWebQuickDeploy/dist/modules/ai/midjourneyDraw.service.js
vendored
Normal file
237
AIWebQuickDeploy/dist/modules/ai/midjourneyDraw.service.js
vendored
Normal file
@@ -0,0 +1,237 @@
|
||||
"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.MidjourneyService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const axios_1 = require("axios");
|
||||
const chatLog_service_1 = require("../chatLog/chatLog.service");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const upload_service_1 = require("../upload/upload.service");
|
||||
let MidjourneyService = class MidjourneyService {
|
||||
constructor(uploadService, globalConfigService, chatLogService) {
|
||||
this.uploadService = uploadService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
this.chatLogService = chatLogService;
|
||||
}
|
||||
async midjourneyDraw(inputs) {
|
||||
var _a, _b, _c, _d;
|
||||
const { id, apiKey, proxyUrl, action, drawId, prompt, usePrompt, customId, timeout, fileInfo, assistantLogId, } = inputs;
|
||||
let result = {
|
||||
text: '',
|
||||
fileInfo: '',
|
||||
drawId: '',
|
||||
customId: '',
|
||||
status: 2,
|
||||
};
|
||||
let response;
|
||||
let retryCount = 0;
|
||||
let url = '';
|
||||
const headers = { 'mj-api-secret': apiKey };
|
||||
common_1.Logger.debug(`当前任务类型: ${action}`, 'MidjourneyService');
|
||||
while (retryCount < 3) {
|
||||
let payloadJson = {};
|
||||
try {
|
||||
if (action === 'IMAGINE') {
|
||||
url = `${proxyUrl}/mj/submit/imagine`;
|
||||
payloadJson = { prompt: usePrompt };
|
||||
}
|
||||
else if (action === 'DESCRIBE') {
|
||||
url = `${proxyUrl}/mj/submit/describe`;
|
||||
if (fileInfo) {
|
||||
const response = await fetch(fileInfo);
|
||||
const blob = await response.blob();
|
||||
const buffer = Buffer.from(await blob.arrayBuffer());
|
||||
const base64String = buffer.toString('base64');
|
||||
payloadJson = { base64: `data:image/png;base64,${base64String}` };
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (action === 'PICREADER') {
|
||||
url = `${proxyUrl}/mj/submit/action`;
|
||||
payloadJson = { taskId: drawId, customId: customId };
|
||||
response = await axios_1.default.post(url, payloadJson, { headers });
|
||||
if ((response === null || response === void 0 ? void 0 : response.status) === 200 && ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.result)) {
|
||||
url = `${proxyUrl}/mj/submit/modal`;
|
||||
payloadJson = { taskId: (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.result };
|
||||
}
|
||||
}
|
||||
else {
|
||||
url = `${proxyUrl}/mj/submit/action`;
|
||||
payloadJson = { taskId: drawId, customId: customId };
|
||||
}
|
||||
common_1.Logger.log(`正在准备发送请求到 ${url},payload: ${JSON.stringify(payloadJson)}, headers: ${JSON.stringify(headers)}`, 'MidjourneyService');
|
||||
response = await axios_1.default.post(url, payloadJson, { headers });
|
||||
if ((response === null || response === void 0 ? void 0 : response.status) === 200 && ((_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.result)) {
|
||||
common_1.Logger.debug(`收到响应: ${JSON.stringify(response.data)}`, 'MidjourneyService');
|
||||
result.drawId = (_d = response === null || response === void 0 ? void 0 : response.data) === null || _d === void 0 ? void 0 : _d.result;
|
||||
result.state = 2;
|
||||
result.answer = '绘画任务提交成功';
|
||||
common_1.Logger.log(`绘画任务提交成功, 绘画ID: ${response.data.result}`, 'MidjourneyService');
|
||||
break;
|
||||
}
|
||||
else {
|
||||
throw new Error('未能获取结果数据, 即将重试');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
retryCount++;
|
||||
if (retryCount >= 3) {
|
||||
result.answer = '任务提交失败,请检查提示词后重试';
|
||||
result.status = 5;
|
||||
common_1.Logger.log(`绘画任务提交失败, 请检查后台配置或者稍后重试! ${error}`, 'MidjourneyService');
|
||||
}
|
||||
}
|
||||
}
|
||||
this.pollMjDrawingResult({
|
||||
proxyUrl,
|
||||
apiKey,
|
||||
drawId: result.drawId,
|
||||
timeout,
|
||||
prompt,
|
||||
onSuccess: async (data) => {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
fileInfo: data === null || data === void 0 ? void 0 : data.fileInfo,
|
||||
answer: (data === null || data === void 0 ? void 0 : data.answer) || prompt,
|
||||
progress: '100%',
|
||||
status: 3,
|
||||
drawId: data === null || data === void 0 ? void 0 : data.drawId,
|
||||
customId: data === null || data === void 0 ? void 0 : data.customId,
|
||||
});
|
||||
common_1.Logger.log('绘图成功!', 'MidjourneyService');
|
||||
},
|
||||
onDrawing: async (data) => {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
answer: (data === null || data === void 0 ? void 0 : data.answer) || '绘制中',
|
||||
progress: data === null || data === void 0 ? void 0 : data.progress,
|
||||
status: 2,
|
||||
});
|
||||
common_1.Logger.log(`绘制中!绘制进度${data === null || data === void 0 ? void 0 : data.progress}`, 'MidjourneyService');
|
||||
},
|
||||
onFailure: async (data) => {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
answer: '绘图失败',
|
||||
status: data.status,
|
||||
});
|
||||
common_1.Logger.log('绘图失败', 'MidjourneyService');
|
||||
},
|
||||
}).catch((error) => {
|
||||
common_1.Logger.error('查询绘图结果时发生错误:', error, 'MidjourneyService');
|
||||
});
|
||||
return result;
|
||||
}
|
||||
async pollMjDrawingResult(inputs) {
|
||||
const { proxyUrl, apiKey, drawId, timeout, onSuccess, prompt, onFailure, onDrawing, } = inputs;
|
||||
const { mjNotSaveImg, mjProxyImgUrl, mjNotUseProxy } = await this.globalConfigService.getConfigs([
|
||||
'mjNotSaveImg',
|
||||
'mjProxyImgUrl',
|
||||
'mjNotUseProxy',
|
||||
]);
|
||||
let result = {
|
||||
fileInfo: '',
|
||||
drawId: '',
|
||||
customId: '',
|
||||
status: 2,
|
||||
progress: 0,
|
||||
answer: '',
|
||||
};
|
||||
const startTime = Date.now();
|
||||
const POLL_INTERVAL = 5000;
|
||||
let retryCount = 0;
|
||||
try {
|
||||
while (Date.now() - startTime < timeout) {
|
||||
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
|
||||
try {
|
||||
const headers = {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'mj-api-secret': apiKey,
|
||||
};
|
||||
const url = `${proxyUrl}/mj/task/${drawId}/fetch`;
|
||||
const res = await axios_1.default.get(url, { headers });
|
||||
const responses = res.data;
|
||||
common_1.Logger.debug(`查询结果: ${JSON.stringify(responses)}`, 'MidjourneyService');
|
||||
if (responses.status === 'SUCCESS') {
|
||||
common_1.Logger.log(`绘制成功, 获取到的URL: ${responses.imageUrl}`, 'MidjourneyService');
|
||||
let processedUrl = responses.imageUrl;
|
||||
const shouldReplaceUrl = mjNotUseProxy === '0' && mjProxyImgUrl;
|
||||
let logMessage = '';
|
||||
if (shouldReplaceUrl) {
|
||||
const newUrlBase = new URL(mjProxyImgUrl);
|
||||
const parsedUrl = new URL(responses.imageUrl);
|
||||
parsedUrl.protocol = newUrlBase.protocol;
|
||||
parsedUrl.hostname = newUrlBase.hostname;
|
||||
parsedUrl.port = newUrlBase.port ? newUrlBase.port : '';
|
||||
processedUrl = parsedUrl.toString();
|
||||
logMessage = `使用代理替换后的 URL: ${processedUrl}`;
|
||||
common_1.Logger.log(logMessage, 'MidjourneyService');
|
||||
}
|
||||
if (mjNotSaveImg !== '1') {
|
||||
try {
|
||||
common_1.Logger.log(`------> 开始上传图片!!!`, 'MidjourneyService');
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const currentDate = `${year}${month}/${day}`;
|
||||
processedUrl = await this.uploadService.uploadFileFromUrl({
|
||||
url: processedUrl,
|
||||
dir: `images/midjourney/${currentDate}`,
|
||||
});
|
||||
logMessage = `上传成功 URL: ${processedUrl}`;
|
||||
}
|
||||
catch (uploadError) {
|
||||
common_1.Logger.error('存储图片失败,使用原始/代理图片链接');
|
||||
logMessage = `存储图片失败,使用原始/代理图片链接 ${processedUrl}`;
|
||||
}
|
||||
common_1.Logger.log(logMessage, 'MidjourneyService');
|
||||
}
|
||||
else {
|
||||
logMessage = `不保存图片,使用 URL: ${processedUrl}`;
|
||||
common_1.Logger.log(logMessage, 'MidjourneyService');
|
||||
}
|
||||
result.fileInfo = processedUrl;
|
||||
result.drawId = responses.id;
|
||||
result.customId = JSON.stringify(responses.buttons);
|
||||
result.answer = `${prompt}\n${responses.finalPrompt || responses.properties.finalPrompt || ''}`;
|
||||
onSuccess(result);
|
||||
return;
|
||||
}
|
||||
result.progress = responses === null || responses === void 0 ? void 0 : responses.progress;
|
||||
result.answer = `当前绘制进度 ${responses === null || responses === void 0 ? void 0 : responses.progress}`;
|
||||
if (result.progress) {
|
||||
onDrawing(result);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
retryCount++;
|
||||
common_1.Logger.error(`轮询过程中发生错误: ${error}`, 'MidjourneyService');
|
||||
}
|
||||
}
|
||||
common_1.Logger.error(`超过 ${startTime / 1000} s 未完成绘画, 请稍后再试! MidjourneyService`);
|
||||
result.status = 4;
|
||||
onFailure(result);
|
||||
throw new common_1.HttpException('绘画超时,请稍后再试!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`绘画失败: ${error} MidjourneyService`);
|
||||
result.status = 5;
|
||||
onFailure(result);
|
||||
}
|
||||
}
|
||||
};
|
||||
MidjourneyService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [upload_service_1.UploadService,
|
||||
globalConfig_service_1.GlobalConfigService,
|
||||
chatLog_service_1.ChatLogService])
|
||||
], MidjourneyService);
|
||||
exports.MidjourneyService = MidjourneyService;
|
||||
128
AIWebQuickDeploy/dist/modules/ai/netSearch.service.js
vendored
Normal file
128
AIWebQuickDeploy/dist/modules/ai/netSearch.service.js
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
"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.netSearchService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
let netSearchService = class netSearchService {
|
||||
constructor(globalConfigService) {
|
||||
this.globalConfigService = globalConfigService;
|
||||
}
|
||||
async webSearchPro(prompt) {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
try {
|
||||
const { pluginUrl, pluginKey } = await this.globalConfigService.getConfigs(['pluginUrl', 'pluginKey']);
|
||||
if (!pluginUrl || !pluginKey) {
|
||||
common_1.Logger.warn('搜索插件配置缺失');
|
||||
return { searchResults: [] };
|
||||
}
|
||||
const keys = pluginKey.split(',').filter((key) => key.trim());
|
||||
const selectedKey = keys[Math.floor(Math.random() * keys.length)];
|
||||
const isBochaiApi = pluginUrl.includes('bochaai.com');
|
||||
const isBigModelApi = pluginUrl.includes('bigmodel.cn');
|
||||
const isTavilyApi = pluginUrl.includes('tavily.com');
|
||||
common_1.Logger.log(`[搜索] API类型: ${isBochaiApi
|
||||
? 'Bochai'
|
||||
: isBigModelApi
|
||||
? 'BigModel'
|
||||
: isTavilyApi
|
||||
? 'Tavily'
|
||||
: '未知'}`);
|
||||
common_1.Logger.log(`[搜索] 请求URL: ${pluginUrl}`);
|
||||
common_1.Logger.log(`[搜索] 搜索关键词: ${prompt}`);
|
||||
const requestBody = isBochaiApi
|
||||
? {
|
||||
query: prompt,
|
||||
freshness: 'oneWeek',
|
||||
summary: true,
|
||||
}
|
||||
: isTavilyApi
|
||||
? {
|
||||
query: prompt,
|
||||
search_depth: 'basic',
|
||||
include_answer: false,
|
||||
include_raw_content: false,
|
||||
include_images: false,
|
||||
}
|
||||
: {
|
||||
tool: 'web-search-pro',
|
||||
stream: false,
|
||||
messages: [{ role: 'user', content: prompt }],
|
||||
};
|
||||
common_1.Logger.log(`[搜索] 请求参数: ${JSON.stringify(requestBody, null, 2)}`);
|
||||
const response = await fetch(pluginUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: selectedKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(requestBody),
|
||||
});
|
||||
if (!response.ok) {
|
||||
common_1.Logger.error(`[搜索] 接口返回错误: ${response.status}`);
|
||||
return { searchResults: [] };
|
||||
}
|
||||
const apiResult = await response.json();
|
||||
common_1.Logger.log(`[搜索] 原始返回数据: ${JSON.stringify(apiResult, null, 2)}`);
|
||||
let searchResults = [];
|
||||
if (isBochaiApi) {
|
||||
if ((apiResult === null || apiResult === void 0 ? void 0 : apiResult.code) === 200 && ((_b = (_a = apiResult === null || apiResult === void 0 ? void 0 : apiResult.data) === null || _a === void 0 ? void 0 : _a.webPages) === null || _b === void 0 ? void 0 : _b.value)) {
|
||||
searchResults = apiResult.data.webPages.value.map((item) => ({
|
||||
title: (item === null || item === void 0 ? void 0 : item.name) || '',
|
||||
link: (item === null || item === void 0 ? void 0 : item.url) || '',
|
||||
content: (item === null || item === void 0 ? void 0 : item.summary) || '',
|
||||
icon: (item === null || item === void 0 ? void 0 : item.siteIcon) || '',
|
||||
media: (item === null || item === void 0 ? void 0 : item.siteName) || '',
|
||||
}));
|
||||
}
|
||||
}
|
||||
else if (isBigModelApi) {
|
||||
if (((_f = (_e = (_d = (_c = apiResult === null || apiResult === void 0 ? void 0 : apiResult.choices) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.message) === null || _e === void 0 ? void 0 : _e.tool_calls) === null || _f === void 0 ? void 0 : _f.length) > 0) {
|
||||
for (const toolCall of apiResult.choices[0].message.tool_calls) {
|
||||
if (Array.isArray(toolCall.search_result)) {
|
||||
searchResults = toolCall.search_result.map((item) => ({
|
||||
title: (item === null || item === void 0 ? void 0 : item.title) || '',
|
||||
link: (item === null || item === void 0 ? void 0 : item.link) || '',
|
||||
content: (item === null || item === void 0 ? void 0 : item.content) || '',
|
||||
icon: (item === null || item === void 0 ? void 0 : item.icon) || '',
|
||||
media: (item === null || item === void 0 ? void 0 : item.media) || '',
|
||||
}));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (isTavilyApi) {
|
||||
if (Array.isArray(apiResult === null || apiResult === void 0 ? void 0 : apiResult.results)) {
|
||||
searchResults = apiResult.results.map((item) => ({
|
||||
title: (item === null || item === void 0 ? void 0 : item.title) || '',
|
||||
link: (item === null || item === void 0 ? void 0 : item.url) || '',
|
||||
content: (item === null || item === void 0 ? void 0 : item.content) || '',
|
||||
icon: '',
|
||||
media: '',
|
||||
}));
|
||||
}
|
||||
}
|
||||
const formattedResult = searchResults.map((item, index) => (Object.assign({ resultIndex: index + 1 }, item)));
|
||||
common_1.Logger.log(`[搜索] 格式化后的结果: ${JSON.stringify(formattedResult, null, 2)}`);
|
||||
return { searchResults: formattedResult };
|
||||
}
|
||||
catch (fetchError) {
|
||||
common_1.Logger.error('[搜索] 调用接口出错:', fetchError);
|
||||
return { searchResults: [] };
|
||||
}
|
||||
}
|
||||
};
|
||||
netSearchService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [globalConfig_service_1.GlobalConfigService])
|
||||
], netSearchService);
|
||||
exports.netSearchService = netSearchService;
|
||||
180
AIWebQuickDeploy/dist/modules/ai/openaiChat.service.js
vendored
Normal file
180
AIWebQuickDeploy/dist/modules/ai/openaiChat.service.js
vendored
Normal file
@@ -0,0 +1,180 @@
|
||||
"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.OpenAIChatService = void 0;
|
||||
const utils_1 = require("../../common/utils");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const axios_1 = require("axios");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
let OpenAIChatService = class OpenAIChatService {
|
||||
constructor(globalConfigService) {
|
||||
this.globalConfigService = globalConfigService;
|
||||
}
|
||||
async openAIChat(messagesHistory, inputs) {
|
||||
const { onFailure, onProgress, apiKey, model, proxyUrl, modelName, timeout, chatId, isFileUpload, modelAvatar, temperature, abortController, } = inputs;
|
||||
let result = {
|
||||
text: '',
|
||||
model: '',
|
||||
modelName: modelName,
|
||||
chatId: chatId,
|
||||
answer: '',
|
||||
errMsg: '',
|
||||
modelAvatar: modelAvatar,
|
||||
};
|
||||
const data = Object.assign({ model, messages: messagesHistory }, (isFileUpload === 2 && { max_tokens: 2048 }));
|
||||
data.stream = true;
|
||||
data.temperature = temperature;
|
||||
const options = {
|
||||
method: 'POST',
|
||||
url: `${proxyUrl}/v1/chat/completions`,
|
||||
responseType: 'stream',
|
||||
timeout: timeout,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
},
|
||||
data: data,
|
||||
};
|
||||
const sanitizedOptions = await this.sanitizeOptionsForLogging(options);
|
||||
console.log('请求配置:', JSON.stringify(sanitizedOptions, null, 2), 'ChatService');
|
||||
console.log('请求配置:', JSON.stringify(sanitizedOptions, null, 2), 'ChatService');
|
||||
try {
|
||||
const response = await (0, axios_1.default)(options);
|
||||
const stream = response.data;
|
||||
let buffer = '';
|
||||
await new Promise((resolve, reject) => {
|
||||
stream.on('data', (chunk) => {
|
||||
buffer += chunk.toString();
|
||||
let lines = buffer.split('\n');
|
||||
buffer = lines.pop();
|
||||
lines.forEach((line) => {
|
||||
var _a, _b;
|
||||
if (line.trim() === 'data: [DONE]') {
|
||||
console.log('处理结束信号 [DONE]');
|
||||
resolve(result);
|
||||
return;
|
||||
}
|
||||
if (line.startsWith('data: ')) {
|
||||
try {
|
||||
const cleanedLine = line.slice(6).trim();
|
||||
if (cleanedLine) {
|
||||
const jsonLine = JSON.parse(cleanedLine);
|
||||
const content = ((_b = (_a = jsonLine.choices[0]) === null || _a === void 0 ? void 0 : _a.delta) === null || _b === void 0 ? void 0 : _b.content) || '';
|
||||
result.answer += content;
|
||||
onProgress === null || onProgress === void 0 ? void 0 : onProgress({ text: content, answer: result.answer });
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Error parsing line:', line, error);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
stream.on('end', () => {
|
||||
resolve(result);
|
||||
});
|
||||
stream.on('error', (error) => {
|
||||
reject(error);
|
||||
});
|
||||
abortController.signal.addEventListener('abort', () => {
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
return result;
|
||||
}
|
||||
catch (error) {
|
||||
result.errMsg = (0, utils_1.handleError)(error);
|
||||
common_1.Logger.error(result.errMsg);
|
||||
onFailure(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
async sanitizeOptionsForLogging(options) {
|
||||
const sanitizedOptions = JSON.parse(JSON.stringify(options));
|
||||
if (sanitizedOptions.headers && sanitizedOptions.headers.Authorization) {
|
||||
const authHeader = sanitizedOptions.headers.Authorization;
|
||||
if (authHeader.startsWith('Bearer ')) {
|
||||
const token = authHeader.slice(7);
|
||||
if (token.length > 10) {
|
||||
sanitizedOptions.headers.Authorization = `Bearer ${token.slice(0, 5)}****${token.slice(-4)}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sanitizedOptions.data &&
|
||||
sanitizedOptions.data.messages &&
|
||||
Array.isArray(sanitizedOptions.data.messages)) {
|
||||
sanitizedOptions.data.messages = sanitizedOptions.data.messages.map((message) => {
|
||||
if (message.content && Array.isArray(message.content)) {
|
||||
message.content = message.content.map((content) => {
|
||||
if (content.type === 'image_url' &&
|
||||
content.image_url &&
|
||||
content.image_url.url) {
|
||||
content.image_url.url = 'data:image/***;base64 ... ...';
|
||||
}
|
||||
return content;
|
||||
});
|
||||
}
|
||||
return message;
|
||||
});
|
||||
}
|
||||
return sanitizedOptions;
|
||||
}
|
||||
async chatFree(prompt, systemMessage, messagesHistory) {
|
||||
const { openaiBaseUrl = '', openaiBaseKey = '', openaiBaseModel, } = await this.globalConfigService.getConfigs([
|
||||
'openaiBaseKey',
|
||||
'openaiBaseUrl',
|
||||
'openaiBaseModel',
|
||||
]);
|
||||
const key = openaiBaseKey;
|
||||
const proxyUrl = openaiBaseUrl;
|
||||
let requestData = [];
|
||||
if (systemMessage) {
|
||||
requestData.push({
|
||||
role: 'system',
|
||||
content: systemMessage,
|
||||
});
|
||||
}
|
||||
if (messagesHistory && messagesHistory.length > 0) {
|
||||
requestData = requestData.concat(messagesHistory);
|
||||
}
|
||||
else {
|
||||
requestData.push({
|
||||
role: 'user',
|
||||
content: prompt,
|
||||
});
|
||||
}
|
||||
const options = {
|
||||
method: 'POST',
|
||||
url: `${proxyUrl}/v1/chat/completions`,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${key}`,
|
||||
},
|
||||
data: {
|
||||
model: openaiBaseModel || 'gpt-3.5-turbo-0125',
|
||||
messages: requestData,
|
||||
},
|
||||
};
|
||||
try {
|
||||
const response = await (0, axios_1.default)(options);
|
||||
common_1.Logger.log(`全局模型调用成功, 返回结果: ${response === null || response === void 0 ? void 0 : response.data.choices[0].message.content}`, 'ChatService');
|
||||
return response === null || response === void 0 ? void 0 : response.data.choices[0].message.content;
|
||||
}
|
||||
catch (error) {
|
||||
console.log('error: ', error);
|
||||
}
|
||||
}
|
||||
};
|
||||
OpenAIChatService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [globalConfig_service_1.GlobalConfigService])
|
||||
], OpenAIChatService);
|
||||
exports.OpenAIChatService = OpenAIChatService;
|
||||
145
AIWebQuickDeploy/dist/modules/ai/openaiDraw.service.js
vendored
Normal file
145
AIWebQuickDeploy/dist/modules/ai/openaiDraw.service.js
vendored
Normal file
@@ -0,0 +1,145 @@
|
||||
"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 OpenAIDrawService_1;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.OpenAIDrawService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const axios_1 = require("axios");
|
||||
const chatLog_service_1 = require("../chatLog/chatLog.service");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const upload_service_1 = require("../upload/upload.service");
|
||||
const openaiChat_service_1 = require("./openaiChat.service");
|
||||
let OpenAIDrawService = OpenAIDrawService_1 = class OpenAIDrawService {
|
||||
constructor(uploadService, globalConfigService, chatLogService, openAIChatService) {
|
||||
this.uploadService = uploadService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
this.chatLogService = chatLogService;
|
||||
this.openAIChatService = openAIChatService;
|
||||
this.logger = new common_1.Logger(OpenAIDrawService_1.name);
|
||||
}
|
||||
async dalleDraw(inputs, buildMessageFromParentMessageId) {
|
||||
var _a, _b, _c, _d;
|
||||
common_1.Logger.log('开始提交 Dalle 绘图任务 ', 'DrawService');
|
||||
const { apiKey, model, proxyUrl, prompt, extraParam, timeout, onSuccess, onFailure, groupId, } = inputs;
|
||||
const isDalleChat = await this.globalConfigService.getConfigs([
|
||||
'isDalleChat',
|
||||
]);
|
||||
let drawPrompt;
|
||||
if (isDalleChat === '1') {
|
||||
try {
|
||||
common_1.Logger.log('已开启连续绘画模式', 'DalleDraw');
|
||||
const { messagesHistory } = await buildMessageFromParentMessageId(`参考上文,结合我的需求,给出绘画描述。我的需求是:${prompt}`, {
|
||||
groupId,
|
||||
systemMessage: '你是一个绘画提示词生成工具,请根据用户的要求,结合上下文,用一段文字,描述用户需要的绘画需求,不用包含任何礼貌性的寒暄,只需要场景的描述,可以适当联想',
|
||||
maxModelTokens: 8000,
|
||||
maxRounds: 5,
|
||||
fileInfo: '',
|
||||
}, this.chatLogService);
|
||||
drawPrompt = await this.openAIChatService.chatFree(prompt, undefined, messagesHistory);
|
||||
}
|
||||
catch (error) {
|
||||
console.error('调用chatFree失败:', error);
|
||||
drawPrompt = prompt;
|
||||
}
|
||||
}
|
||||
else {
|
||||
drawPrompt = prompt;
|
||||
}
|
||||
const size = (extraParam === null || extraParam === void 0 ? void 0 : extraParam.size) || '1024x1024';
|
||||
let result = { answer: '', fileInfo: '', status: 2 };
|
||||
try {
|
||||
const options = {
|
||||
method: 'POST',
|
||||
url: `${proxyUrl}/v1/images/generations`,
|
||||
timeout: timeout,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
},
|
||||
data: {
|
||||
model: model,
|
||||
prompt: drawPrompt,
|
||||
size,
|
||||
},
|
||||
};
|
||||
const response = await (0, axios_1.default)(options);
|
||||
const url = response.data.data[0].url;
|
||||
try {
|
||||
common_1.Logger.log(`------> 开始上传图片!!!`, 'DrawService');
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const currentDate = `${year}${month}/${day}`;
|
||||
result.fileInfo = await this.uploadService.uploadFileFromUrl({
|
||||
url: url,
|
||||
dir: `images/dalle/${currentDate}`,
|
||||
});
|
||||
common_1.Logger.log(`图片上传成功,URL: ${result.fileInfo}`, 'DrawService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`上传图片过程中出现错误: ${error}`, 'DrawService');
|
||||
}
|
||||
let revised_prompt_cn;
|
||||
try {
|
||||
revised_prompt_cn = await this.openAIChatService.chatFree(`根据提示词{${response.data.data[0].revised_prompt}}, 模拟AI绘画机器人的语气,用中文回复,告诉用户已经画好了`);
|
||||
}
|
||||
catch (error) {
|
||||
revised_prompt_cn = `${prompt} 绘制成功`;
|
||||
common_1.Logger.error('翻译失败: ', error);
|
||||
}
|
||||
result.answer = revised_prompt_cn;
|
||||
result.status = 3;
|
||||
onSuccess(result);
|
||||
return;
|
||||
}
|
||||
catch (error) {
|
||||
result.status = 5;
|
||||
onFailure(result);
|
||||
const status = ((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status) || 500;
|
||||
console.log('draw error: ', JSON.stringify(error), status);
|
||||
const message = (_d = (_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.message;
|
||||
if (status === 429) {
|
||||
result.text = '当前请求已过载、请稍等会儿再试试吧!';
|
||||
return result;
|
||||
}
|
||||
if (status === 400 &&
|
||||
message.includes('This request has been blocked by our content filters')) {
|
||||
result.text = '您的请求已被系统拒绝。您的提示可能存在一些非法的文本。';
|
||||
return result;
|
||||
}
|
||||
if (status === 400 &&
|
||||
message.includes('Billing hard limit has been reached')) {
|
||||
result.text =
|
||||
'当前模型key已被封禁、已冻结当前调用Key、尝试重新对话试试吧!';
|
||||
return result;
|
||||
}
|
||||
if (status === 500) {
|
||||
result.text = '绘制图片失败,请检查你的提示词是否有非法描述!';
|
||||
return result;
|
||||
}
|
||||
if (status === 401) {
|
||||
result.text = '绘制图片失败,此次绘画被拒绝了!';
|
||||
return result;
|
||||
}
|
||||
result.text = '绘制图片失败,请稍后试试吧!';
|
||||
return result;
|
||||
}
|
||||
}
|
||||
};
|
||||
OpenAIDrawService = OpenAIDrawService_1 = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [upload_service_1.UploadService,
|
||||
globalConfig_service_1.GlobalConfigService,
|
||||
chatLog_service_1.ChatLogService,
|
||||
openaiChat_service_1.OpenAIChatService])
|
||||
], OpenAIDrawService);
|
||||
exports.OpenAIDrawService = OpenAIDrawService;
|
||||
104
AIWebQuickDeploy/dist/modules/ai/stableDiffusion.service.js
vendored
Normal file
104
AIWebQuickDeploy/dist/modules/ai/stableDiffusion.service.js
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
"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 StableDiffusionService_1;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.StableDiffusionService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const axios_1 = require("axios");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const upload_service_1 = require("../upload/upload.service");
|
||||
let StableDiffusionService = StableDiffusionService_1 = class StableDiffusionService {
|
||||
constructor(uploadService, globalConfigService) {
|
||||
this.uploadService = uploadService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
this.logger = new common_1.Logger(StableDiffusionService_1.name);
|
||||
}
|
||||
async sdxl(inputs) {
|
||||
const { onSuccess, onFailure, apiKey, model, proxyUrl, modelName, timeout, chatId, prompt, } = inputs;
|
||||
let result = {
|
||||
answer: '',
|
||||
model: model,
|
||||
modelName: modelName,
|
||||
chatId: chatId,
|
||||
fileInfo: '',
|
||||
status: 2,
|
||||
};
|
||||
console.log('开始处理', { model, modelName, prompt });
|
||||
const options = {
|
||||
method: 'POST',
|
||||
url: `${proxyUrl}/v1/chat/completions`,
|
||||
timeout: timeout,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
},
|
||||
data: {
|
||||
model,
|
||||
messages: [{ role: 'user', content: prompt }],
|
||||
},
|
||||
};
|
||||
try {
|
||||
const response = await (0, axios_1.default)(options);
|
||||
console.log('API响应接收', response.data);
|
||||
if (response.data.choices && response.data.choices.length > 0) {
|
||||
const choice = response.data.choices[0];
|
||||
const content = choice.message.content;
|
||||
console.log('处理内容', content);
|
||||
const regex = /\]\((https?:\/\/[^\)]+)\)/;
|
||||
const match = content.match(regex);
|
||||
if (match && match[1]) {
|
||||
result.fileInfo = match[1];
|
||||
try {
|
||||
const localStorageStatus = await this.globalConfigService.getConfigs(['localStorageStatus']);
|
||||
if (Number(localStorageStatus)) {
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const currentDate = `${year}${month}/${day}`;
|
||||
result.fileInfo = await this.uploadService.uploadFileFromUrl({
|
||||
url: result.fileInfo,
|
||||
dir: `images/stable-diffusion/${currentDate}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`上传文件失败: ${error.message}`, 'StableDiffusionService');
|
||||
}
|
||||
console.log('找到链接', match[1]);
|
||||
}
|
||||
else {
|
||||
console.log('没有找到链接');
|
||||
}
|
||||
result.answer = `${prompt} 绘制成功`;
|
||||
if (result.fileInfo) {
|
||||
onSuccess(result);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
onFailure('No link found.');
|
||||
}
|
||||
}
|
||||
else {
|
||||
onFailure('No choices returned.');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error('服务器错误,请求失败:', error);
|
||||
}
|
||||
}
|
||||
};
|
||||
StableDiffusionService = StableDiffusionService_1 = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [upload_service_1.UploadService,
|
||||
globalConfig_service_1.GlobalConfigService])
|
||||
], StableDiffusionService);
|
||||
exports.StableDiffusionService = StableDiffusionService;
|
||||
325
AIWebQuickDeploy/dist/modules/ai/suno.service.js
vendored
Normal file
325
AIWebQuickDeploy/dist/modules/ai/suno.service.js
vendored
Normal file
@@ -0,0 +1,325 @@
|
||||
"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.SunoService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const axios_1 = require("axios");
|
||||
const chatLog_service_1 = require("../chatLog/chatLog.service");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const upload_service_1 = require("../upload/upload.service");
|
||||
let SunoService = class SunoService {
|
||||
constructor(chatLogService, uploadService, globalConfigService) {
|
||||
this.chatLogService = chatLogService;
|
||||
this.uploadService = uploadService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
}
|
||||
async suno(inputs) {
|
||||
var _a, _b, _c;
|
||||
const { apiKey, proxyUrl, action, prompt, timeout, assistantLogId, taskData, extraParam, } = inputs;
|
||||
common_1.Logger.debug(`SunoService: ${JSON.stringify(inputs)}`, 'SunoService');
|
||||
let result = {
|
||||
text: '',
|
||||
fileInfo: '',
|
||||
taskId: '',
|
||||
taskData: '',
|
||||
status: 2,
|
||||
};
|
||||
common_1.Logger.log('开始生成音乐', 'SunoService');
|
||||
let response = null;
|
||||
let url = '';
|
||||
let payloadJson = {};
|
||||
const headers = { Authorization: `Bearer ${apiKey}` };
|
||||
if (action === 'LYRICS') {
|
||||
url = `${proxyUrl}/task/suno/v1/submit/lyrics`;
|
||||
payloadJson = { prompt: prompt };
|
||||
}
|
||||
if (action === 'MUSIC') {
|
||||
url = `${proxyUrl}/task/suno/v1/submit/music`;
|
||||
try {
|
||||
payloadJson = JSON.parse(taskData);
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`解析taskData失败: ${error.message}`, 'SunoService');
|
||||
throw new Error('taskData格式错误');
|
||||
}
|
||||
}
|
||||
common_1.Logger.log(`正在准备发送请求到 ${url},payload: ${JSON.stringify(payloadJson)}, headers: ${JSON.stringify(headers)}`, 'SunoService');
|
||||
try {
|
||||
response = await axios_1.default.post(url, payloadJson, { headers });
|
||||
common_1.Logger.debug(`任务提交结果,状态码: ${response.status}, 状态消息: ${response.statusText}, 数据: ${JSON.stringify(response.data)}`);
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`任务提交失败: ${error.message}`, 'SunoService');
|
||||
throw new Error('任务提交失败');
|
||||
}
|
||||
if ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.data) {
|
||||
result.taskId = (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.data;
|
||||
common_1.Logger.log(`任务提交成功, 任务ID: ${(_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.data}`, 'SunoService');
|
||||
}
|
||||
else {
|
||||
throw new Error('未能获取结果数据, 即将重试');
|
||||
}
|
||||
try {
|
||||
await this.pollSunoMusicResult({
|
||||
proxyUrl,
|
||||
apiKey,
|
||||
taskId: response.data.data,
|
||||
timeout,
|
||||
prompt,
|
||||
action,
|
||||
onSuccess: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
videoUrl: data === null || data === void 0 ? void 0 : data.videoUrl,
|
||||
audioUrl: data === null || data === void 0 ? void 0 : data.audioUrl,
|
||||
fileInfo: data === null || data === void 0 ? void 0 : data.fileInfo,
|
||||
answer: (data === null || data === void 0 ? void 0 : data.answer) || prompt,
|
||||
progress: '100%',
|
||||
status: 3,
|
||||
taskId: data === null || data === void 0 ? void 0 : data.taskId,
|
||||
taskData: data === null || data === void 0 ? void 0 : data.taskData,
|
||||
});
|
||||
common_1.Logger.log('音乐任务已完成', 'SunoService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'SunoService');
|
||||
}
|
||||
},
|
||||
onAudioSuccess: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
videoUrl: data === null || data === void 0 ? void 0 : data.videoUrl,
|
||||
audioUrl: data === null || data === void 0 ? void 0 : data.audioUrl,
|
||||
fileInfo: data === null || data === void 0 ? void 0 : data.fileInfo,
|
||||
answer: (data === null || data === void 0 ? void 0 : data.answer) || prompt,
|
||||
progress: data === null || data === void 0 ? void 0 : data.progress,
|
||||
status: data.status,
|
||||
taskId: data === null || data === void 0 ? void 0 : data.taskId,
|
||||
taskData: data === null || data === void 0 ? void 0 : data.taskData,
|
||||
});
|
||||
common_1.Logger.log('音频生成成功,等待视频生成...', 'SunoService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'SunoService');
|
||||
}
|
||||
},
|
||||
onGenerating: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
videoUrl: data === null || data === void 0 ? void 0 : data.videoUrl,
|
||||
audioUrl: data === null || data === void 0 ? void 0 : data.audioUrl,
|
||||
fileInfo: data === null || data === void 0 ? void 0 : data.fileInfo,
|
||||
answer: (data === null || data === void 0 ? void 0 : data.answer) || '音乐生成中...',
|
||||
progress: data === null || data === void 0 ? void 0 : data.progress,
|
||||
status: data.status,
|
||||
});
|
||||
common_1.Logger.log('音乐生成中...', 'SunoService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'SunoService');
|
||||
}
|
||||
},
|
||||
onFailure: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
answer: '音乐生成失败',
|
||||
status: data.status,
|
||||
});
|
||||
common_1.Logger.log('生成失败', 'SunoService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'SunoService');
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error('查询生成结果时发生错误:', error.message, 'SunoService');
|
||||
throw new Error('查询生成结果时发生错误');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async pollSunoMusicResult(inputs) {
|
||||
const { proxyUrl, apiKey, taskId, timeout, onSuccess, onAudioSuccess, onFailure, onGenerating, action, } = inputs;
|
||||
let result = {
|
||||
videoUrl: '',
|
||||
audioUrl: '',
|
||||
fileInfo: '',
|
||||
drawId: '',
|
||||
taskData: '',
|
||||
status: 2,
|
||||
progress: 0,
|
||||
answer: '',
|
||||
};
|
||||
const headers = { Authorization: `Bearer ${apiKey}` };
|
||||
const url = `${proxyUrl}/task/suno/v1/fetch/${taskId}`;
|
||||
const startTime = Date.now();
|
||||
const POLL_INTERVAL = 5000;
|
||||
let retryCount = 0;
|
||||
try {
|
||||
while (Date.now() - startTime < timeout) {
|
||||
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
|
||||
try {
|
||||
const res = await axios_1.default.get(url, { headers });
|
||||
const responses = res.data.data;
|
||||
common_1.Logger.debug(`轮询结果: ${JSON.stringify(responses)}`, 'SunoService');
|
||||
if (action === 'LYRICS') {
|
||||
if (responses.status === 'SUCCESS') {
|
||||
result.taskId = responses.data.id;
|
||||
result.taskData = JSON.stringify(responses.data);
|
||||
result.answer = responses.data.text;
|
||||
onSuccess(result);
|
||||
return;
|
||||
}
|
||||
result.progress = responses === null || responses === void 0 ? void 0 : responses.progress;
|
||||
result.answer = `歌词生成中`;
|
||||
if (result.progress) {
|
||||
onGenerating(result);
|
||||
}
|
||||
}
|
||||
if (action === 'MUSIC') {
|
||||
if (responses.data) {
|
||||
const data = responses.data;
|
||||
result.taskData = JSON.stringify(data);
|
||||
if (Array.isArray(data)) {
|
||||
const validAudioUrls = data
|
||||
.map((item) => item.audio_url)
|
||||
.filter((url) => url);
|
||||
const validVideoUrls = data
|
||||
.map((item) => item.video_url)
|
||||
.filter((url) => url);
|
||||
const validImageUrls = data
|
||||
.map((item) => item.image_url)
|
||||
.filter((url) => url);
|
||||
const titles = data.map((item) => item.title);
|
||||
const firstTitle = titles.length > 0 ? titles[0] : '音乐已生成';
|
||||
if (responses.status === 'SUCCESS') {
|
||||
let audioUrls = [];
|
||||
let videoUrls = [];
|
||||
let imageUrls = [];
|
||||
try {
|
||||
const localStorageStatus = await this.globalConfigService.getConfigs([
|
||||
'localStorageStatus',
|
||||
]);
|
||||
if (Number(localStorageStatus)) {
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const currentDate = `${year}${month}/${day}`;
|
||||
for (const url of validAudioUrls) {
|
||||
try {
|
||||
const uploadedUrl = await this.uploadService.uploadFileFromUrl({
|
||||
url: url,
|
||||
dir: `audio/suno-music/${currentDate}`,
|
||||
});
|
||||
audioUrls.push(uploadedUrl);
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`上传音频文件失败: ${error.message}`, 'SunoService');
|
||||
audioUrls.push(url);
|
||||
}
|
||||
}
|
||||
for (const url of validVideoUrls) {
|
||||
try {
|
||||
const uploadedUrl = await this.uploadService.uploadFileFromUrl({
|
||||
url: url,
|
||||
dir: `video/suno-music/${currentDate}`,
|
||||
});
|
||||
videoUrls.push(uploadedUrl);
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`上传视频文件失败: ${error.message}`, 'SunoService');
|
||||
videoUrls.push(url);
|
||||
}
|
||||
}
|
||||
for (const url of validImageUrls) {
|
||||
try {
|
||||
const uploadedUrl = await this.uploadService.uploadFileFromUrl({
|
||||
url: url,
|
||||
dir: `images/suno-music/${currentDate}`,
|
||||
});
|
||||
imageUrls.push(uploadedUrl);
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`上传图片文件失败: ${error.message}`, 'SunoService');
|
||||
imageUrls.push(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
audioUrls = validAudioUrls;
|
||||
videoUrls = validVideoUrls;
|
||||
imageUrls = validImageUrls;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`获取配置失败: ${error.message}`, 'LumaService');
|
||||
audioUrls = validAudioUrls;
|
||||
videoUrls = validVideoUrls;
|
||||
imageUrls = validImageUrls;
|
||||
}
|
||||
result.audioUrl = audioUrls.join(',');
|
||||
result.videoUrl = videoUrls.join(',');
|
||||
result.fileInfo = imageUrls.join(',');
|
||||
if (validAudioUrls.length === 2) {
|
||||
result.status = 3;
|
||||
result.answer = firstTitle;
|
||||
}
|
||||
else {
|
||||
result.status = 2;
|
||||
result.progress = responses === null || responses === void 0 ? void 0 : responses.progress;
|
||||
result.answer = `当前生成进度 ${responses === null || responses === void 0 ? void 0 : responses.progress}`;
|
||||
}
|
||||
common_1.Logger.debug(`音乐生成成功: ${JSON.stringify(data)}`, 'SunoService');
|
||||
onSuccess(result);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
result.audioUrl = validAudioUrls.join(',');
|
||||
result.videoUrl = validVideoUrls.join(',');
|
||||
result.fileInfo = validImageUrls.join(',');
|
||||
result.status = 2;
|
||||
result.progress = responses === null || responses === void 0 ? void 0 : responses.progress;
|
||||
result.answer = firstTitle;
|
||||
onAudioSuccess(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!result.audioUrl && result.progress && result.status === 2) {
|
||||
onGenerating(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
retryCount++;
|
||||
common_1.Logger.error(`轮询失败,重试次数: ${retryCount}`, 'SunoService');
|
||||
}
|
||||
}
|
||||
common_1.Logger.error('轮询超时,请稍后再试!', 'SunoService');
|
||||
result.status = 4;
|
||||
onFailure(result);
|
||||
throw new Error('查询超时,请稍后再试!');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`轮询过程中发生错误: ${error}`, 'SunoService');
|
||||
result.status = 5;
|
||||
onFailure(result);
|
||||
}
|
||||
}
|
||||
};
|
||||
SunoService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [chatLog_service_1.ChatLogService,
|
||||
upload_service_1.UploadService,
|
||||
globalConfig_service_1.GlobalConfigService])
|
||||
], SunoService);
|
||||
exports.SunoService = SunoService;
|
||||
218
AIWebQuickDeploy/dist/modules/app/app.controller.js
vendored
Normal file
218
AIWebQuickDeploy/dist/modules/app/app.controller.js
vendored
Normal file
@@ -0,0 +1,218 @@
|
||||
"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.AppController = void 0;
|
||||
const adminAuth_guard_1 = require("../../common/auth/adminAuth.guard");
|
||||
const jwtAuth_guard_1 = require("../../common/auth/jwtAuth.guard");
|
||||
const superAuth_guard_1 = require("../../common/auth/superAuth.guard");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const app_service_1 = require("./app.service");
|
||||
const collectApp_dto_1 = require("./dto/collectApp.dto");
|
||||
const createApp_dto_1 = require("./dto/createApp.dto");
|
||||
const createCats_dto_1 = require("./dto/createCats.dto");
|
||||
const deleteApp_dto_1 = require("./dto/deleteApp.dto");
|
||||
const deleteCats_dto_1 = require("./dto/deleteCats.dto");
|
||||
const queryApp_dto_1 = require("./dto/queryApp.dto");
|
||||
const queryCats_dto_1 = require("./dto/queryCats.dto");
|
||||
const updateApp_dto_1 = require("./dto/updateApp.dto");
|
||||
const updateCats_dto_1 = require("./dto/updateCats.dto");
|
||||
let AppController = class AppController {
|
||||
constructor(appService) {
|
||||
this.appService = appService;
|
||||
}
|
||||
appCatsList(query) {
|
||||
return this.appService.appCatsList(query);
|
||||
}
|
||||
catsList() {
|
||||
const params = { status: 1, page: 1, size: 1000, name: '' };
|
||||
return this.appService.appCatsList(params);
|
||||
}
|
||||
queryOneCats(query) {
|
||||
return this.appService.queryOneCat(query);
|
||||
}
|
||||
createAppCat(body) {
|
||||
return this.appService.createAppCat(body);
|
||||
}
|
||||
updateAppCats(body) {
|
||||
return this.appService.updateAppCats(body);
|
||||
}
|
||||
delAppCat(body) {
|
||||
return this.appService.delAppCat(body);
|
||||
}
|
||||
appList(req, query) {
|
||||
return this.appService.appList(req, query);
|
||||
}
|
||||
list(req, query) {
|
||||
return this.appService.frontAppList(req, query);
|
||||
}
|
||||
async searchList(body) {
|
||||
return this.appService.searchAppList(body);
|
||||
}
|
||||
createApp(body) {
|
||||
return this.appService.createApp(body);
|
||||
}
|
||||
updateApp(body) {
|
||||
return this.appService.updateApp(body);
|
||||
}
|
||||
delApp(body) {
|
||||
return this.appService.delApp(body);
|
||||
}
|
||||
collect(body, req) {
|
||||
return this.appService.collect(body, req);
|
||||
}
|
||||
mineApps(req) {
|
||||
return this.appService.mineApps(req);
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Get)('queryAppCats'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '获取App分类列表' }),
|
||||
(0, common_1.UseGuards)(adminAuth_guard_1.AdminAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [queryCats_dto_1.QuerCatsDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "appCatsList", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('queryCats'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '用户端获取App分类列表' }),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "catsList", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('queryOneCat'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '用户端获取App分类列表' }),
|
||||
__param(0, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "queryOneCats", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('createAppCats'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '添加App分类' }),
|
||||
(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", [createCats_dto_1.CreateCatsDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "createAppCat", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('updateAppCats'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '修改App分类' }),
|
||||
(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", [updateCats_dto_1.UpdateCatsDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "updateAppCats", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('delAppCats'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '删除App分类' }),
|
||||
(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", [deleteCats_dto_1.DeleteCatsDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "delAppCat", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('queryApp'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '获取App列表' }),
|
||||
(0, common_1.UseGuards)(adminAuth_guard_1.AdminAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, queryApp_dto_1.QuerAppDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "appList", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('list'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '客户端获取App' }),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, queryApp_dto_1.QuerAppDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "list", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('searchList'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '客户端获取App' }),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AppController.prototype, "searchList", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('createApp'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '添加App' }),
|
||||
(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", [createApp_dto_1.CreateAppDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "createApp", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('updateApp'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '修改App' }),
|
||||
(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", [updateApp_dto_1.UpdateAppDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "updateApp", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('delApp'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '删除App' }),
|
||||
(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", [deleteApp_dto_1.OperateAppDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "delApp", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('collect'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '收藏/取消收藏App' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [collectApp_dto_1.CollectAppDto, Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "collect", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('mineApps'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '我的收藏' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "mineApps", null);
|
||||
AppController = __decorate([
|
||||
(0, swagger_1.ApiTags)('App'),
|
||||
(0, common_1.Controller)('app'),
|
||||
__metadata("design:paramtypes", [app_service_1.AppService])
|
||||
], AppController);
|
||||
exports.AppController = AppController;
|
||||
84
AIWebQuickDeploy/dist/modules/app/app.entity.js
vendored
Normal file
84
AIWebQuickDeploy/dist/modules/app/app.entity.js
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
"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.AppEntity = void 0;
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
const typeorm_1 = require("typeorm");
|
||||
let AppEntity = class AppEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ unique: true, comment: 'App应用名称' }),
|
||||
__metadata("design:type", String)
|
||||
], AppEntity.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App分类Id' }),
|
||||
__metadata("design:type", Number)
|
||||
], AppEntity.prototype, "catId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用描述信息' }),
|
||||
__metadata("design:type", String)
|
||||
], AppEntity.prototype, "des", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用预设场景信息', type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], AppEntity.prototype, "preset", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用封面图片', nullable: true, type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], AppEntity.prototype, "coverImg", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用排序、数字越大越靠前', default: 100 }),
|
||||
__metadata("design:type", Number)
|
||||
], AppEntity.prototype, "order", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用是否启用中 0:禁用 1:启用', default: 1 }),
|
||||
__metadata("design:type", Number)
|
||||
], AppEntity.prototype, "status", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App示例数据', nullable: true, type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], AppEntity.prototype, "demoData", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用角色 system user', default: 'system' }),
|
||||
__metadata("design:type", String)
|
||||
], AppEntity.prototype, "role", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用是否是GPTs', default: '0' }),
|
||||
__metadata("design:type", Number)
|
||||
], AppEntity.prototype, "isGPTs", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用是否是固定使用模型', default: '0' }),
|
||||
__metadata("design:type", Number)
|
||||
], AppEntity.prototype, "isFixedModel", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用使用的模型', type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], AppEntity.prototype, "appModel", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'GPTs 的调用ID', default: '' }),
|
||||
__metadata("design:type", String)
|
||||
], AppEntity.prototype, "gizmoID", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App是否共享到应用广场', default: false }),
|
||||
__metadata("design:type", Boolean)
|
||||
], AppEntity.prototype, "public", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '用户Id', nullable: true }),
|
||||
__metadata("design:type", Number)
|
||||
], AppEntity.prototype, "userId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '是否系统预留', default: false, nullable: true }),
|
||||
__metadata("design:type", Boolean)
|
||||
], AppEntity.prototype, "isSystemReserved", void 0);
|
||||
AppEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'app' })
|
||||
], AppEntity);
|
||||
exports.AppEntity = AppEntity;
|
||||
26
AIWebQuickDeploy/dist/modules/app/app.module.js
vendored
Normal file
26
AIWebQuickDeploy/dist/modules/app/app.module.js
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
"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.AppModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const app_controller_1 = require("./app.controller");
|
||||
const app_service_1 = require("./app.service");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const appCats_entity_1 = require("./appCats.entity");
|
||||
const app_entity_1 = require("./app.entity");
|
||||
const userApps_entity_1 = require("./userApps.entity");
|
||||
let AppModule = class AppModule {
|
||||
};
|
||||
AppModule = __decorate([
|
||||
(0, common_1.Module)({
|
||||
imports: [typeorm_1.TypeOrmModule.forFeature([appCats_entity_1.AppCatsEntity, app_entity_1.AppEntity, userApps_entity_1.UserAppsEntity])],
|
||||
controllers: [app_controller_1.AppController],
|
||||
providers: [app_service_1.AppService],
|
||||
})
|
||||
], AppModule);
|
||||
exports.AppModule = AppModule;
|
||||
331
AIWebQuickDeploy/dist/modules/app/app.service.js
vendored
Normal file
331
AIWebQuickDeploy/dist/modules/app/app.service.js
vendored
Normal file
@@ -0,0 +1,331 @@
|
||||
"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.AppService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const typeorm_2 = require("typeorm");
|
||||
const app_entity_1 = require("./app.entity");
|
||||
const appCats_entity_1 = require("./appCats.entity");
|
||||
const userApps_entity_1 = require("./userApps.entity");
|
||||
let AppService = class AppService {
|
||||
constructor(appCatsEntity, appEntity, userAppsEntity) {
|
||||
this.appCatsEntity = appCatsEntity;
|
||||
this.appEntity = appEntity;
|
||||
this.userAppsEntity = userAppsEntity;
|
||||
}
|
||||
async createAppCat(body) {
|
||||
const { name } = body;
|
||||
const c = await this.appCatsEntity.findOne({ where: { name } });
|
||||
if (c) {
|
||||
throw new common_1.HttpException('该分类名称已存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return await this.appCatsEntity.save(body);
|
||||
}
|
||||
async delAppCat(body) {
|
||||
const { id } = body;
|
||||
const c = await this.appCatsEntity.findOne({ where: { id } });
|
||||
if (!c) {
|
||||
throw new common_1.HttpException('该分类不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const count = await this.appEntity.count({ where: { catId: id } });
|
||||
if (count > 0) {
|
||||
throw new common_1.HttpException('该分类下存在App,不可删除!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const res = await this.appCatsEntity.delete(id);
|
||||
if (res.affected > 0)
|
||||
return '删除成功';
|
||||
throw new common_1.HttpException('删除失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
async updateAppCats(body) {
|
||||
const { id, name } = body;
|
||||
const c = await this.appCatsEntity.findOne({
|
||||
where: { name, id: (0, typeorm_2.Not)(id) },
|
||||
});
|
||||
if (c) {
|
||||
throw new common_1.HttpException('该分类名称已存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const res = await this.appCatsEntity.update({ id }, body);
|
||||
if (res.affected > 0)
|
||||
return '修改成功';
|
||||
throw new common_1.HttpException('修改失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
async queryOneCat(params) {
|
||||
const { id } = params;
|
||||
if (!id) {
|
||||
throw new common_1.HttpException('缺失必要参数!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const app = await this.appEntity.findOne({ where: { id } });
|
||||
const { demoData: demo, coverImg, des, name, isFixedModel, isGPTs, appModel, } = app;
|
||||
return {
|
||||
demoData: demo ? demo.split('\n') : [],
|
||||
coverImg,
|
||||
des,
|
||||
name,
|
||||
isGPTs,
|
||||
isFixedModel,
|
||||
appModel,
|
||||
};
|
||||
}
|
||||
async appCatsList(query) {
|
||||
const { page = 1, size = 10, name, status } = query;
|
||||
const where = {};
|
||||
name && (where.name = (0, typeorm_2.Like)(`%${name}%`));
|
||||
[0, 1, '0', '1'].includes(status) && (where.status = status);
|
||||
const [rows, count] = await this.appCatsEntity.findAndCount({
|
||||
where,
|
||||
order: { order: 'DESC' },
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
});
|
||||
const catIds = rows.map((item) => item.id);
|
||||
const apps = await this.appEntity.find({ where: { catId: (0, typeorm_2.In)(catIds) } });
|
||||
const appCountMap = {};
|
||||
apps.forEach((item) => {
|
||||
if (appCountMap[item.catId]) {
|
||||
appCountMap[item.catId] += 1;
|
||||
}
|
||||
else {
|
||||
appCountMap[item.catId] = 1;
|
||||
}
|
||||
});
|
||||
rows.forEach((item) => (item.appCount = appCountMap[item.id] || 0));
|
||||
return { rows, count };
|
||||
}
|
||||
async appList(req, query, orderKey = 'id') {
|
||||
var _a;
|
||||
const { page = 1, size = 10, name, status, catId, role } = query;
|
||||
const where = { isSystemReserved: 0 };
|
||||
name && (where.name = (0, typeorm_2.Like)(`%${name}%`));
|
||||
catId && (where.catId = catId);
|
||||
role && (where.role = role);
|
||||
status && (where.status = status);
|
||||
const [rows, count] = await this.appEntity.findAndCount({
|
||||
where,
|
||||
order: { [orderKey]: 'DESC' },
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
});
|
||||
const catIds = rows.map((item) => item.catId);
|
||||
const cats = await this.appCatsEntity.find({ where: { id: (0, typeorm_2.In)(catIds) } });
|
||||
rows.forEach((item) => {
|
||||
const cat = cats.find((c) => c.id === item.catId);
|
||||
item.catName = cat ? cat.name : '';
|
||||
});
|
||||
if (((_a = req === null || req === void 0 ? void 0 : req.user) === null || _a === void 0 ? void 0 : _a.role) !== 'super') {
|
||||
rows.forEach((item) => {
|
||||
delete item.preset;
|
||||
});
|
||||
}
|
||||
return { rows, count };
|
||||
}
|
||||
async frontAppList(req, query, orderKey = 'id') {
|
||||
var _a;
|
||||
const { page = 1, size = 1000, name, catId, role } = query;
|
||||
const where = [
|
||||
{
|
||||
status: (0, typeorm_2.In)([1, 4]),
|
||||
userId: (0, typeorm_2.IsNull)(),
|
||||
public: false,
|
||||
isSystemReserved: 0,
|
||||
},
|
||||
{ userId: (0, typeorm_2.MoreThan)(0), public: true },
|
||||
];
|
||||
const [rows, count] = await this.appEntity.findAndCount({
|
||||
where,
|
||||
order: { order: 'DESC' },
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
});
|
||||
const catIds = rows.map((item) => item.catId);
|
||||
const cats = await this.appCatsEntity.find({ where: { id: (0, typeorm_2.In)(catIds) } });
|
||||
rows.forEach((item) => {
|
||||
const cat = cats.find((c) => c.id === item.catId);
|
||||
item.catName = cat ? cat.name : '';
|
||||
});
|
||||
if (((_a = req === null || req === void 0 ? void 0 : req.user) === null || _a === void 0 ? void 0 : _a.role) !== 'super') {
|
||||
rows.forEach((item) => {
|
||||
delete item.preset;
|
||||
});
|
||||
}
|
||||
return { rows, count };
|
||||
}
|
||||
async searchAppList(body) {
|
||||
console.log('搜索App列表', body);
|
||||
const { page = 1, size = 1000, keyword } = body;
|
||||
console.log(`搜索关键词:${keyword}`);
|
||||
let baseWhere = [
|
||||
{
|
||||
status: (0, typeorm_2.In)([1, 4]),
|
||||
userId: (0, typeorm_2.IsNull)(),
|
||||
public: false,
|
||||
isSystemReserved: 0,
|
||||
},
|
||||
{ userId: (0, typeorm_2.MoreThan)(0), public: true },
|
||||
];
|
||||
console.log('初始查询条件:', JSON.stringify(baseWhere));
|
||||
if (keyword) {
|
||||
baseWhere = baseWhere.map((condition) => (Object.assign(Object.assign({}, condition), { name: (0, typeorm_2.Like)(`%${keyword}%`) })));
|
||||
console.log('更新后的查询条件:', JSON.stringify(baseWhere));
|
||||
}
|
||||
try {
|
||||
const [rows, count] = await this.appEntity.findAndCount({
|
||||
where: baseWhere,
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
});
|
||||
console.log(`查询返回 ${count} 条结果,显示第 ${page} 页的结果。`);
|
||||
rows.forEach((item) => {
|
||||
delete item.preset;
|
||||
});
|
||||
console.log('完成查询,准备返回结果');
|
||||
return { rows, count };
|
||||
}
|
||||
catch (error) {
|
||||
console.error('查询数据库时出错:', error);
|
||||
throw new Error('Database query failed');
|
||||
}
|
||||
}
|
||||
async createApp(body) {
|
||||
const { name, catId } = body;
|
||||
body.role = 'system';
|
||||
const a = await this.appEntity.findOne({ where: { name } });
|
||||
if (a) {
|
||||
throw new common_1.HttpException('该应用名称已存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const c = await this.appCatsEntity.findOne({ where: { id: catId } });
|
||||
if (!c) {
|
||||
throw new common_1.HttpException('该分类不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return await this.appEntity.save(body);
|
||||
}
|
||||
async updateApp(body) {
|
||||
const { id, name, catId, status } = body;
|
||||
const a = await this.appEntity.findOne({ where: { name, id: (0, typeorm_2.Not)(id) } });
|
||||
if (a) {
|
||||
throw new common_1.HttpException('该应用名称已存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const c = await this.appCatsEntity.findOne({ where: { id: catId } });
|
||||
if (!c) {
|
||||
throw new common_1.HttpException('该分类不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const curApp = await this.appEntity.findOne({ where: { id } });
|
||||
if (curApp.status !== body.status) {
|
||||
await this.userAppsEntity.update({ appId: id }, { status });
|
||||
}
|
||||
const res = await this.appEntity.update({ id }, body);
|
||||
if (res.affected > 0)
|
||||
return '修改App信息成功';
|
||||
throw new common_1.HttpException('修改App信息失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
async delApp(body) {
|
||||
const { id } = body;
|
||||
const a = await this.appEntity.findOne({ where: { id } });
|
||||
if (!a) {
|
||||
throw new common_1.HttpException('该应用不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const useApp = await this.userAppsEntity.count({ where: { appId: id } });
|
||||
const res = await this.appEntity.delete(id);
|
||||
if (res.affected > 0)
|
||||
return '删除App成功';
|
||||
throw new common_1.HttpException('删除App失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
async auditPass(body) {
|
||||
const { id } = body;
|
||||
const a = await this.appEntity.findOne({ where: { id, status: 3 } });
|
||||
if (!a) {
|
||||
throw new common_1.HttpException('该应用不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
await this.appEntity.update({ id }, { status: 4 });
|
||||
await this.userAppsEntity.update({ appId: id }, { status: 4 });
|
||||
return '应用审核通过';
|
||||
}
|
||||
async auditFail(body) {
|
||||
const { id } = body;
|
||||
const a = await this.appEntity.findOne({ where: { id, status: 3 } });
|
||||
if (!a) {
|
||||
throw new common_1.HttpException('该应用不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
await this.appEntity.update({ id }, { status: 5 });
|
||||
await this.userAppsEntity.update({ appId: id }, { status: 5 });
|
||||
return '应用审核拒绝完成';
|
||||
}
|
||||
async collect(body, req) {
|
||||
const { appId } = body;
|
||||
const { id: userId } = req.user;
|
||||
const historyApp = await this.userAppsEntity.findOne({
|
||||
where: { appId, userId },
|
||||
});
|
||||
if (historyApp) {
|
||||
const r = await this.userAppsEntity.delete({ appId, userId });
|
||||
if (r.affected > 0) {
|
||||
return '取消收藏成功!';
|
||||
}
|
||||
else {
|
||||
throw new common_1.HttpException('取消收藏失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
const app = await this.appEntity.findOne({ where: { id: appId } });
|
||||
const { id, role: appRole, catId } = app;
|
||||
const collectInfo = {
|
||||
userId,
|
||||
appId: id,
|
||||
catId,
|
||||
appRole,
|
||||
public: true,
|
||||
status: 1,
|
||||
};
|
||||
await this.userAppsEntity.save(collectInfo);
|
||||
return '已将应用加入到我的收藏!';
|
||||
}
|
||||
async mineApps(req, query = { page: 1, size: 30 }) {
|
||||
const { id } = req.user;
|
||||
const { page = 1, size = 30 } = query;
|
||||
let rows, count;
|
||||
try {
|
||||
[rows, count] = await this.userAppsEntity.findAndCount({
|
||||
where: { userId: id, status: (0, typeorm_2.In)([1, 3, 4, 5]) },
|
||||
order: { id: 'DESC' },
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
});
|
||||
const appIds = rows.map((item) => item.appId);
|
||||
const appsInfo = await this.appEntity.find({ where: { id: (0, typeorm_2.In)(appIds) } });
|
||||
rows.forEach((item) => {
|
||||
const app = appsInfo.find((c) => c.id === item.appId);
|
||||
item.appName = app ? app.name : '未知';
|
||||
item.appRole = app ? app.role : '未知';
|
||||
item.appDes = app ? app.des : '未知';
|
||||
item.coverImg = app ? app.coverImg : '未知';
|
||||
item.demoData = app ? app.demoData : '未知';
|
||||
item.preset = app.userId === id ? app.preset : '******';
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`处理用户ID: ${id} 的mineApps请求时发生错误`, error);
|
||||
throw error;
|
||||
}
|
||||
return { rows, count };
|
||||
}
|
||||
};
|
||||
AppService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__param(0, (0, typeorm_1.InjectRepository)(appCats_entity_1.AppCatsEntity)),
|
||||
__param(1, (0, typeorm_1.InjectRepository)(app_entity_1.AppEntity)),
|
||||
__param(2, (0, typeorm_1.InjectRepository)(userApps_entity_1.UserAppsEntity)),
|
||||
__metadata("design:paramtypes", [typeorm_2.Repository,
|
||||
typeorm_2.Repository,
|
||||
typeorm_2.Repository])
|
||||
], AppService);
|
||||
exports.AppService = AppService;
|
||||
32
AIWebQuickDeploy/dist/modules/app/appCats.entity.js
vendored
Normal file
32
AIWebQuickDeploy/dist/modules/app/appCats.entity.js
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
"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.AppCatsEntity = void 0;
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
const typeorm_1 = require("typeorm");
|
||||
let AppCatsEntity = class AppCatsEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ unique: true, comment: 'App分类名称' }),
|
||||
__metadata("design:type", String)
|
||||
], AppCatsEntity.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App分类排序、数字越大越靠前', default: 100 }),
|
||||
__metadata("design:type", Number)
|
||||
], AppCatsEntity.prototype, "order", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App分类是否启用中 0:禁用 1:启用', default: 1 }),
|
||||
__metadata("design:type", Number)
|
||||
], AppCatsEntity.prototype, "status", void 0);
|
||||
AppCatsEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'app_cats' })
|
||||
], AppCatsEntity);
|
||||
exports.AppCatsEntity = AppCatsEntity;
|
||||
22
AIWebQuickDeploy/dist/modules/app/dto/collectApp.dto.js
vendored
Normal file
22
AIWebQuickDeploy/dist/modules/app/dto/collectApp.dto.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"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.CollectAppDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class CollectAppDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '要收藏的appId', required: true }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: 'ID必须是Number' }),
|
||||
__metadata("design:type", Number)
|
||||
], CollectAppDto.prototype, "appId", void 0);
|
||||
exports.CollectAppDto = CollectAppDto;
|
||||
75
AIWebQuickDeploy/dist/modules/app/dto/createApp.dto.js
vendored
Normal file
75
AIWebQuickDeploy/dist/modules/app/dto/createApp.dto.js
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
"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.CreateAppDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class CreateAppDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '前端助手', description: 'app名称', required: true }),
|
||||
(0, class_validator_1.IsDefined)({ message: 'app名称是必传参数' }),
|
||||
__metadata("design:type", String)
|
||||
], CreateAppDto.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: 'app分类Id', required: true }),
|
||||
(0, class_validator_1.IsDefined)({ message: 'app分类Id必传参数' }),
|
||||
__metadata("design:type", Number)
|
||||
], CreateAppDto.prototype, "catId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: '适用于编程编码、期望成为您的编程助手',
|
||||
description: 'app名称详情描述',
|
||||
required: false,
|
||||
}),
|
||||
(0, class_validator_1.IsDefined)({ message: 'app名称描述是必传参数' }),
|
||||
__metadata("design:type", String)
|
||||
], CreateAppDto.prototype, "des", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '你现在是一个翻译官。接下来我说的所有话帮我翻译成中文', description: '预设的prompt', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], CreateAppDto.prototype, "preset", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'GPTs 的调用ID', description: 'GPTs 使用的 ID', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], CreateAppDto.prototype, "gizmoID", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ description: '是否GPTs', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], CreateAppDto.prototype, "isGPTs", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'https://xxxx.png', description: '套餐封面图片', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], CreateAppDto.prototype, "coverImg", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 100, description: '套餐排序、数字越大越靠前', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], CreateAppDto.prototype, "order", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '套餐状态 0:禁用 1:启用', required: true }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '套餐状态必须是Number' }),
|
||||
(0, class_validator_1.IsIn)([0, 1, 3, 4, 5], { message: '套餐状态错误' }),
|
||||
__metadata("design:type", Number)
|
||||
], CreateAppDto.prototype, "status", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '这是一句示例数据', description: 'app示例数据', required: false }),
|
||||
__metadata("design:type", String)
|
||||
], CreateAppDto.prototype, "demoData", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'system', description: '创建的角色', required: false }),
|
||||
__metadata("design:type", String)
|
||||
], CreateAppDto.prototype, "role", void 0);
|
||||
exports.CreateAppDto = CreateAppDto;
|
||||
45
AIWebQuickDeploy/dist/modules/app/dto/createCats.dto.js
vendored
Normal file
45
AIWebQuickDeploy/dist/modules/app/dto/createCats.dto.js
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
"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.CreateCatsDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class CreateCatsDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: '编程助手',
|
||||
description: 'app分类名称',
|
||||
required: true,
|
||||
}),
|
||||
(0, class_validator_1.IsDefined)({ message: 'app分类名称是必传参数' }),
|
||||
__metadata("design:type", String)
|
||||
], CreateCatsDto.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: 100,
|
||||
description: '分类排序、数字越大越靠前',
|
||||
required: false,
|
||||
}),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], CreateCatsDto.prototype, "order", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: 1,
|
||||
description: '分类状态 0:禁用 1:启用',
|
||||
required: true,
|
||||
}),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '状态必须是Number' }),
|
||||
(0, class_validator_1.IsIn)([0, 1, 3, 4, 5], { message: '套餐状态错误' }),
|
||||
__metadata("design:type", Number)
|
||||
], CreateCatsDto.prototype, "status", void 0);
|
||||
exports.CreateCatsDto = CreateCatsDto;
|
||||
55
AIWebQuickDeploy/dist/modules/app/dto/custonApp.dto.js
vendored
Normal file
55
AIWebQuickDeploy/dist/modules/app/dto/custonApp.dto.js
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
"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.CustomAppDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class CustomAppDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '前端助手', description: 'app名称', required: true }),
|
||||
__metadata("design:type", String)
|
||||
], CustomAppDto.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: 'app分类Id', required: true }),
|
||||
__metadata("design:type", Number)
|
||||
], CustomAppDto.prototype, "catId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: '适用于编程编码、期望成为您的编程助手',
|
||||
description: 'app名称详情描述',
|
||||
required: false,
|
||||
}),
|
||||
(0, class_validator_1.IsDefined)({ message: 'app名称描述是必传参数' }),
|
||||
__metadata("design:type", String)
|
||||
], CustomAppDto.prototype, "des", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '你现在是一个翻译官。接下来我说的所有话帮我翻译成中文', description: '预设的prompt', required: true }),
|
||||
__metadata("design:type", String)
|
||||
], CustomAppDto.prototype, "preset", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'https://xxxx.png', description: '套餐封面图片', required: false }),
|
||||
__metadata("design:type", String)
|
||||
], CustomAppDto.prototype, "coverImg", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '这是一句示例数据', description: 'app示例数据', required: false }),
|
||||
__metadata("design:type", String)
|
||||
], CustomAppDto.prototype, "demoData", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: false, description: '是否共享到所有人', required: false }),
|
||||
__metadata("design:type", Boolean)
|
||||
], CustomAppDto.prototype, "public", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '应用ID', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], CustomAppDto.prototype, "appId", void 0);
|
||||
exports.CustomAppDto = CustomAppDto;
|
||||
22
AIWebQuickDeploy/dist/modules/app/dto/deleteApp.dto.js
vendored
Normal file
22
AIWebQuickDeploy/dist/modules/app/dto/deleteApp.dto.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"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.OperateAppDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class OperateAppDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '要删除的appId', required: true }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: 'ID必须是Number' }),
|
||||
__metadata("design:type", Number)
|
||||
], OperateAppDto.prototype, "id", void 0);
|
||||
exports.OperateAppDto = OperateAppDto;
|
||||
22
AIWebQuickDeploy/dist/modules/app/dto/deleteCats.dto.js
vendored
Normal file
22
AIWebQuickDeploy/dist/modules/app/dto/deleteCats.dto.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"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.DeleteCatsDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class DeleteCatsDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '要删除app分类Id', required: true }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: 'ID必须是Number' }),
|
||||
__metadata("design:type", Number)
|
||||
], DeleteCatsDto.prototype, "id", void 0);
|
||||
exports.DeleteCatsDto = DeleteCatsDto;
|
||||
52
AIWebQuickDeploy/dist/modules/app/dto/queryApp.dto.js
vendored
Normal file
52
AIWebQuickDeploy/dist/modules/app/dto/queryApp.dto.js
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
"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.QuerAppDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class QuerAppDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAppDto.prototype, "page", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAppDto.prototype, "size", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'name', description: 'app名称', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QuerAppDto.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: 'app状态 0:禁用 1:启用 3:审核加入广场中 4:已拒绝加入广场', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAppDto.prototype, "status", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 2, description: 'app分类Id', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAppDto.prototype, "catId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'role', description: 'app角色', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QuerAppDto.prototype, "role", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '关键词', description: '搜索关键词', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QuerAppDto.prototype, "keyword", void 0);
|
||||
exports.QuerAppDto = QuerAppDto;
|
||||
37
AIWebQuickDeploy/dist/modules/app/dto/queryCats.dto.js
vendored
Normal file
37
AIWebQuickDeploy/dist/modules/app/dto/queryCats.dto.js
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
"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.QuerCatsDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class QuerCatsDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerCatsDto.prototype, "page", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerCatsDto.prototype, "size", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'name', description: '分类名称', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QuerCatsDto.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '分类状态 0:禁用 1:启用', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerCatsDto.prototype, "status", void 0);
|
||||
exports.QuerCatsDto = QuerCatsDto;
|
||||
23
AIWebQuickDeploy/dist/modules/app/dto/updateApp.dto.js
vendored
Normal file
23
AIWebQuickDeploy/dist/modules/app/dto/updateApp.dto.js
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
"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.UpdateAppDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const createApp_dto_1 = require("./createApp.dto");
|
||||
class UpdateAppDto extends createApp_dto_1.CreateAppDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '要修改的分类Id', required: true }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '分类ID必须是Number' }),
|
||||
__metadata("design:type", Number)
|
||||
], UpdateAppDto.prototype, "id", void 0);
|
||||
exports.UpdateAppDto = UpdateAppDto;
|
||||
23
AIWebQuickDeploy/dist/modules/app/dto/updateCats.dto.js
vendored
Normal file
23
AIWebQuickDeploy/dist/modules/app/dto/updateCats.dto.js
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
"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.UpdateCatsDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const createCats_dto_1 = require("./createCats.dto");
|
||||
class UpdateCatsDto extends createCats_dto_1.CreateCatsDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '要修改的分类Id', required: true }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '分类ID必须是Number' }),
|
||||
__metadata("design:type", Number)
|
||||
], UpdateCatsDto.prototype, "id", void 0);
|
||||
exports.UpdateCatsDto = UpdateCatsDto;
|
||||
48
AIWebQuickDeploy/dist/modules/app/userApps.entity.js
vendored
Normal file
48
AIWebQuickDeploy/dist/modules/app/userApps.entity.js
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
"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.UserAppsEntity = void 0;
|
||||
const typeorm_1 = require("typeorm");
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
let UserAppsEntity = class UserAppsEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '用户ID' }),
|
||||
__metadata("design:type", Number)
|
||||
], UserAppsEntity.prototype, "userId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '应用ID' }),
|
||||
__metadata("design:type", Number)
|
||||
], UserAppsEntity.prototype, "appId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '应用分类ID' }),
|
||||
__metadata("design:type", Number)
|
||||
], UserAppsEntity.prototype, "catId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'app类型 system/user', default: 'user' }),
|
||||
__metadata("design:type", String)
|
||||
], UserAppsEntity.prototype, "appType", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '是否公开到公告菜单', default: false }),
|
||||
__metadata("design:type", Boolean)
|
||||
], UserAppsEntity.prototype, "public", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'app状态 1正常 2审核 3违规', default: 1 }),
|
||||
__metadata("design:type", Number)
|
||||
], UserAppsEntity.prototype, "status", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用排序、数字越大越靠前', default: 100 }),
|
||||
__metadata("design:type", Number)
|
||||
], UserAppsEntity.prototype, "order", void 0);
|
||||
UserAppsEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'user_apps' })
|
||||
], UserAppsEntity);
|
||||
exports.UserAppsEntity = UserAppsEntity;
|
||||
161
AIWebQuickDeploy/dist/modules/auth/auth.controller.js
vendored
Normal file
161
AIWebQuickDeploy/dist/modules/auth/auth.controller.js
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
"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.AuthController = void 0;
|
||||
const jwtAuth_guard_1 = require("../../common/auth/jwtAuth.guard");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const auth_service_1 = require("./auth.service");
|
||||
const authLogin_dto_1 = require("./dto/authLogin.dto");
|
||||
const authRegister_dto_1 = require("./dto/authRegister.dto");
|
||||
const updatePassByOther_dto_1 = require("./dto/updatePassByOther.dto");
|
||||
const updatePassword_dto_1 = require("./dto/updatePassword.dto");
|
||||
let AuthController = class AuthController {
|
||||
constructor(authService) {
|
||||
this.authService = authService;
|
||||
}
|
||||
async register(body, req) {
|
||||
return await this.authService.register(body, req);
|
||||
}
|
||||
async login(body, req) {
|
||||
return this.authService.login(body, req);
|
||||
}
|
||||
async loginWithCaptcha(body, req) {
|
||||
return this.authService.loginWithCaptcha(body, req);
|
||||
}
|
||||
async updatePassword(req, body) {
|
||||
return this.authService.updatePassword(req, body);
|
||||
}
|
||||
async updatePassByOther(req, body) {
|
||||
return this.authService.updatePassByOther(req, body);
|
||||
}
|
||||
async getInfo(req) {
|
||||
return this.authService.getInfo(req);
|
||||
}
|
||||
async sendCode(parmas) {
|
||||
return this.authService.sendCode(parmas);
|
||||
}
|
||||
async sendPhoneCode(parmas) {
|
||||
return this.authService.sendPhoneCode(parmas);
|
||||
}
|
||||
async verifyIdentity(req, body) {
|
||||
return this.authService.verifyIdentity(req, body);
|
||||
}
|
||||
async verifyPhoneIdentity(req, body) {
|
||||
return this.authService.verifyPhoneIdentity(req, body);
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Post)('register'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '用户注册' }),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [authRegister_dto_1.UserRegisterDto, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "register", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('login'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '用户登录' }),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [authLogin_dto_1.UserLoginDto, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "login", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('loginWithCaptcha'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '用户使用验证码登录' }),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "loginWithCaptcha", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('updatePassword'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '用户更改密码' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, updatePassword_dto_1.UpdatePasswordDto]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "updatePassword", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('updatePassByOther'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '用户更改密码' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, updatePassByOther_dto_1.UpdatePassByOtherDto]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "updatePassByOther", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('getInfo'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '获取用户个人信息' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "getInfo", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('sendCode'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '发送验证码' }),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "sendCode", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('sendPhoneCode'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '发送手机验证码' }),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "sendPhoneCode", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('verifyIdentity'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '验证身份' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "verifyIdentity", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('verifyPhoneIdentity'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '验证手机号' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "verifyPhoneIdentity", null);
|
||||
AuthController = __decorate([
|
||||
(0, swagger_1.ApiTags)('auth'),
|
||||
(0, common_1.Controller)('auth'),
|
||||
__metadata("design:paramtypes", [auth_service_1.AuthService])
|
||||
], AuthController);
|
||||
exports.AuthController = AuthController;
|
||||
76
AIWebQuickDeploy/dist/modules/auth/auth.module.js
vendored
Normal file
76
AIWebQuickDeploy/dist/modules/auth/auth.module.js
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
"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.AuthModule = void 0;
|
||||
const jwt_strategy_1 = require("../../common/auth/jwt.strategy");
|
||||
const jwtAuth_guard_1 = require("../../common/auth/jwtAuth.guard");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const jwt_1 = require("@nestjs/jwt");
|
||||
const passport_1 = require("@nestjs/passport");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const chatGroup_entity_1 = require("../chatGroup/chatGroup.entity");
|
||||
const chatLog_entity_1 = require("../chatLog/chatLog.entity");
|
||||
const cramiPackage_entity_1 = require("../crami/cramiPackage.entity");
|
||||
const config_entity_1 = require("../globalConfig/config.entity");
|
||||
const mailer_service_1 = require("../mailer/mailer.service");
|
||||
const redisCache_module_1 = require("../redisCache/redisCache.module");
|
||||
const redisCache_service_1 = require("../redisCache/redisCache.service");
|
||||
const user_entity_1 = require("../user/user.entity");
|
||||
const user_module_1 = require("../user/user.module");
|
||||
const accountLog_entity_1 = require("../userBalance/accountLog.entity");
|
||||
const balance_entity_1 = require("../userBalance/balance.entity");
|
||||
const fingerprint_entity_1 = require("../userBalance/fingerprint.entity");
|
||||
const userBalance_entity_1 = require("../userBalance/userBalance.entity");
|
||||
const userBalance_service_1 = require("../userBalance/userBalance.service");
|
||||
const verification_service_1 = require("./../verification/verification.service");
|
||||
const verifycation_entity_1 = require("./../verification/verifycation.entity");
|
||||
const auth_controller_1 = require("./auth.controller");
|
||||
const auth_service_1 = require("./auth.service");
|
||||
let AuthModule = class AuthModule {
|
||||
};
|
||||
AuthModule = __decorate([
|
||||
(0, common_1.Global)(),
|
||||
(0, common_1.Module)({
|
||||
imports: [
|
||||
user_module_1.UserModule,
|
||||
redisCache_module_1.RedisCacheModule,
|
||||
passport_1.PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||
jwt_1.JwtModule.registerAsync({
|
||||
inject: [redisCache_service_1.RedisCacheService],
|
||||
useFactory: async (redisService) => ({
|
||||
secret: await redisService.getJwtSecret(),
|
||||
signOptions: { expiresIn: '7d' },
|
||||
}),
|
||||
}),
|
||||
typeorm_1.TypeOrmModule.forFeature([
|
||||
verifycation_entity_1.VerifycationEntity,
|
||||
balance_entity_1.BalanceEntity,
|
||||
accountLog_entity_1.AccountLogEntity,
|
||||
config_entity_1.ConfigEntity,
|
||||
cramiPackage_entity_1.CramiPackageEntity,
|
||||
userBalance_entity_1.UserBalanceEntity,
|
||||
user_entity_1.UserEntity,
|
||||
fingerprint_entity_1.FingerprintLogEntity,
|
||||
chatLog_entity_1.ChatLogEntity,
|
||||
chatGroup_entity_1.ChatGroupEntity,
|
||||
]),
|
||||
],
|
||||
controllers: [auth_controller_1.AuthController],
|
||||
providers: [
|
||||
auth_service_1.AuthService,
|
||||
jwt_strategy_1.JwtStrategy,
|
||||
jwtAuth_guard_1.JwtAuthGuard,
|
||||
mailer_service_1.MailerService,
|
||||
verification_service_1.VerificationService,
|
||||
userBalance_service_1.UserBalanceService,
|
||||
redisCache_service_1.RedisCacheService,
|
||||
],
|
||||
exports: [auth_service_1.AuthService],
|
||||
})
|
||||
], AuthModule);
|
||||
exports.AuthModule = AuthModule;
|
||||
460
AIWebQuickDeploy/dist/modules/auth/auth.service.js
vendored
Normal file
460
AIWebQuickDeploy/dist/modules/auth/auth.service.js
vendored
Normal file
@@ -0,0 +1,460 @@
|
||||
"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.AuthService = void 0;
|
||||
const user_constant_1 = require("../../common/constants/user.constant");
|
||||
const utils_1 = require("../../common/utils");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const jwt_1 = require("@nestjs/jwt");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const bcrypt = require("bcryptjs");
|
||||
const os = require("os");
|
||||
const typeorm_2 = require("typeorm");
|
||||
const config_entity_1 = require("../globalConfig/config.entity");
|
||||
const mailer_service_1 = require("../mailer/mailer.service");
|
||||
const redisCache_service_1 = require("../redisCache/redisCache.service");
|
||||
const user_service_1 = require("../user/user.service");
|
||||
const userBalance_service_1 = require("../userBalance/userBalance.service");
|
||||
const verification_service_1 = require("./../verification/verification.service");
|
||||
let AuthService = class AuthService {
|
||||
constructor(configEntity, userService, jwtService, mailerService, verificationService, userBalanceService, redisCacheService, globalConfigService) {
|
||||
this.configEntity = configEntity;
|
||||
this.userService = userService;
|
||||
this.jwtService = jwtService;
|
||||
this.mailerService = mailerService;
|
||||
this.verificationService = verificationService;
|
||||
this.userBalanceService = userBalanceService;
|
||||
this.redisCacheService = redisCacheService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
}
|
||||
async onModuleInit() {
|
||||
this.getIp();
|
||||
}
|
||||
async register(body, req) {
|
||||
const { password, contact, code } = body;
|
||||
let email = '', phone = '';
|
||||
const isEmail = /\S+@\S+\.\S+/.test(contact);
|
||||
const isPhone = /^\d{10,}$/.test(contact);
|
||||
common_1.Logger.debug(`Contact: ${contact}, isEmail: ${isEmail}, isPhone: ${isPhone}`);
|
||||
let username = (0, utils_1.createRandomUid)();
|
||||
while (true) {
|
||||
const usernameTaken = await this.userService.verifyUserRegister({
|
||||
username,
|
||||
});
|
||||
common_1.Logger.debug(`Checking if username ${username} is taken: ${usernameTaken}`);
|
||||
if (usernameTaken) {
|
||||
break;
|
||||
}
|
||||
username = (0, utils_1.createRandomUid)();
|
||||
}
|
||||
if (isEmail) {
|
||||
email = contact;
|
||||
const isAvailable = await this.userService.verifyUserRegister({
|
||||
username,
|
||||
email,
|
||||
});
|
||||
common_1.Logger.debug(`Email ${email} is available: ${isAvailable}`);
|
||||
if (!isAvailable) {
|
||||
throw new common_1.HttpException('当前邮箱已注册,请勿重复注册!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
else if (isPhone) {
|
||||
phone = contact;
|
||||
const isAvailable = await this.userService.verifyUserRegister({
|
||||
username,
|
||||
phone,
|
||||
});
|
||||
common_1.Logger.debug(`Phone ${phone} is available: ${isAvailable}`);
|
||||
if (!isAvailable) {
|
||||
throw new common_1.HttpException('当前手机号已注册,请勿重复注册!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new common_1.HttpException('请提供有效的邮箱地址或手机号码。', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const noVerifyRegister = await this.globalConfigService.getConfigs([
|
||||
'noVerifyRegister',
|
||||
]);
|
||||
common_1.Logger.debug(`noVerifyRegister: ${noVerifyRegister}`);
|
||||
if (noVerifyRegister !== '1') {
|
||||
const nameSpace = await this.globalConfigService.getNamespace();
|
||||
const key = `${nameSpace}:CODE:${contact}`;
|
||||
const redisCode = await this.redisCacheService.get({ key });
|
||||
common_1.Logger.debug(`Retrieved redisCode for ${contact}: ${redisCode}`);
|
||||
if (code === '') {
|
||||
throw new common_1.HttpException('请输入验证码', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (!redisCode) {
|
||||
common_1.Logger.log(`验证码过期: ${contact}`, 'authService');
|
||||
throw new common_1.HttpException('验证码已过期,请重新发送!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (code !== redisCode) {
|
||||
common_1.Logger.log(`验证码错误: ${contact} 输入的验证码: ${code}, 期望的验证码: ${redisCode}`, 'authService');
|
||||
throw new common_1.HttpException('验证码填写错误,请重新输入!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
let newUser;
|
||||
if (isEmail) {
|
||||
newUser = {
|
||||
username,
|
||||
password,
|
||||
email: contact,
|
||||
status: user_constant_1.UserStatusEnum.ACTIVE,
|
||||
};
|
||||
}
|
||||
else {
|
||||
const email = `${(0, utils_1.createRandomUid)()}@aiweb.com`;
|
||||
newUser = {
|
||||
username,
|
||||
password,
|
||||
email,
|
||||
phone: contact,
|
||||
status: user_constant_1.UserStatusEnum.ACTIVE,
|
||||
};
|
||||
}
|
||||
common_1.Logger.debug('获取默认用户头像...');
|
||||
const userDefautlAvatar = await this.globalConfigService.getConfigs([
|
||||
'userDefautlAvatar',
|
||||
]);
|
||||
common_1.Logger.debug(`使用默认用户头像: ${userDefautlAvatar}`);
|
||||
newUser.avatar = userDefautlAvatar;
|
||||
common_1.Logger.debug('加密用户密码...');
|
||||
const hashedPassword = bcrypt.hashSync(password, 10);
|
||||
newUser.password = hashedPassword;
|
||||
common_1.Logger.debug('保存新用户到数据库...');
|
||||
const u = await this.userService.createUser(newUser);
|
||||
common_1.Logger.debug(`用户创建成功,用户ID: ${u.id}`);
|
||||
await this.userBalanceService.addBalanceToNewUser(u.id);
|
||||
common_1.Logger.debug('完成新用户余额处理');
|
||||
return { success: true, message: '注册成功' };
|
||||
}
|
||||
async login(user, req) {
|
||||
console.log(`开始用户登录流程,用户名: ${user.username}`);
|
||||
const u = await this.userService.verifyUserCredentials(user);
|
||||
if (!u) {
|
||||
console.error(`登录失败: 用户凭证无效 - 用户名: ${user.username}`);
|
||||
throw new common_1.HttpException('登录失败,用户凭证无效。', common_1.HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
const { username, id, email, role, openId, client, phone } = u;
|
||||
console.log(`用户凭证验证成功,用户ID: ${id}, 用户名: ${username}`);
|
||||
const ip = (0, utils_1.getClientIp)(req);
|
||||
await this.userService.savaLoginIp(id, ip);
|
||||
console.log(`保存登录IP: ${ip} - 用户ID: ${id}`);
|
||||
const token = await this.jwtService.sign({
|
||||
username,
|
||||
id,
|
||||
email,
|
||||
role,
|
||||
openId,
|
||||
client,
|
||||
phone,
|
||||
});
|
||||
console.log(`JWT令牌生成成功 - 用户ID: ${id}`);
|
||||
await this.redisCacheService.saveToken(id, token);
|
||||
console.log(`令牌已保存到Redis - 用户ID: ${id}`);
|
||||
return token;
|
||||
}
|
||||
async loginWithCaptcha(body, req) {
|
||||
const { contact, code } = body;
|
||||
let email = '', phone = '';
|
||||
const isEmail = /\S+@\S+\.\S+/.test(contact);
|
||||
const isPhone = /^\d{10,}$/.test(contact);
|
||||
if (isEmail) {
|
||||
email = contact;
|
||||
}
|
||||
else if (isPhone) {
|
||||
phone = contact;
|
||||
}
|
||||
else {
|
||||
throw new common_1.HttpException('请提供有效的邮箱地址或手机号码。', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const isAvailable = await this.userService.verifyUserRegister({
|
||||
email,
|
||||
phone,
|
||||
});
|
||||
const nameSpace = await this.globalConfigService.getNamespace();
|
||||
const key = `${nameSpace}:CODE:${contact}`;
|
||||
const redisCode = await this.redisCacheService.get({ key });
|
||||
if (!redisCode) {
|
||||
common_1.Logger.log(`验证码过期: ${contact}`, 'authService');
|
||||
throw new common_1.HttpException('验证码已过期,请重新发送!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (code !== redisCode) {
|
||||
common_1.Logger.log(`验证码错误: ${contact} 输入的验证码: ${code}, 期望的验证码: ${redisCode}`, 'authService');
|
||||
throw new common_1.HttpException('验证码填写错误,请重新输入!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
let u;
|
||||
if (isAvailable) {
|
||||
u = await this.userService.createUserFromContact({ email, phone });
|
||||
}
|
||||
else {
|
||||
u = await this.userService.getUserByContact({ email, phone });
|
||||
}
|
||||
if (!u) {
|
||||
throw new common_1.HttpException('登录失败,用户凭证无效。', common_1.HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
const { username, id, role, openId, client } = u;
|
||||
console.log(`用户凭证验证成功,用户ID: ${id}, 用户名: ${username}`);
|
||||
const ip = (0, utils_1.getClientIp)(req);
|
||||
await this.userService.savaLoginIp(id, ip);
|
||||
console.log(`保存登录IP: ${ip} - 用户ID: ${id}`);
|
||||
const token = await this.jwtService.sign({
|
||||
username,
|
||||
id,
|
||||
email,
|
||||
role,
|
||||
openId,
|
||||
client,
|
||||
phone,
|
||||
});
|
||||
console.log(`JWT令牌生成成功 - 用户ID: ${id}`);
|
||||
await this.redisCacheService.saveToken(id, token);
|
||||
console.log(`令牌已保存到Redis - 用户ID: ${id}`);
|
||||
return token;
|
||||
}
|
||||
async loginByOpenId(user, req) {
|
||||
const { status } = user;
|
||||
if (status !== user_constant_1.UserStatusEnum.ACTIVE) {
|
||||
throw new common_1.HttpException(user_constant_1.UserStatusErrMsg[status], common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const { username, id, email, role, openId, client } = user;
|
||||
const ip = (0, utils_1.getClientIp)(req);
|
||||
await this.userService.savaLoginIp(id, ip);
|
||||
const token = await this.jwtService.sign({
|
||||
username,
|
||||
id,
|
||||
email,
|
||||
role,
|
||||
openId,
|
||||
client,
|
||||
});
|
||||
await this.redisCacheService.saveToken(id, token);
|
||||
return token;
|
||||
}
|
||||
async getInfo(req) {
|
||||
const { id } = req.user;
|
||||
return await this.userService.getUserInfo(id);
|
||||
}
|
||||
async updatePassword(req, body) {
|
||||
const { id, client, role } = req.user;
|
||||
if (client && Number(client) > 0) {
|
||||
throw new common_1.HttpException('无权此操作、请联系管理员!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (role === 'admin') {
|
||||
throw new common_1.HttpException('非法操作、请联系管理员!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
this.userService.updateUserPassword(id, body.password);
|
||||
return '密码修改成功';
|
||||
}
|
||||
async updatePassByOther(req, body) {
|
||||
const { id, client } = req.user;
|
||||
if (!client) {
|
||||
throw new common_1.HttpException('无权此操作!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
this.userService.updateUserPassword(id, body.password);
|
||||
return '密码修改成功';
|
||||
}
|
||||
getIp() {
|
||||
let ipAddress;
|
||||
const interfaces = os.networkInterfaces();
|
||||
Object.keys(interfaces).forEach((interfaceName) => {
|
||||
const interfaceInfo = interfaces[interfaceName];
|
||||
for (let i = 0; i < interfaceInfo.length; i++) {
|
||||
const alias = interfaceInfo[i];
|
||||
if (alias.family === 'IPv4' &&
|
||||
alias.address !== '127.0.0.1' &&
|
||||
!alias.internal) {
|
||||
ipAddress = alias.address;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
this.ipAddress = ipAddress;
|
||||
}
|
||||
async sendCode(body) {
|
||||
const { contact, isLogin } = body;
|
||||
let email = '', phone = '';
|
||||
const code = (0, utils_1.createRandomCode)();
|
||||
const isEmail = /\S+@\S+\.\S+/.test(contact);
|
||||
const isPhone = /^\d{10,}$/.test(contact);
|
||||
if (!isEmail && !isPhone) {
|
||||
throw new common_1.HttpException('请提供有效的邮箱地址或手机号码。', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (!isLogin) {
|
||||
if (isEmail) {
|
||||
email = contact;
|
||||
const isAvailable = await this.userService.verifyUserRegister({
|
||||
email,
|
||||
});
|
||||
if (!isAvailable) {
|
||||
throw new common_1.HttpException('当前邮箱已注册,请勿重复注册!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
else if (isPhone) {
|
||||
phone = contact;
|
||||
const isAvailable = await this.userService.verifyUserRegister({
|
||||
phone,
|
||||
});
|
||||
if (!isAvailable) {
|
||||
throw new common_1.HttpException('当前手机号已注册,请勿重复注册!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
const nameSpace = await this.globalConfigService.getNamespace();
|
||||
const key = `${nameSpace}:CODE:${contact}`;
|
||||
const ttl = await this.redisCacheService.ttl(key);
|
||||
if (ttl && ttl > 0 && isPhone) {
|
||||
throw new common_1.HttpException(`${ttl}秒内不得重复发送验证码!`, common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (isEmail) {
|
||||
const existingCode = await this.redisCacheService.get({ key });
|
||||
if (existingCode) {
|
||||
await this.mailerService.sendMail({
|
||||
to: email,
|
||||
context: {
|
||||
code: existingCode,
|
||||
},
|
||||
});
|
||||
return `验证码发送成功、请填写验证码完成注册!`;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
await this.mailerService.sendMail({
|
||||
to: email,
|
||||
context: {
|
||||
code: code,
|
||||
},
|
||||
});
|
||||
console.log('邮件发送成功');
|
||||
}
|
||||
catch (error) {
|
||||
console.error('邮件发送失败', error);
|
||||
}
|
||||
await this.redisCacheService.set({ key, val: code }, 10 * 60);
|
||||
return `验证码发送成功、请填写验证码完成注册!`;
|
||||
}
|
||||
}
|
||||
else if (isPhone) {
|
||||
const messageInfo = { phone, code };
|
||||
await this.verificationService.sendPhoneCode(messageInfo);
|
||||
await this.redisCacheService.set({ key, val: code }, 10 * 60);
|
||||
return `验证码发送成功、请填写验证码完成注册!`;
|
||||
}
|
||||
}
|
||||
async sendPhoneCode(body) {
|
||||
const { phone, isLogin } = body;
|
||||
const code = (0, utils_1.createRandomCode)();
|
||||
const isPhone = /^\d{10,}$/.test(phone);
|
||||
if (!isPhone) {
|
||||
throw new common_1.HttpException('请提供有效的邮箱地址或手机号码。', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (isLogin) {
|
||||
if (isPhone) {
|
||||
const isAvailable = await this.userService.verifyUserRegister({
|
||||
phone,
|
||||
});
|
||||
if (!isAvailable) {
|
||||
throw new common_1.HttpException('当前手机号已注册,请勿重复注册!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
const nameSpace = await this.globalConfigService.getNamespace();
|
||||
const key = `${nameSpace}:CODE:${phone}`;
|
||||
const ttl = await this.redisCacheService.ttl(key);
|
||||
if (ttl && ttl > 0 && isPhone) {
|
||||
throw new common_1.HttpException(`${ttl}秒内不得重复发送验证码!`, common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const messageInfo = { phone, code };
|
||||
await this.redisCacheService.set({ key, val: code }, 10 * 60);
|
||||
await this.verificationService.sendPhoneCode(messageInfo);
|
||||
return `验证码发送成功、请填写验证码完成认证!`;
|
||||
}
|
||||
createTokenFromFingerprint(fingerprint) {
|
||||
const token = this.jwtService.sign({
|
||||
username: `游客${fingerprint}`,
|
||||
id: fingerprint,
|
||||
email: `${fingerprint}@visitor.com`,
|
||||
role: 'visitor',
|
||||
openId: null,
|
||||
client: null,
|
||||
});
|
||||
return token;
|
||||
}
|
||||
async verifyIdentity(req, body) {
|
||||
common_1.Logger.debug('开始实名认证流程');
|
||||
const { name, idCard } = body;
|
||||
const { id } = req.user;
|
||||
try {
|
||||
const result = await this.verificationService.verifyIdentity(body);
|
||||
common_1.Logger.debug(`实名认证结果: ${result}`);
|
||||
if (!result) {
|
||||
throw new common_1.HttpException('身份验证错误,请检查实名信息', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
await this.userService.saveRealNameInfo(id, name, idCard);
|
||||
return '认证成功';
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error('验证过程出现错误', error);
|
||||
throw new common_1.HttpException('认证失败,请检查相关信息', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
async verifyPhoneIdentity(req, body) {
|
||||
common_1.Logger.debug('开始手机号认证流程');
|
||||
const { phone, username, password, code } = body;
|
||||
const { id } = req.user;
|
||||
const nameSpace = this.globalConfigService.getNamespace();
|
||||
const key = `${nameSpace}:CODE:${phone}`;
|
||||
const redisCode = await this.redisCacheService.get({ key });
|
||||
common_1.Logger.debug(`Retrieved redisCode for ${phone}: ${redisCode}`);
|
||||
if (code === '') {
|
||||
throw new common_1.HttpException('请输入验证码', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (!redisCode) {
|
||||
common_1.Logger.log(`验证码过期: ${phone}`, 'authService');
|
||||
throw new common_1.HttpException('验证码已过期,请重新发送!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (code !== redisCode) {
|
||||
common_1.Logger.log(`验证码错误: ${phone} 输入的验证码: ${code}, 期望的验证码: ${redisCode}`, 'authService');
|
||||
throw new common_1.HttpException('验证码填写错误,请重新输入!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (username) {
|
||||
const usernameTaken = await this.userService.isUsernameTaken(body.username, id);
|
||||
if (usernameTaken) {
|
||||
throw new common_1.HttpException('用户名已存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
try {
|
||||
await this.userService.updateUserPhone(id, phone, username, password);
|
||||
return '认证成功';
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error('验证过程出现错误', error);
|
||||
throw new common_1.HttpException('身份验证错误,请检查相关信息', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
};
|
||||
AuthService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__param(0, (0, typeorm_1.InjectRepository)(config_entity_1.ConfigEntity)),
|
||||
__metadata("design:paramtypes", [typeorm_2.Repository,
|
||||
user_service_1.UserService,
|
||||
jwt_1.JwtService,
|
||||
mailer_service_1.MailerService,
|
||||
verification_service_1.VerificationService,
|
||||
userBalance_service_1.UserBalanceService,
|
||||
redisCache_service_1.RedisCacheService,
|
||||
globalConfig_service_1.GlobalConfigService])
|
||||
], AuthService);
|
||||
exports.AuthService = AuthService;
|
||||
32
AIWebQuickDeploy/dist/modules/auth/dto/adminLogin.dto.js
vendored
Normal file
32
AIWebQuickDeploy/dist/modules/auth/dto/adminLogin.dto.js
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
"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.AdminLoginDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class AdminLoginDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'super', description: '邮箱' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户名不能为空!' }),
|
||||
(0, class_validator_1.MinLength)(2, { message: '用户名最短是两位数!' }),
|
||||
(0, class_validator_1.MaxLength)(30, { message: '用户名最长不得超过30位!' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], AdminLoginDto.prototype, "username", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '999999', description: '密码' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户密码不能为空!' }),
|
||||
(0, class_validator_1.MinLength)(6, { message: '用户密码最低需要大于6位数!' }),
|
||||
(0, class_validator_1.MaxLength)(30, { message: '用户密码最长不能超过30位数!' }),
|
||||
__metadata("design:type", String)
|
||||
], AdminLoginDto.prototype, "password", void 0);
|
||||
exports.AdminLoginDto = AdminLoginDto;
|
||||
37
AIWebQuickDeploy/dist/modules/auth/dto/authLogin.dto.js
vendored
Normal file
37
AIWebQuickDeploy/dist/modules/auth/dto/authLogin.dto.js
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
"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.UserLoginDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class UserLoginDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'super', description: '邮箱' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户名不能为空!' }),
|
||||
(0, class_validator_1.MinLength)(2, { message: '用户名最短是两位数!' }),
|
||||
(0, class_validator_1.MaxLength)(30, { message: '用户名最长不得超过30位!' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UserLoginDto.prototype, "username", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '用户ID' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], UserLoginDto.prototype, "uid", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '999999', description: '密码' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户密码不能为空!' }),
|
||||
(0, class_validator_1.MinLength)(6, { message: '用户密码最低需要大于6位数!' }),
|
||||
(0, class_validator_1.MaxLength)(30, { message: '用户密码最长不能超过30位数!' }),
|
||||
__metadata("design:type", String)
|
||||
], UserLoginDto.prototype, "password", void 0);
|
||||
exports.UserLoginDto = UserLoginDto;
|
||||
50
AIWebQuickDeploy/dist/modules/auth/dto/authRegister.dto.js
vendored
Normal file
50
AIWebQuickDeploy/dist/modules/auth/dto/authRegister.dto.js
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
"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.UserRegisterDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class UserRegisterDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'cooper', description: '用户名称' }),
|
||||
__metadata("design:type", String)
|
||||
], UserRegisterDto.prototype, "username", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '123456', description: '用户密码' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户密码不能为空' }),
|
||||
(0, class_validator_1.MinLength)(6, { message: '用户密码最低需要大于6位数!' }),
|
||||
(0, class_validator_1.MaxLength)(30, { message: '用户密码最长不能超过30位数!' }),
|
||||
__metadata("design:type", String)
|
||||
], UserRegisterDto.prototype, "password", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'ai@aiweb.com', description: '用户邮箱' }),
|
||||
__metadata("design:type", String)
|
||||
], UserRegisterDto.prototype, "email", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: '',
|
||||
description: '用户头像',
|
||||
required: false,
|
||||
}),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UserRegisterDto.prototype, "avatar", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: 'default',
|
||||
description: '用户注册来源',
|
||||
required: false,
|
||||
}),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UserRegisterDto.prototype, "client", void 0);
|
||||
exports.UserRegisterDto = UserRegisterDto;
|
||||
30
AIWebQuickDeploy/dist/modules/auth/dto/loginByPhone.dt.js
vendored
Normal file
30
AIWebQuickDeploy/dist/modules/auth/dto/loginByPhone.dt.js
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
"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.LoginByPhoneDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class LoginByPhoneDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '19999999', description: '手机号' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '手机号不能为空!' }),
|
||||
(0, class_validator_1.IsPhoneNumber)('CN', { message: '手机号格式不正确!' }),
|
||||
__metadata("design:type", String)
|
||||
], LoginByPhoneDto.prototype, "phone", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '999999', description: '密码' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户密码不能为空!' }),
|
||||
(0, class_validator_1.MinLength)(6, { message: '用户密码最低需要大于6位数!' }),
|
||||
(0, class_validator_1.MaxLength)(30, { message: '用户密码最长不能超过30位数!' }),
|
||||
__metadata("design:type", String)
|
||||
], LoginByPhoneDto.prototype, "password", void 0);
|
||||
exports.LoginByPhoneDto = LoginByPhoneDto;
|
||||
34
AIWebQuickDeploy/dist/modules/auth/dto/sendPhoneCode.dto.js
vendored
Normal file
34
AIWebQuickDeploy/dist/modules/auth/dto/sendPhoneCode.dto.js
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
"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.SendPhoneCodeDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class SendPhoneCodeDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '199999999', description: '手机号' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '手机号不能为空' }),
|
||||
(0, class_validator_1.MinLength)(11, { message: '手机号长度为11位' }),
|
||||
(0, class_validator_1.MaxLength)(11, { message: '手机号长度为11位!' }),
|
||||
__metadata("design:type", String)
|
||||
], SendPhoneCodeDto.prototype, "phone", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '2b4i1b4', description: '图形验证码KEY' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '验证码KEY不能为空' }),
|
||||
__metadata("design:type", String)
|
||||
], SendPhoneCodeDto.prototype, "captchaId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '1g4d', description: '图形验证码' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '验证码不能为空' }),
|
||||
__metadata("design:type", String)
|
||||
], SendPhoneCodeDto.prototype, "captchaCode", void 0);
|
||||
exports.SendPhoneCodeDto = SendPhoneCodeDto;
|
||||
24
AIWebQuickDeploy/dist/modules/auth/dto/updatePassByOther.dto.js
vendored
Normal file
24
AIWebQuickDeploy/dist/modules/auth/dto/updatePassByOther.dto.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;
|
||||
};
|
||||
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.UpdatePassByOtherDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class UpdatePassByOtherDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '666666', description: '三方用户更新新密码' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户密码不能为空!' }),
|
||||
(0, class_validator_1.MinLength)(6, { message: '用户密码最低需要大于6位数!' }),
|
||||
(0, class_validator_1.MaxLength)(30, { message: '用户密码最长不能超过30位数!' }),
|
||||
__metadata("design:type", String)
|
||||
], UpdatePassByOtherDto.prototype, "password", void 0);
|
||||
exports.UpdatePassByOtherDto = UpdatePassByOtherDto;
|
||||
24
AIWebQuickDeploy/dist/modules/auth/dto/updatePassword.dto.js
vendored
Normal file
24
AIWebQuickDeploy/dist/modules/auth/dto/updatePassword.dto.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;
|
||||
};
|
||||
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.UpdatePasswordDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class UpdatePasswordDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '666666', description: '用户更新新密码' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户密码不能为空!' }),
|
||||
(0, class_validator_1.MinLength)(6, { message: '用户密码最低需要大于6位数!' }),
|
||||
(0, class_validator_1.MaxLength)(30, { message: '用户密码最长不能超过30位数!' }),
|
||||
__metadata("design:type", String)
|
||||
], UpdatePasswordDto.prototype, "password", void 0);
|
||||
exports.UpdatePasswordDto = UpdatePasswordDto;
|
||||
42
AIWebQuickDeploy/dist/modules/auth/dto/userRegisterByPhone.dto.js
vendored
Normal file
42
AIWebQuickDeploy/dist/modules/auth/dto/userRegisterByPhone.dto.js
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
"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.UserRegisterByPhoneDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class UserRegisterByPhoneDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'cooper', description: '用户名称' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户名不能为空!' }),
|
||||
(0, class_validator_1.MinLength)(2, { message: '用户名最低需要大于2位数!' }),
|
||||
(0, class_validator_1.MaxLength)(12, { message: '用户名不得超过12位!' }),
|
||||
__metadata("design:type", String)
|
||||
], UserRegisterByPhoneDto.prototype, "username", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '123456', description: '用户密码' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户密码不能为空' }),
|
||||
(0, class_validator_1.MinLength)(6, { message: '用户密码最低需要大于6位数!' }),
|
||||
(0, class_validator_1.MaxLength)(30, { message: '用户密码最长不能超过30位数!' }),
|
||||
__metadata("design:type", String)
|
||||
], UserRegisterByPhoneDto.prototype, "password", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '19999999999', description: '用户手机号码' }),
|
||||
(0, class_validator_1.IsPhoneNumber)('CN', { message: '手机号码格式不正确!' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '手机号码不能为空!' }),
|
||||
__metadata("design:type", String)
|
||||
], UserRegisterByPhoneDto.prototype, "phone", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '152546', description: '手机验证码' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '手机验证码不能为空!' }),
|
||||
__metadata("design:type", String)
|
||||
], UserRegisterByPhoneDto.prototype, "phoneCode", void 0);
|
||||
exports.UserRegisterByPhoneDto = UserRegisterByPhoneDto;
|
||||
87
AIWebQuickDeploy/dist/modules/autoreply/autoreply.controller.js
vendored
Normal file
87
AIWebQuickDeploy/dist/modules/autoreply/autoreply.controller.js
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
"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.AutoreplyController = void 0;
|
||||
const adminAuth_guard_1 = require("../../common/auth/adminAuth.guard");
|
||||
const superAuth_guard_1 = require("../../common/auth/superAuth.guard");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const autoreply_service_1 = require("./autoreply.service");
|
||||
const addAutoReply_dto_1 = require("./dto/addAutoReply.dto");
|
||||
const delBadWords_dto_1 = require("./dto/delBadWords.dto");
|
||||
const queryAutoReply_dto_1 = require("./dto/queryAutoReply.dto");
|
||||
const updateAutoReply_dto_1 = require("./dto/updateAutoReply.dto");
|
||||
let AutoreplyController = class AutoreplyController {
|
||||
constructor(autoreplyService) {
|
||||
this.autoreplyService = autoreplyService;
|
||||
}
|
||||
queryAutoreply(query) {
|
||||
return this.autoreplyService.queryAutoreply(query);
|
||||
}
|
||||
addAutoreply(body) {
|
||||
return this.autoreplyService.addAutoreply(body);
|
||||
}
|
||||
updateAutoreply(body) {
|
||||
return this.autoreplyService.updateAutoreply(body);
|
||||
}
|
||||
delAutoreply(body) {
|
||||
return this.autoreplyService.delAutoreply(body);
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Get)('query'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询自动回复' }),
|
||||
(0, common_1.UseGuards)(adminAuth_guard_1.AdminAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [queryAutoReply_dto_1.QueryAutoReplyDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AutoreplyController.prototype, "queryAutoreply", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('add'),
|
||||
(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", [addAutoReply_dto_1.AddAutoReplyDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AutoreplyController.prototype, "addAutoreply", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('update'),
|
||||
(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", [updateAutoReply_dto_1.UpdateAutoReplyDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AutoreplyController.prototype, "updateAutoreply", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('del'),
|
||||
(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", [delBadWords_dto_1.DelAutoReplyDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AutoreplyController.prototype, "delAutoreply", null);
|
||||
AutoreplyController = __decorate([
|
||||
(0, swagger_1.ApiTags)('autoreply'),
|
||||
(0, common_1.Controller)('autoreply'),
|
||||
__metadata("design:paramtypes", [autoreply_service_1.AutoreplyService])
|
||||
], AutoreplyController);
|
||||
exports.AutoreplyController = AutoreplyController;
|
||||
36
AIWebQuickDeploy/dist/modules/autoreply/autoreply.entity.js
vendored
Normal file
36
AIWebQuickDeploy/dist/modules/autoreply/autoreply.entity.js
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
"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.AutoReplyEntity = void 0;
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
const typeorm_1 = require("typeorm");
|
||||
let AutoReplyEntity = class AutoReplyEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '提问的问题', type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], AutoReplyEntity.prototype, "prompt", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '定义的答案', type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], AutoReplyEntity.prototype, "answer", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ default: 1, comment: '是否开启AI回复,0:关闭 1:启用' }),
|
||||
__metadata("design:type", Number)
|
||||
], AutoReplyEntity.prototype, "isAIReplyEnabled", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ default: 1, comment: '启用当前自动回复状态, 0:关闭 1:启用' }),
|
||||
__metadata("design:type", Number)
|
||||
], AutoReplyEntity.prototype, "status", void 0);
|
||||
AutoReplyEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'auto_reply' })
|
||||
], AutoReplyEntity);
|
||||
exports.AutoReplyEntity = AutoReplyEntity;
|
||||
26
AIWebQuickDeploy/dist/modules/autoreply/autoreply.module.js
vendored
Normal file
26
AIWebQuickDeploy/dist/modules/autoreply/autoreply.module.js
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
"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.AutoreplyModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const autoreply_controller_1 = require("./autoreply.controller");
|
||||
const autoreply_entity_1 = require("./autoreply.entity");
|
||||
const autoreply_service_1 = require("./autoreply.service");
|
||||
let AutoreplyModule = class AutoreplyModule {
|
||||
};
|
||||
AutoreplyModule = __decorate([
|
||||
(0, common_1.Global)(),
|
||||
(0, common_1.Module)({
|
||||
imports: [typeorm_1.TypeOrmModule.forFeature([autoreply_entity_1.AutoReplyEntity])],
|
||||
controllers: [autoreply_controller_1.AutoreplyController],
|
||||
providers: [autoreply_service_1.AutoreplyService],
|
||||
exports: [autoreply_service_1.AutoreplyService],
|
||||
})
|
||||
], AutoreplyModule);
|
||||
exports.AutoreplyModule = AutoreplyModule;
|
||||
126
AIWebQuickDeploy/dist/modules/autoreply/autoreply.service.js
vendored
Normal file
126
AIWebQuickDeploy/dist/modules/autoreply/autoreply.service.js
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
"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.AutoreplyService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const typeorm_2 = require("typeorm");
|
||||
const autoreply_entity_1 = require("./autoreply.entity");
|
||||
let AutoreplyService = class AutoreplyService {
|
||||
constructor(autoReplyEntity) {
|
||||
this.autoReplyEntity = autoReplyEntity;
|
||||
this.autoReplyKes = [];
|
||||
this.autoReplyMap = {};
|
||||
this.autoReplyFuzzyMatch = true;
|
||||
}
|
||||
async onModuleInit() {
|
||||
await this.loadAutoReplyList();
|
||||
}
|
||||
async loadAutoReplyList() {
|
||||
const res = await this.autoReplyEntity.find({
|
||||
where: { status: 1 },
|
||||
select: ['prompt', 'answer', 'isAIReplyEnabled'],
|
||||
});
|
||||
this.autoReplyMap = {};
|
||||
this.autoReplyKes = [];
|
||||
res.forEach((t) => {
|
||||
this.autoReplyMap[t.prompt] = {
|
||||
answer: t.answer,
|
||||
isAIReplyEnabled: t.isAIReplyEnabled,
|
||||
};
|
||||
const keywords = t.prompt.split(' ').map((k) => k.trim());
|
||||
this.autoReplyKes.push({ prompt: t.prompt, keywords });
|
||||
});
|
||||
}
|
||||
async checkAutoReply(prompt) {
|
||||
let answers = [];
|
||||
let isAIReplyEnabled = 0;
|
||||
const seenGroups = new Set();
|
||||
if (this.autoReplyFuzzyMatch) {
|
||||
for (const item of this.autoReplyKes) {
|
||||
if (item.keywords.some((keyword) => prompt.includes(keyword))) {
|
||||
if (!seenGroups.has(item.prompt)) {
|
||||
answers.push(this.autoReplyMap[item.prompt].answer);
|
||||
seenGroups.add(item.prompt);
|
||||
if (this.autoReplyMap[item.prompt].isAIReplyEnabled === 1) {
|
||||
isAIReplyEnabled = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const matches = this.autoReplyKes.filter((item) => item.prompt === prompt);
|
||||
for (const match of matches) {
|
||||
if (!seenGroups.has(match.prompt)) {
|
||||
answers.push(this.autoReplyMap[match.prompt].answer);
|
||||
seenGroups.add(match.prompt);
|
||||
if (this.autoReplyMap[match.prompt].isAIReplyEnabled === 1) {
|
||||
isAIReplyEnabled = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
answer: answers.join('\n'),
|
||||
isAIReplyEnabled,
|
||||
};
|
||||
}
|
||||
async queryAutoreply(query) {
|
||||
const { page = 1, size = 10, prompt, status } = query;
|
||||
const where = {};
|
||||
[0, 1, '0', '1'].includes(status) && (where.status = status);
|
||||
prompt && (where.prompt = (0, typeorm_2.Like)(`%${prompt}%`));
|
||||
const [rows, count] = await this.autoReplyEntity.findAndCount({
|
||||
where,
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
order: { id: 'DESC' },
|
||||
});
|
||||
return { rows, count };
|
||||
}
|
||||
async addAutoreply(body) {
|
||||
await this.autoReplyEntity.save(body);
|
||||
await this.loadAutoReplyList();
|
||||
return '添加问题成功!';
|
||||
}
|
||||
async updateAutoreply(body) {
|
||||
const { id } = body;
|
||||
const res = await this.autoReplyEntity.update({ id }, body);
|
||||
if (res.affected > 0) {
|
||||
await this.loadAutoReplyList();
|
||||
return '更新问题成功';
|
||||
}
|
||||
throw new common_1.HttpException('更新失败', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
async delAutoreply(body) {
|
||||
const { id } = body;
|
||||
const z = await this.autoReplyEntity.findOne({ where: { id } });
|
||||
if (!z) {
|
||||
throw new common_1.HttpException('该问题不存在,请检查您的提交信息', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const res = await this.autoReplyEntity.delete({ id });
|
||||
if (res.affected > 0) {
|
||||
await this.loadAutoReplyList();
|
||||
return '删除问题成功';
|
||||
}
|
||||
throw new common_1.HttpException('删除失败', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
};
|
||||
AutoreplyService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__param(0, (0, typeorm_1.InjectRepository)(autoreply_entity_1.AutoReplyEntity)),
|
||||
__metadata("design:paramtypes", [typeorm_2.Repository])
|
||||
], AutoreplyService);
|
||||
exports.AutoreplyService = AutoreplyService;
|
||||
28
AIWebQuickDeploy/dist/modules/autoreply/dto/addAutoReply.dto.js
vendored
Normal file
28
AIWebQuickDeploy/dist/modules/autoreply/dto/addAutoReply.dto.js
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
"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.AddAutoReplyDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class AddAutoReplyDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '你是谁', description: '提问的问题', required: true }),
|
||||
__metadata("design:type", String)
|
||||
], AddAutoReplyDto.prototype, "prompt", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: '我是AIWeb提供的Ai服务机器人',
|
||||
description: '回答的答案',
|
||||
required: true,
|
||||
}),
|
||||
__metadata("design:type", String)
|
||||
], AddAutoReplyDto.prototype, "answer", void 0);
|
||||
exports.AddAutoReplyDto = AddAutoReplyDto;
|
||||
20
AIWebQuickDeploy/dist/modules/autoreply/dto/delBadWords.dto.js
vendored
Normal file
20
AIWebQuickDeploy/dist/modules/autoreply/dto/delBadWords.dto.js
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
"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.DelAutoReplyDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class DelAutoReplyDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '自动回复id', required: true }),
|
||||
__metadata("design:type", Number)
|
||||
], DelAutoReplyDto.prototype, "id", void 0);
|
||||
exports.DelAutoReplyDto = DelAutoReplyDto;
|
||||
37
AIWebQuickDeploy/dist/modules/autoreply/dto/queryAutoReply.dto.js
vendored
Normal file
37
AIWebQuickDeploy/dist/modules/autoreply/dto/queryAutoReply.dto.js
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
"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.QueryAutoReplyDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class QueryAutoReplyDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QueryAutoReplyDto.prototype, "page", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QueryAutoReplyDto.prototype, "size", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '你是谁', description: '提问问题', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QueryAutoReplyDto.prototype, "prompt", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '问题状态', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QueryAutoReplyDto.prototype, "status", void 0);
|
||||
exports.QueryAutoReplyDto = QueryAutoReplyDto;
|
||||
41
AIWebQuickDeploy/dist/modules/autoreply/dto/updateAutoReply.dto.js
vendored
Normal file
41
AIWebQuickDeploy/dist/modules/autoreply/dto/updateAutoReply.dto.js
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
"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.UpdateAutoReplyDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class UpdateAutoReplyDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '自动回复id', required: true }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], UpdateAutoReplyDto.prototype, "id", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '你可以干嘛', description: '问题', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateAutoReplyDto.prototype, "prompt", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: '我可以干很多事情.......',
|
||||
description: '答案',
|
||||
required: false,
|
||||
}),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateAutoReplyDto.prototype, "answer", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 0, description: '状态', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], UpdateAutoReplyDto.prototype, "status", void 0);
|
||||
exports.UpdateAutoReplyDto = UpdateAutoReplyDto;
|
||||
100
AIWebQuickDeploy/dist/modules/badWords/badWords.controller.js
vendored
Normal file
100
AIWebQuickDeploy/dist/modules/badWords/badWords.controller.js
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
"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.BadWordsController = void 0;
|
||||
const adminAuth_guard_1 = require("../../common/auth/adminAuth.guard");
|
||||
const superAuth_guard_1 = require("../../common/auth/superAuth.guard");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const badWords_service_1 = require("./badWords.service");
|
||||
const addBadWords_dto_1 = require("./dto/addBadWords.dto");
|
||||
const delBadWords_dto_1 = require("./dto/delBadWords.dto");
|
||||
const queryBadWords_dto_1 = require("./dto/queryBadWords.dto");
|
||||
const queryViolation_dto_1 = require("./dto/queryViolation.dto");
|
||||
const updateBadWords_dto_1 = require("./dto/updateBadWords.dto");
|
||||
let BadWordsController = class BadWordsController {
|
||||
constructor(badWordsService) {
|
||||
this.badWordsService = badWordsService;
|
||||
}
|
||||
queryBadWords(query) {
|
||||
return this.badWordsService.queryBadWords(query);
|
||||
}
|
||||
delBadWords(body) {
|
||||
return this.badWordsService.delBadWords(body);
|
||||
}
|
||||
updateBadWords(body) {
|
||||
return this.badWordsService.updateBadWords(body);
|
||||
}
|
||||
addBadWord(body) {
|
||||
return this.badWordsService.addBadWord(body);
|
||||
}
|
||||
violation(req, query) {
|
||||
return this.badWordsService.violation(req, query);
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Get)('query'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询所有敏感词' }),
|
||||
__param(0, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [queryBadWords_dto_1.QueryBadWordsDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], BadWordsController.prototype, "queryBadWords", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('del'),
|
||||
(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", [delBadWords_dto_1.DelBadWordsDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], BadWordsController.prototype, "delBadWords", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('update'),
|
||||
(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", [updateBadWords_dto_1.UpdateBadWordsDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], BadWordsController.prototype, "updateBadWords", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('add'),
|
||||
(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", [addBadWords_dto_1.AddBadWordDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], BadWordsController.prototype, "addBadWord", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('violation'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询违规记录' }),
|
||||
(0, common_1.UseGuards)(adminAuth_guard_1.AdminAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, queryViolation_dto_1.QueryViolationDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], BadWordsController.prototype, "violation", null);
|
||||
BadWordsController = __decorate([
|
||||
(0, swagger_1.ApiTags)('badWords'),
|
||||
(0, common_1.Controller)('badWords'),
|
||||
__metadata("design:paramtypes", [badWords_service_1.BadWordsService])
|
||||
], BadWordsController);
|
||||
exports.BadWordsController = BadWordsController;
|
||||
32
AIWebQuickDeploy/dist/modules/badWords/badWords.entity.js
vendored
Normal file
32
AIWebQuickDeploy/dist/modules/badWords/badWords.entity.js
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
"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.BadWordsEntity = void 0;
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
const typeorm_1 = require("typeorm");
|
||||
let BadWordsEntity = class BadWordsEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ length: 20, comment: '敏感词' }),
|
||||
__metadata("design:type", String)
|
||||
], BadWordsEntity.prototype, "word", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ default: 1, comment: '敏感词开启状态' }),
|
||||
__metadata("design:type", Number)
|
||||
], BadWordsEntity.prototype, "status", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ default: 0, comment: '敏感词触发次数' }),
|
||||
__metadata("design:type", Number)
|
||||
], BadWordsEntity.prototype, "count", void 0);
|
||||
BadWordsEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'bad_words' })
|
||||
], BadWordsEntity);
|
||||
exports.BadWordsEntity = BadWordsEntity;
|
||||
30
AIWebQuickDeploy/dist/modules/badWords/badWords.module.js
vendored
Normal file
30
AIWebQuickDeploy/dist/modules/badWords/badWords.module.js
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
"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.BadWordsModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const user_entity_1 = require("../user/user.entity");
|
||||
const badWords_controller_1 = require("./badWords.controller");
|
||||
const badWords_entity_1 = require("./badWords.entity");
|
||||
const badWords_service_1 = require("./badWords.service");
|
||||
const violationLog_entity_1 = require("./violationLog.entity");
|
||||
let BadWordsModule = class BadWordsModule {
|
||||
};
|
||||
BadWordsModule = __decorate([
|
||||
(0, common_1.Global)(),
|
||||
(0, common_1.Module)({
|
||||
imports: [
|
||||
typeorm_1.TypeOrmModule.forFeature([badWords_entity_1.BadWordsEntity, violationLog_entity_1.ViolationLogEntity, user_entity_1.UserEntity]),
|
||||
],
|
||||
providers: [badWords_service_1.BadWordsService],
|
||||
controllers: [badWords_controller_1.BadWordsController],
|
||||
exports: [badWords_service_1.BadWordsService],
|
||||
})
|
||||
], BadWordsModule);
|
||||
exports.BadWordsModule = BadWordsModule;
|
||||
208
AIWebQuickDeploy/dist/modules/badWords/badWords.service.js
vendored
Normal file
208
AIWebQuickDeploy/dist/modules/badWords/badWords.service.js
vendored
Normal file
@@ -0,0 +1,208 @@
|
||||
"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.BadWordsService = void 0;
|
||||
const utils_1 = require("../../common/utils");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const axios_1 = require("axios");
|
||||
const typeorm_2 = require("typeorm");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const user_entity_1 = require("../user/user.entity");
|
||||
const badWords_entity_1 = require("./badWords.entity");
|
||||
const violationLog_entity_1 = require("./violationLog.entity");
|
||||
let BadWordsService = class BadWordsService {
|
||||
constructor(badWordsEntity, violationLogEntity, userEntity, globalConfigService) {
|
||||
this.badWordsEntity = badWordsEntity;
|
||||
this.violationLogEntity = violationLogEntity;
|
||||
this.userEntity = userEntity;
|
||||
this.globalConfigService = globalConfigService;
|
||||
this.badWords = [];
|
||||
}
|
||||
async onModuleInit() {
|
||||
this.loadBadWords();
|
||||
}
|
||||
async customSensitiveWords(content, userId) {
|
||||
const triggeredWords = [];
|
||||
for (let i = 0; i < this.badWords.length; i++) {
|
||||
const word = this.badWords[i];
|
||||
if (content.includes(word)) {
|
||||
triggeredWords.push(word);
|
||||
}
|
||||
}
|
||||
if (triggeredWords.length) {
|
||||
await this.recordUserBadWords(userId, content, triggeredWords, ['自定义'], '自定义检测');
|
||||
}
|
||||
return triggeredWords;
|
||||
}
|
||||
async checkBadWords(content, userId) {
|
||||
const config = await this.globalConfigService.getSensitiveConfig();
|
||||
if (config) {
|
||||
await this.checkBadWordsByConfig(content, config, userId);
|
||||
}
|
||||
return await this.customSensitiveWords(content, userId);
|
||||
}
|
||||
async checkBadWordsByConfig(content, config, userId) {
|
||||
const { useType } = config;
|
||||
useType === 'baidu' &&
|
||||
(await this.baiduCheckBadWords(content, config.baiduTextAccessToken, userId));
|
||||
}
|
||||
extractContent(str) {
|
||||
const pattern = /存在(.*?)不合规/;
|
||||
const match = str.match(pattern);
|
||||
return match ? match[1] : '';
|
||||
}
|
||||
async baiduCheckBadWords(content, accessToken, userId) {
|
||||
if (!accessToken)
|
||||
return;
|
||||
const url = `https://aip.baidubce.com/rest/2.0/solution/v1/text_censor/v2/user_defined?access_token=${accessToken}}`;
|
||||
const headers = {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
Accept: 'application/json',
|
||||
};
|
||||
const response = await axios_1.default.post(url, { text: content }, { headers });
|
||||
const { conclusion, error_code, error_msg, conclusionType, data } = response.data;
|
||||
if (error_code) {
|
||||
console.log('百度文本检测出现错误、请查看配置信息: ', error_msg);
|
||||
}
|
||||
if (conclusionType !== 1) {
|
||||
const types = [
|
||||
...new Set(data.map((item) => this.extractContent(item.msg))),
|
||||
];
|
||||
await this.recordUserBadWords(userId, content, ['***'], types, '百度云检测');
|
||||
const tips = `您提交的信息中包含${types.join(',')}的内容、我们已对您的账户进行标记、请合规使用!`;
|
||||
throw new common_1.HttpException(tips, common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
formarTips(wordList) {
|
||||
const categorys = wordList.map((t) => t.category);
|
||||
const unSet = [...new Set(categorys)];
|
||||
return `您提交的内容中包含${unSet.join(',')}的信息、我们已对您账号进行标记、请合规使用!`;
|
||||
}
|
||||
async loadBadWords() {
|
||||
const data = await this.badWordsEntity.find({
|
||||
where: { status: 1 },
|
||||
select: ['word'],
|
||||
});
|
||||
this.badWords = data.map((t) => t.word);
|
||||
}
|
||||
async queryBadWords(query) {
|
||||
const { page = 1, size = 500, word, status } = query;
|
||||
const where = {};
|
||||
[0, 1, '0', '1'].includes(status) && (where.status = status);
|
||||
word && (where.word = (0, typeorm_2.Like)(`%${word}%`));
|
||||
const [rows, count] = await this.badWordsEntity.findAndCount({
|
||||
where,
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
order: { id: 'ASC' },
|
||||
});
|
||||
return { rows, count };
|
||||
}
|
||||
async delBadWords(body) {
|
||||
const b = await this.badWordsEntity.findOne({ where: { id: body.id } });
|
||||
if (!b) {
|
||||
throw new common_1.HttpException('敏感词不存在,请检查您的提交信息', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const res = await this.badWordsEntity.delete({ id: body.id });
|
||||
if (res.affected > 0) {
|
||||
await this.loadBadWords();
|
||||
return '删除敏感词成功';
|
||||
}
|
||||
else {
|
||||
throw new common_1.HttpException('删除敏感词失败', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
async updateBadWords(body) {
|
||||
const { id, word, status } = body;
|
||||
const b = await this.badWordsEntity.findOne({ where: { word } });
|
||||
if (b) {
|
||||
throw new common_1.HttpException('敏感词已经存在了、请勿重复添加', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const res = await this.badWordsEntity.update({ id }, { word, status });
|
||||
if (res.affected > 0) {
|
||||
await this.loadBadWords();
|
||||
return '更新敏感词成功';
|
||||
}
|
||||
else {
|
||||
throw new common_1.HttpException('更新敏感词失败', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
async addBadWord(body) {
|
||||
const { word } = body;
|
||||
const b = await this.badWordsEntity.findOne({ where: { word } });
|
||||
if (b) {
|
||||
throw new common_1.HttpException('敏感词已存在,请检查您的提交信息', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
await this.badWordsEntity.save({ word });
|
||||
await this.loadBadWords();
|
||||
return '添加敏感词成功';
|
||||
}
|
||||
async recordUserBadWords(userId, content, words, typeCn, typeOriginCn) {
|
||||
const data = {
|
||||
userId,
|
||||
content,
|
||||
words: JSON.stringify(words),
|
||||
typeCn: JSON.stringify(typeCn),
|
||||
typeOriginCn,
|
||||
};
|
||||
try {
|
||||
await this.userEntity
|
||||
.createQueryBuilder()
|
||||
.update(user_entity_1.UserEntity)
|
||||
.set({ violationCount: () => 'violationCount + 1' })
|
||||
.where('id = :userId', { userId })
|
||||
.execute();
|
||||
await this.violationLogEntity.save(data);
|
||||
}
|
||||
catch (error) {
|
||||
console.log('error: ', error);
|
||||
}
|
||||
}
|
||||
async violation(req, query) {
|
||||
const { role } = req.user;
|
||||
const { page = 1, size = 10, userId, typeOriginCn } = query;
|
||||
const where = {};
|
||||
userId && (where['userId'] = userId);
|
||||
typeOriginCn && (where['typeOriginCn'] = typeOriginCn);
|
||||
const [rows, count] = await this.violationLogEntity.findAndCount({
|
||||
where,
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
order: { id: 'DESC' },
|
||||
});
|
||||
const userIds = [...new Set(rows.map((t) => t.userId))];
|
||||
const usersInfo = await this.userEntity.find({
|
||||
where: { id: (0, typeorm_2.In)(userIds) },
|
||||
select: ['id', 'avatar', 'username', 'email', 'violationCount', 'status'],
|
||||
});
|
||||
rows.forEach((t) => {
|
||||
const user = usersInfo.find((u) => u.id === t.userId) || {};
|
||||
role !== 'super' && (user.email = (0, utils_1.hideString)(user.email));
|
||||
t.userInfo = user;
|
||||
});
|
||||
return { rows, count };
|
||||
}
|
||||
};
|
||||
BadWordsService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__param(0, (0, typeorm_1.InjectRepository)(badWords_entity_1.BadWordsEntity)),
|
||||
__param(1, (0, typeorm_1.InjectRepository)(violationLog_entity_1.ViolationLogEntity)),
|
||||
__param(2, (0, typeorm_1.InjectRepository)(user_entity_1.UserEntity)),
|
||||
__metadata("design:paramtypes", [typeorm_2.Repository,
|
||||
typeorm_2.Repository,
|
||||
typeorm_2.Repository,
|
||||
globalConfig_service_1.GlobalConfigService])
|
||||
], BadWordsService);
|
||||
exports.BadWordsService = BadWordsService;
|
||||
20
AIWebQuickDeploy/dist/modules/badWords/dto/addBadWords.dto.js
vendored
Normal file
20
AIWebQuickDeploy/dist/modules/badWords/dto/addBadWords.dto.js
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
"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.AddBadWordDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class AddBadWordDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'test', description: '敏感词', required: true }),
|
||||
__metadata("design:type", String)
|
||||
], AddBadWordDto.prototype, "word", void 0);
|
||||
exports.AddBadWordDto = AddBadWordDto;
|
||||
20
AIWebQuickDeploy/dist/modules/badWords/dto/delBadWords.dto.js
vendored
Normal file
20
AIWebQuickDeploy/dist/modules/badWords/dto/delBadWords.dto.js
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
"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.DelBadWordsDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class DelBadWordsDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '敏感词id', required: true }),
|
||||
__metadata("design:type", Number)
|
||||
], DelBadWordsDto.prototype, "id", void 0);
|
||||
exports.DelBadWordsDto = DelBadWordsDto;
|
||||
37
AIWebQuickDeploy/dist/modules/badWords/dto/queryBadWords.dto.js
vendored
Normal file
37
AIWebQuickDeploy/dist/modules/badWords/dto/queryBadWords.dto.js
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
"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.QueryBadWordsDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class QueryBadWordsDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QueryBadWordsDto.prototype, "page", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QueryBadWordsDto.prototype, "size", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'test', description: '敏感词内容', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QueryBadWordsDto.prototype, "word", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '关键词状态', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QueryBadWordsDto.prototype, "status", void 0);
|
||||
exports.QueryBadWordsDto = QueryBadWordsDto;
|
||||
37
AIWebQuickDeploy/dist/modules/badWords/dto/queryViolation.dto.js
vendored
Normal file
37
AIWebQuickDeploy/dist/modules/badWords/dto/queryViolation.dto.js
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
"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.QueryViolationDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class QueryViolationDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QueryViolationDto.prototype, "page", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QueryViolationDto.prototype, "size", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '用户ID', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QueryViolationDto.prototype, "userId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '百度云检测', description: '检测平台来源', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QueryViolationDto.prototype, "typeOriginCn", void 0);
|
||||
exports.QueryViolationDto = QueryViolationDto;
|
||||
32
AIWebQuickDeploy/dist/modules/badWords/dto/updateBadWords.dto.js
vendored
Normal file
32
AIWebQuickDeploy/dist/modules/badWords/dto/updateBadWords.dto.js
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
"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.UpdateBadWordsDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class UpdateBadWordsDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '敏感词id', required: true }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], UpdateBadWordsDto.prototype, "id", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'test', description: '敏感词内容', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateBadWordsDto.prototype, "word", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '关键词状态', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], UpdateBadWordsDto.prototype, "status", void 0);
|
||||
exports.UpdateBadWordsDto = UpdateBadWordsDto;
|
||||
40
AIWebQuickDeploy/dist/modules/badWords/violationLog.entity.js
vendored
Normal file
40
AIWebQuickDeploy/dist/modules/badWords/violationLog.entity.js
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
"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.ViolationLogEntity = void 0;
|
||||
const typeorm_1 = require("typeorm");
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
let ViolationLogEntity = class ViolationLogEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '用户id' }),
|
||||
__metadata("design:type", Number)
|
||||
], ViolationLogEntity.prototype, "userId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '违规内容', type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], ViolationLogEntity.prototype, "content", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '敏感词', type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], ViolationLogEntity.prototype, "words", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '违规类型' }),
|
||||
__metadata("design:type", String)
|
||||
], ViolationLogEntity.prototype, "typeCn", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '违规检测失败于哪个平台' }),
|
||||
__metadata("design:type", String)
|
||||
], ViolationLogEntity.prototype, "typeOriginCn", void 0);
|
||||
ViolationLogEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'violation_log' })
|
||||
], ViolationLogEntity);
|
||||
exports.ViolationLogEntity = ViolationLogEntity;
|
||||
123
AIWebQuickDeploy/dist/modules/chat/chat.controller.js
vendored
Normal file
123
AIWebQuickDeploy/dist/modules/chat/chat.controller.js
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
"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.ChatController = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const jwtAuth_guard_1 = require("../../common/auth/jwtAuth.guard");
|
||||
const chat_service_1 = require("./chat.service");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const chatProcess_dto_1 = require("./dto/chatProcess.dto");
|
||||
const aiPPT_1 = require("../ai/aiPPT");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
let ChatController = class ChatController {
|
||||
constructor(chatService, globalConfigService, aiPptService) {
|
||||
this.chatService = chatService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
this.aiPptService = aiPptService;
|
||||
}
|
||||
chatProcess(body, req, res) {
|
||||
return this.chatService.chatProcess(body, req, res);
|
||||
}
|
||||
chatProcessSync(body, req) {
|
||||
return this.chatService.chatProcess(Object.assign({}, body), req);
|
||||
}
|
||||
async mjFanyi(body, req) {
|
||||
return this.chatService.chatProcess(Object.assign(Object.assign({}, body), { specialModel: 'PromptOptimization' }), req);
|
||||
}
|
||||
async chatmind(body, req, res) {
|
||||
return this.chatService.chatProcess(Object.assign(Object.assign({}, body), { specialModel: 'MindMap' }), req, res);
|
||||
}
|
||||
ttsProcess(body, req, res) {
|
||||
return this.chatService.ttsProcess(body, req, res);
|
||||
}
|
||||
pptCover(body) {
|
||||
return this.aiPptService.pptCover(body);
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Post)('chat-process'),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'gpt聊天对话' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__param(2, (0, common_1.Res)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [chatProcess_dto_1.ChatProcessDto, Object, Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatController.prototype, "chatProcess", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('chat-sync'),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'gpt聊天对话' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [chatProcess_dto_1.ChatProcessDto, Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatController.prototype, "chatProcessSync", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('mj-fy'),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'gpt描述词绘画翻译' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [chatProcess_dto_1.ChatProcessDto, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ChatController.prototype, "mjFanyi", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('chat-mind'),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'mind思维导图提示' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__param(2, (0, common_1.Res)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [chatProcess_dto_1.ChatProcessDto, Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ChatController.prototype, "chatmind", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('tts-process'),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'tts语音播报' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__param(2, (0, common_1.Res)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object, Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatController.prototype, "ttsProcess", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('ppt-cover'),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'ppt封面获取' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatController.prototype, "pptCover", null);
|
||||
ChatController = __decorate([
|
||||
(0, swagger_1.ApiTags)('chatgpt'),
|
||||
(0, common_1.Controller)('chatgpt'),
|
||||
__metadata("design:paramtypes", [chat_service_1.ChatService,
|
||||
globalConfig_service_1.GlobalConfigService,
|
||||
aiPPT_1.AiPptService])
|
||||
], ChatController);
|
||||
exports.ChatController = ChatController;
|
||||
87
AIWebQuickDeploy/dist/modules/chat/chat.module.js
vendored
Normal file
87
AIWebQuickDeploy/dist/modules/chat/chat.module.js
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
"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.ChatModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const aiPPT_1 = require("../ai/aiPPT");
|
||||
const cogVideo_service_1 = require("../ai/cogVideo.service");
|
||||
const fluxDraw_service_1 = require("../ai/fluxDraw.service");
|
||||
const lumaVideo_service_1 = require("../ai/lumaVideo.service");
|
||||
const midjourneyDraw_service_1 = require("../ai/midjourneyDraw.service");
|
||||
const openaiChat_service_1 = require("../ai/openaiChat.service");
|
||||
const openaiDraw_service_1 = require("../ai/openaiDraw.service");
|
||||
const stableDiffusion_service_1 = require("../ai/stableDiffusion.service");
|
||||
const suno_service_1 = require("../ai/suno.service");
|
||||
const app_entity_1 = require("../app/app.entity");
|
||||
const chatGroup_entity_1 = require("../chatGroup/chatGroup.entity");
|
||||
const chatLog_entity_1 = require("../chatLog/chatLog.entity");
|
||||
const chatLog_service_1 = require("../chatLog/chatLog.service");
|
||||
const cramiPackage_entity_1 = require("../crami/cramiPackage.entity");
|
||||
const config_entity_1 = require("../globalConfig/config.entity");
|
||||
const mailer_service_1 = require("../mailer/mailer.service");
|
||||
const plugin_entity_1 = require("../plugin/plugin.entity");
|
||||
const redisCache_service_1 = require("../redisCache/redisCache.service");
|
||||
const user_entity_1 = require("../user/user.entity");
|
||||
const user_service_1 = require("../user/user.service");
|
||||
const accountLog_entity_1 = require("../userBalance/accountLog.entity");
|
||||
const balance_entity_1 = require("../userBalance/balance.entity");
|
||||
const fingerprint_entity_1 = require("../userBalance/fingerprint.entity");
|
||||
const userBalance_entity_1 = require("../userBalance/userBalance.entity");
|
||||
const userBalance_service_1 = require("../userBalance/userBalance.service");
|
||||
const verification_service_1 = require("../verification/verification.service");
|
||||
const verifycation_entity_1 = require("../verification/verifycation.entity");
|
||||
const chat_controller_1 = require("./chat.controller");
|
||||
const chat_service_1 = require("./chat.service");
|
||||
const netSearch_service_1 = require("../ai/netSearch.service");
|
||||
let ChatModule = class ChatModule {
|
||||
};
|
||||
ChatModule = __decorate([
|
||||
(0, common_1.Global)(),
|
||||
(0, common_1.Module)({
|
||||
imports: [
|
||||
typeorm_1.TypeOrmModule.forFeature([
|
||||
balance_entity_1.BalanceEntity,
|
||||
user_entity_1.UserEntity,
|
||||
plugin_entity_1.PluginEntity,
|
||||
verifycation_entity_1.VerifycationEntity,
|
||||
chatLog_entity_1.ChatLogEntity,
|
||||
accountLog_entity_1.AccountLogEntity,
|
||||
config_entity_1.ConfigEntity,
|
||||
user_entity_1.UserEntity,
|
||||
cramiPackage_entity_1.CramiPackageEntity,
|
||||
chatGroup_entity_1.ChatGroupEntity,
|
||||
app_entity_1.AppEntity,
|
||||
userBalance_entity_1.UserBalanceEntity,
|
||||
fingerprint_entity_1.FingerprintLogEntity,
|
||||
]),
|
||||
],
|
||||
controllers: [chat_controller_1.ChatController],
|
||||
providers: [
|
||||
chat_service_1.ChatService,
|
||||
userBalance_service_1.UserBalanceService,
|
||||
user_service_1.UserService,
|
||||
verification_service_1.VerificationService,
|
||||
chatLog_service_1.ChatLogService,
|
||||
redisCache_service_1.RedisCacheService,
|
||||
mailer_service_1.MailerService,
|
||||
suno_service_1.SunoService,
|
||||
openaiChat_service_1.OpenAIChatService,
|
||||
stableDiffusion_service_1.StableDiffusionService,
|
||||
midjourneyDraw_service_1.MidjourneyService,
|
||||
openaiDraw_service_1.OpenAIDrawService,
|
||||
lumaVideo_service_1.LumaVideoService,
|
||||
cogVideo_service_1.CogVideoService,
|
||||
fluxDraw_service_1.FluxDrawService,
|
||||
aiPPT_1.AiPptService,
|
||||
netSearch_service_1.netSearchService,
|
||||
],
|
||||
exports: [chat_service_1.ChatService],
|
||||
})
|
||||
], ChatModule);
|
||||
exports.ChatModule = ChatModule;
|
||||
1007
AIWebQuickDeploy/dist/modules/chat/chat.service.js
vendored
Normal file
1007
AIWebQuickDeploy/dist/modules/chat/chat.service.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
78
AIWebQuickDeploy/dist/modules/chat/dto/chatDraw.dto.js
vendored
Normal file
78
AIWebQuickDeploy/dist/modules/chat/dto/chatDraw.dto.js
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
"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.ChatDrawDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class ChatDrawDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'Draw a cute little dog', description: '绘画描述信息' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatDrawDto.prototype, "prompt", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '绘画张数', required: true }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatDrawDto.prototype, "n", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '1024x1024', description: '图片尺寸', required: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatDrawDto.prototype, "size", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'standard', description: '图片质量', required: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatDrawDto.prototype, "quality", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: 'close-up polaroid photo, of a little joyful cute panda, in the forest, sun rays coming, photographic, sharp focus, depth of field, soft lighting, heigh quality, 24mm, Nikon Z FX',
|
||||
description: '绘画提示词!',
|
||||
required: true,
|
||||
}),
|
||||
(0, swagger_1.ApiProperty)({ example: '--ar 16:9 --c 0', description: '除了prompt的额外参数' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], ChatDrawDto.prototype, "extraParam", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'https://xsdasdasd.com', description: '垫图图片地址' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], ChatDrawDto.prototype, "imgUrl", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'IMAGINE', description: '任务类型,可用值:IMAGINE,UPSCALE,VARIATION,ZOOM,PAN,DESCRIBE,BLEND,SHORTEN,SWAP_FACE' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], ChatDrawDto.prototype, "action", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '变体或者放大的序号' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], ChatDrawDto.prototype, "orderId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '绘画的DBID' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], ChatDrawDto.prototype, "drawId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: 'customId' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], ChatDrawDto.prototype, "customId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: 'base64' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], ChatDrawDto.prototype, "base64", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '任务ID' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], ChatDrawDto.prototype, "taskId", void 0);
|
||||
exports.ChatDrawDto = ChatDrawDto;
|
||||
57
AIWebQuickDeploy/dist/modules/chat/dto/chatProcess.dto.js
vendored
Normal file
57
AIWebQuickDeploy/dist/modules/chat/dto/chatProcess.dto.js
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
"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.ChatProcessDto = exports.Options = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_transformer_1 = require("class-transformer");
|
||||
class Options {
|
||||
}
|
||||
__decorate([
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], Options.prototype, "parentMessageId", void 0);
|
||||
exports.Options = Options;
|
||||
class ChatProcessDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'hello, Who are you', description: '对话信息' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '提问信息不能为空!' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatProcessDto.prototype, "prompt", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'https://aiweb.com', description: '对话附带的链接', required: false }),
|
||||
__metadata("design:type", String)
|
||||
], ChatProcessDto.prototype, "url", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '{ parentMessageId: 0 }', description: '上次对话信息', required: false }),
|
||||
(0, class_transformer_1.Type)(() => Options),
|
||||
__metadata("design:type", Options)
|
||||
], ChatProcessDto.prototype, "options", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully. Respond using markdown.",
|
||||
description: '系统预设信息',
|
||||
}),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], ChatProcessDto.prototype, "systemMessage", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '应用id', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], ChatProcessDto.prototype, "appId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: "gpt-3.5-turbo", description: '使用模型', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], ChatProcessDto.prototype, "model", void 0);
|
||||
exports.ChatProcessDto = ChatProcessDto;
|
||||
46
AIWebQuickDeploy/dist/modules/chat/helper.js
vendored
Normal file
46
AIWebQuickDeploy/dist/modules/chat/helper.js
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.addOneIfOdd = exports.unifiedFormattingResponse = void 0;
|
||||
function unifiedFormattingResponse(keyType, response, others) {
|
||||
let formatRes = {
|
||||
keyType,
|
||||
parentMessageId: '',
|
||||
text: '',
|
||||
usage: {
|
||||
prompt_tokens: 0,
|
||||
completion_tokens: 0,
|
||||
total_tokens: 0,
|
||||
}
|
||||
};
|
||||
const { parentMessageId } = response === null || response === void 0 ? void 0 : response.detail;
|
||||
let { usage } = response === null || response === void 0 ? void 0 : response.detail;
|
||||
if (!usage) {
|
||||
usage = {
|
||||
prompt_tokens: 0,
|
||||
completion_tokens: 0,
|
||||
total_tokens: 0
|
||||
};
|
||||
}
|
||||
const { prompt_tokens, completion_tokens, total_tokens } = usage;
|
||||
formatRes = {
|
||||
keyType,
|
||||
parentMessageId,
|
||||
text: response.text,
|
||||
usage: {
|
||||
prompt_tokens,
|
||||
completion_tokens,
|
||||
total_tokens
|
||||
}
|
||||
};
|
||||
return formatRes;
|
||||
}
|
||||
exports.unifiedFormattingResponse = unifiedFormattingResponse;
|
||||
function addOneIfOdd(num) {
|
||||
if (num % 2 !== 0) {
|
||||
return num + 1;
|
||||
}
|
||||
else {
|
||||
return num;
|
||||
}
|
||||
}
|
||||
exports.addOneIfOdd = addOneIfOdd;
|
||||
101
AIWebQuickDeploy/dist/modules/chatGroup/chatGroup.controller.js
vendored
Normal file
101
AIWebQuickDeploy/dist/modules/chatGroup/chatGroup.controller.js
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
"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.ChatGroupController = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const chatGroup_service_1 = require("./chatGroup.service");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const createGroup_dto_1 = require("./dto/createGroup.dto");
|
||||
const jwtAuth_guard_1 = require("../../common/auth/jwtAuth.guard");
|
||||
const delGroup_dto_1 = require("./dto/delGroup.dto");
|
||||
const updateGroup_dto_1 = require("./dto/updateGroup.dto");
|
||||
let ChatGroupController = class ChatGroupController {
|
||||
constructor(chatGroupService) {
|
||||
this.chatGroupService = chatGroupService;
|
||||
}
|
||||
create(body, req) {
|
||||
return this.chatGroupService.create(body, req);
|
||||
}
|
||||
query(req) {
|
||||
return this.chatGroupService.query(req);
|
||||
}
|
||||
update(body, req) {
|
||||
return this.chatGroupService.update(body, req);
|
||||
}
|
||||
del(body, req) {
|
||||
return this.chatGroupService.del(body, req);
|
||||
}
|
||||
delAll(req) {
|
||||
return this.chatGroupService.delAll(req);
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Post)('create'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '创建对话组' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [createGroup_dto_1.CreateGroupDto, Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatGroupController.prototype, "create", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('query'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询对话组' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatGroupController.prototype, "query", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('update'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '更新对话组' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [updateGroup_dto_1.UpdateGroupDto, Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatGroupController.prototype, "update", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('del'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '删除对话组' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [delGroup_dto_1.DelGroupDto, Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatGroupController.prototype, "del", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('delAll'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '删除对话组' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatGroupController.prototype, "delAll", null);
|
||||
ChatGroupController = __decorate([
|
||||
(0, swagger_1.ApiTags)('group'),
|
||||
(0, common_1.Controller)('group'),
|
||||
__metadata("design:paramtypes", [chatGroup_service_1.ChatGroupService])
|
||||
], ChatGroupController);
|
||||
exports.ChatGroupController = ChatGroupController;
|
||||
56
AIWebQuickDeploy/dist/modules/chatGroup/chatGroup.entity.js
vendored
Normal file
56
AIWebQuickDeploy/dist/modules/chatGroup/chatGroup.entity.js
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
"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.ChatGroupEntity = void 0;
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
const typeorm_1 = require("typeorm");
|
||||
let ChatGroupEntity = class ChatGroupEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '用户ID' }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatGroupEntity.prototype, "userId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '是否置顶聊天', type: 'boolean', default: false }),
|
||||
__metadata("design:type", Boolean)
|
||||
], ChatGroupEntity.prototype, "isSticky", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '分组名称', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatGroupEntity.prototype, "title", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '应用ID', nullable: true }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatGroupEntity.prototype, "appId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '是否删除了', default: false }),
|
||||
__metadata("design:type", Boolean)
|
||||
], ChatGroupEntity.prototype, "isDelete", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '配置', nullable: true, default: null, type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatGroupEntity.prototype, "config", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '附加参数', nullable: true, type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatGroupEntity.prototype, "params", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '文件链接', nullable: true, default: null, type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatGroupEntity.prototype, "fileUrl", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'PDF中的文字内容', nullable: true, type: 'mediumtext' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatGroupEntity.prototype, "pdfTextContent", void 0);
|
||||
ChatGroupEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'chat_group' })
|
||||
], ChatGroupEntity);
|
||||
exports.ChatGroupEntity = ChatGroupEntity;
|
||||
27
AIWebQuickDeploy/dist/modules/chatGroup/chatGroup.module.js
vendored
Normal file
27
AIWebQuickDeploy/dist/modules/chatGroup/chatGroup.module.js
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
"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.ChatGroupModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const chatGroup_controller_1 = require("./chatGroup.controller");
|
||||
const chatGroup_service_1 = require("./chatGroup.service");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const chatGroup_entity_1 = require("./chatGroup.entity");
|
||||
const app_entity_1 = require("../app/app.entity");
|
||||
let ChatGroupModule = class ChatGroupModule {
|
||||
};
|
||||
ChatGroupModule = __decorate([
|
||||
(0, common_1.Global)(),
|
||||
(0, common_1.Module)({
|
||||
imports: [typeorm_1.TypeOrmModule.forFeature([chatGroup_entity_1.ChatGroupEntity, app_entity_1.AppEntity])],
|
||||
controllers: [chatGroup_controller_1.ChatGroupController],
|
||||
providers: [chatGroup_service_1.ChatGroupService],
|
||||
exports: [chatGroup_service_1.ChatGroupService]
|
||||
})
|
||||
], ChatGroupModule);
|
||||
exports.ChatGroupModule = ChatGroupModule;
|
||||
219
AIWebQuickDeploy/dist/modules/chatGroup/chatGroup.service.js
vendored
Normal file
219
AIWebQuickDeploy/dist/modules/chatGroup/chatGroup.service.js
vendored
Normal file
@@ -0,0 +1,219 @@
|
||||
"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); }
|
||||
};
|
||||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
||||
t[p[i]] = s[p[i]];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ChatGroupService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const axios_1 = require("axios");
|
||||
const pdf = require("pdf-parse");
|
||||
const typeorm_2 = require("typeorm");
|
||||
const app_entity_1 = require("../app/app.entity");
|
||||
const models_service_1 = require("../models/models.service");
|
||||
const chatGroup_entity_1 = require("./chatGroup.entity");
|
||||
let ChatGroupService = class ChatGroupService {
|
||||
constructor(chatGroupEntity, appEntity, modelsService) {
|
||||
this.chatGroupEntity = chatGroupEntity;
|
||||
this.appEntity = appEntity;
|
||||
this.modelsService = modelsService;
|
||||
}
|
||||
async create(body, req) {
|
||||
const { id } = req.user;
|
||||
const { appId, modelConfig: bodyModelConfig, params } = body;
|
||||
let modelConfig = bodyModelConfig || (await this.modelsService.getBaseConfig());
|
||||
if (!modelConfig) {
|
||||
throw new common_1.HttpException('管理员未配置任何AI模型、请先联系管理员开通聊天模型配置!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
modelConfig = JSON.parse(JSON.stringify(modelConfig));
|
||||
const groupParams = { title: '新对话', userId: id, appId, params };
|
||||
if (appId) {
|
||||
const appInfo = await this.appEntity.findOne({ where: { id: appId } });
|
||||
if (!appInfo) {
|
||||
throw new common_1.HttpException('非法操作、您在使用一个不存在的应用!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const { status, name, isFixedModel, isGPTs, appModel, coverImg } = appInfo;
|
||||
Object.assign(modelConfig.modelInfo, {
|
||||
isGPTs,
|
||||
isFixedModel,
|
||||
modelAvatar: coverImg,
|
||||
modelName: name,
|
||||
});
|
||||
if (isGPTs === 1 || isFixedModel === 1) {
|
||||
const appModelKey = await this.modelsService.getCurrentModelKeyInfo(isFixedModel === 1 ? appModel : 'gpts');
|
||||
Object.assign(modelConfig.modelInfo, {
|
||||
deductType: appModelKey.deductType,
|
||||
deduct: appModelKey.deduct,
|
||||
model: appModel,
|
||||
isFileUpload: appModelKey.isFileUpload,
|
||||
});
|
||||
}
|
||||
if (![1, 3, 4, 5].includes(status)) {
|
||||
throw new common_1.HttpException('非法操作、您在使用一个未启用的应用!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (name) {
|
||||
groupParams.title = name;
|
||||
}
|
||||
}
|
||||
const newGroup = await this.chatGroupEntity.save(Object.assign(Object.assign({}, groupParams), { config: JSON.stringify(modelConfig) }));
|
||||
return newGroup;
|
||||
}
|
||||
async query(req) {
|
||||
try {
|
||||
const { id } = req.user;
|
||||
const params = { userId: id, isDelete: false };
|
||||
const res = await this.chatGroupEntity.find({
|
||||
where: params,
|
||||
order: { isSticky: 'DESC', updatedAt: 'DESC' },
|
||||
});
|
||||
return res;
|
||||
const appIds = res.filter((t) => t.appId).map((t) => t.appId);
|
||||
const appInfos = await this.appEntity.find({ where: { id: (0, typeorm_2.In)(appIds) } });
|
||||
return res.map((item) => {
|
||||
var _a;
|
||||
item.appLogo = (_a = appInfos.find((t) => t.id === item.appId)) === null || _a === void 0 ? void 0 : _a.coverImg;
|
||||
return item;
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
console.log('error: ', error);
|
||||
}
|
||||
}
|
||||
async update(body, req) {
|
||||
const { title, isSticky, groupId, config, fileUrl } = body;
|
||||
const { id } = req.user;
|
||||
const g = await this.chatGroupEntity.findOne({
|
||||
where: { id: groupId, userId: id },
|
||||
});
|
||||
if (!g) {
|
||||
throw new common_1.HttpException('请先选择一个对话或者新加一个对话再操作!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const { appId } = g;
|
||||
if (appId && !title) {
|
||||
try {
|
||||
const parseData = JSON.parse(config);
|
||||
if (Number(parseData.keyType) !== 1) {
|
||||
throw new common_1.HttpException('应用对话名称不能修改哟!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
}
|
||||
}
|
||||
const data = {};
|
||||
title && (data['title'] = title);
|
||||
typeof isSticky !== 'undefined' && (data['isSticky'] = isSticky);
|
||||
config && (data['config'] = config);
|
||||
fileUrl && (data['fileUrl'] = fileUrl);
|
||||
const u = await this.chatGroupEntity.update({ id: groupId }, data);
|
||||
if (u.affected) {
|
||||
if (fileUrl) {
|
||||
this.handlePdfExtraction(fileUrl, groupId);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
throw new common_1.HttpException('更新对话失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
async handlePdfExtraction(fileUrl, groupId) {
|
||||
try {
|
||||
const pdfText = await this.extractPdfText(fileUrl);
|
||||
await this.chatGroupEntity.update({ id: groupId }, { pdfTextContent: pdfText });
|
||||
}
|
||||
catch (error) {
|
||||
console.error('PDF 读取失败:', error);
|
||||
}
|
||||
}
|
||||
async extractPdfText(fileUrl) {
|
||||
try {
|
||||
const response = await axios_1.default.get(fileUrl, {
|
||||
responseType: 'arraybuffer',
|
||||
});
|
||||
const dataBuffer = Buffer.from(response.data);
|
||||
const pdfData = await pdf(dataBuffer);
|
||||
return pdfData.text;
|
||||
}
|
||||
catch (error) {
|
||||
console.error('PDF 解析失败:', error);
|
||||
throw new Error('PDF 解析失败');
|
||||
}
|
||||
}
|
||||
async updateTime(groupId) {
|
||||
await this.chatGroupEntity.update(groupId, {
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
}
|
||||
async del(body, req) {
|
||||
const { groupId } = body;
|
||||
const { id } = req.user;
|
||||
const g = await this.chatGroupEntity.findOne({
|
||||
where: { id: groupId, userId: id },
|
||||
});
|
||||
if (!g) {
|
||||
throw new common_1.HttpException('非法操作、您在删除一个非法资源!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const r = await this.chatGroupEntity.update({ id: groupId }, { isDelete: true });
|
||||
if (r.affected) {
|
||||
return '删除成功';
|
||||
}
|
||||
else {
|
||||
throw new common_1.HttpException('删除失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
async delAll(req) {
|
||||
const { id } = req.user;
|
||||
const r = await this.chatGroupEntity.update({ userId: id, isSticky: false, isDelete: false }, { isDelete: true });
|
||||
if (r.affected) {
|
||||
return '删除成功';
|
||||
}
|
||||
else {
|
||||
throw new common_1.HttpException('删除失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
async getGroupInfoFromId(id) {
|
||||
if (!id)
|
||||
return;
|
||||
const groupInfo = await this.chatGroupEntity.findOne({ where: { id } });
|
||||
if (groupInfo) {
|
||||
const { pdfTextContent } = groupInfo, rest = __rest(groupInfo, ["pdfTextContent"]);
|
||||
return rest;
|
||||
}
|
||||
}
|
||||
async getGroupPdfText(groupId) {
|
||||
const groupInfo = await this.chatGroupEntity.findOne({
|
||||
where: { id: groupId },
|
||||
});
|
||||
if (groupInfo) {
|
||||
return groupInfo.pdfTextContent;
|
||||
}
|
||||
}
|
||||
};
|
||||
ChatGroupService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__param(0, (0, typeorm_1.InjectRepository)(chatGroup_entity_1.ChatGroupEntity)),
|
||||
__param(1, (0, typeorm_1.InjectRepository)(app_entity_1.AppEntity)),
|
||||
__metadata("design:paramtypes", [typeorm_2.Repository,
|
||||
typeorm_2.Repository,
|
||||
models_service_1.ModelsService])
|
||||
], ChatGroupService);
|
||||
exports.ChatGroupService = ChatGroupService;
|
||||
38
AIWebQuickDeploy/dist/modules/chatGroup/dto/createGroup.dto.js
vendored
Normal file
38
AIWebQuickDeploy/dist/modules/chatGroup/dto/createGroup.dto.js
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
"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.CreateGroupDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class CreateGroupDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, description: '应用ID', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], CreateGroupDto.prototype, "appId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: '',
|
||||
description: '对话模型配置项序列化的字符串',
|
||||
required: false,
|
||||
}),
|
||||
__metadata("design:type", Object)
|
||||
], CreateGroupDto.prototype, "modelConfig", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: '',
|
||||
description: '对话组参数序列化的字符串',
|
||||
required: false,
|
||||
}),
|
||||
__metadata("design:type", String)
|
||||
], CreateGroupDto.prototype, "params", void 0);
|
||||
exports.CreateGroupDto = CreateGroupDto;
|
||||
20
AIWebQuickDeploy/dist/modules/chatGroup/dto/delGroup.dto.js
vendored
Normal file
20
AIWebQuickDeploy/dist/modules/chatGroup/dto/delGroup.dto.js
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
"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.DelGroupDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class DelGroupDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '对话分组ID', required: true }),
|
||||
__metadata("design:type", Number)
|
||||
], DelGroupDto.prototype, "groupId", void 0);
|
||||
exports.DelGroupDto = DelGroupDto;
|
||||
45
AIWebQuickDeploy/dist/modules/chatGroup/dto/updateGroup.dto.js
vendored
Normal file
45
AIWebQuickDeploy/dist/modules/chatGroup/dto/updateGroup.dto.js
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
"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.UpdateGroupDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class UpdateGroupDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '修改的对话ID', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], UpdateGroupDto.prototype, "groupId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, description: '对话组title', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateGroupDto.prototype, "title", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, description: '对话组是否置顶', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Boolean)
|
||||
], UpdateGroupDto.prototype, "isSticky", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '', description: '对话组文件地址', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateGroupDto.prototype, "fileUrl", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: '',
|
||||
description: '对话模型配置项序列化的字符串',
|
||||
required: false,
|
||||
}),
|
||||
__metadata("design:type", String)
|
||||
], UpdateGroupDto.prototype, "config", void 0);
|
||||
exports.UpdateGroupDto = UpdateGroupDto;
|
||||
176
AIWebQuickDeploy/dist/modules/chatLog/chatLog.controller.js
vendored
Normal file
176
AIWebQuickDeploy/dist/modules/chatLog/chatLog.controller.js
vendored
Normal file
@@ -0,0 +1,176 @@
|
||||
"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.ChatLogController = void 0;
|
||||
const adminAuth_guard_1 = require("../../common/auth/adminAuth.guard");
|
||||
const jwtAuth_guard_1 = require("../../common/auth/jwtAuth.guard");
|
||||
const superAuth_guard_1 = require("../../common/auth/superAuth.guard");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const chatLog_service_1 = require("./chatLog.service");
|
||||
const chatList_dto_1 = require("./dto/chatList.dto");
|
||||
const del_dto_1 = require("./dto/del.dto");
|
||||
const delByGroup_dto_1 = require("./dto/delByGroup.dto");
|
||||
const exportExcelChatlog_dto_1 = require("./dto/exportExcelChatlog.dto");
|
||||
const queryAllChatLog_dto_1 = require("./dto/queryAllChatLog.dto");
|
||||
const queryAllDrawLog_dto_1 = require("./dto/queryAllDrawLog.dto");
|
||||
const queryByAppId_dto_1 = require("./dto/queryByAppId.dto");
|
||||
const queryMyChatLog_dto_1 = require("./dto/queryMyChatLog.dto");
|
||||
const recDrawImg_dto_1 = require("./dto/recDrawImg.dto");
|
||||
let ChatLogController = class ChatLogController {
|
||||
constructor(chatLogService) {
|
||||
this.chatLogService = chatLogService;
|
||||
}
|
||||
querDrawLog(query, req) {
|
||||
return this.chatLogService.querDrawLog(req, query);
|
||||
}
|
||||
recDrawImg(body) {
|
||||
return this.chatLogService.recDrawImg(body);
|
||||
}
|
||||
querAllDrawLog(params) {
|
||||
return this.chatLogService.querAllDrawLog(params);
|
||||
}
|
||||
queryAllChatLog(params, req) {
|
||||
return this.chatLogService.querAllChatLog(params, req);
|
||||
}
|
||||
exportExcel(body, res) {
|
||||
return this.chatLogService.exportExcel(body, res);
|
||||
}
|
||||
chatList(req, params) {
|
||||
return this.chatLogService.chatList(req, params);
|
||||
}
|
||||
del(req, body) {
|
||||
return this.chatLogService.deleteChatLog(req, body);
|
||||
}
|
||||
delByGroupId(req, body) {
|
||||
return this.chatLogService.delByGroupId(req, body);
|
||||
}
|
||||
deleteChatsAfterId(req, body) {
|
||||
return this.chatLogService.deleteChatsAfterId(req, body);
|
||||
}
|
||||
byAppId(req, params) {
|
||||
return this.chatLogService.byAppId(req, params);
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Get)('draw'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询我的绘制记录' }),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
__param(0, (0, common_1.Query)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [queryMyChatLog_dto_1.QuerMyChatLogDto, Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatLogController.prototype, "querDrawLog", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('recDrawImg'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '推荐此图片对外展示' }),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [recDrawImg_dto_1.recDrawImgDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatLogController.prototype, "recDrawImg", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('drawAll'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询所有的绘制记录' }),
|
||||
__param(0, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [queryAllDrawLog_dto_1.QuerAllDrawLogDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatLogController.prototype, "querAllDrawLog", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('chatAll'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询所有的问答记录' }),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
(0, common_1.UseGuards)(adminAuth_guard_1.AdminAuthGuard),
|
||||
__param(0, (0, common_1.Query)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [queryAllChatLog_dto_1.QuerAllChatLogDto, Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatLogController.prototype, "queryAllChatLog", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('exportExcel'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '导出问答记录' }),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Res)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [exportExcelChatlog_dto_1.ExportExcelChatlogDto, Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatLogController.prototype, "exportExcel", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('chatList'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询我的问答记录' }),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, chatList_dto_1.ChatListDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatLogController.prototype, "chatList", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('del'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '删除我的问答记录' }),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, del_dto_1.DelDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatLogController.prototype, "del", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('delByGroupId'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '清空一组对话' }),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, delByGroup_dto_1.DelByGroupDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatLogController.prototype, "delByGroupId", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('deleteChatsAfterId'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '删除对话组中某条对话及其后的所有对话' }),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatLogController.prototype, "deleteChatsAfterId", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('byAppId'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询某个应用的问答记录' }),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, queryByAppId_dto_1.QueryByAppIdDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatLogController.prototype, "byAppId", null);
|
||||
ChatLogController = __decorate([
|
||||
(0, common_1.Controller)('chatLog'),
|
||||
(0, swagger_1.ApiTags)('ChatLog'),
|
||||
__metadata("design:paramtypes", [chatLog_service_1.ChatLogService])
|
||||
], ChatLogController);
|
||||
exports.ChatLogController = ChatLogController;
|
||||
144
AIWebQuickDeploy/dist/modules/chatLog/chatLog.entity.js
vendored
Normal file
144
AIWebQuickDeploy/dist/modules/chatLog/chatLog.entity.js
vendored
Normal file
@@ -0,0 +1,144 @@
|
||||
"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.ChatLogEntity = void 0;
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
const typeorm_1 = require("typeorm");
|
||||
let ChatLogEntity = class ChatLogEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '用户ID' }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatLogEntity.prototype, "userId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '使用的模型', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "model", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({
|
||||
comment: '使用类型1: 普通对话 2: 绘图 3: 拓展性对话',
|
||||
nullable: true,
|
||||
default: 1,
|
||||
}),
|
||||
__metadata("design:type", Number)
|
||||
], ChatLogEntity.prototype, "type", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '自定义的模型名称', nullable: true, default: 'AI' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "modelName", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '自定义的模型名称', nullable: false, default: '' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "modelAvatar", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'Ip地址', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "curIp", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '询问的问题', type: 'text', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "prompt", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '附加参数', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "extraParam", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '插件参数', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "pluginParam", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '回答的答案', type: 'text', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "answer", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '提问的token', nullable: true }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatLogEntity.prototype, "promptTokens", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '回答的token', nullable: true }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatLogEntity.prototype, "completionTokens", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '总花费的token', nullable: true }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatLogEntity.prototype, "totalTokens", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'role system user assistant', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "role", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '任务进度', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "progress", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '任务状态', nullable: true, default: 3 }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatLogEntity.prototype, "status", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '任务类型', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "action", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '对图片操作的按钮ID', type: 'text', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "customId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '绘画的ID每条不一样', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "drawId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '文件信息', nullable: true, type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "fileInfo", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '对话转语音的链接', nullable: true, type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "ttsUrl", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '是否推荐0: 默认 1: 推荐', nullable: true, default: 0 }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatLogEntity.prototype, "rec", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '分组ID', nullable: true }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatLogEntity.prototype, "groupId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '使用的应用id', nullable: true }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatLogEntity.prototype, "appId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '是否删除', default: false }),
|
||||
__metadata("design:type", Boolean)
|
||||
], ChatLogEntity.prototype, "isDelete", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '任务ID', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "taskId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '任务数据', nullable: true, type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "taskData", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '视频Url', nullable: true, type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "videoUrl", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '音频Url', nullable: true, type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "audioUrl", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '提问参考', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "promptReference", void 0);
|
||||
ChatLogEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'chatlog' })
|
||||
], ChatLogEntity);
|
||||
exports.ChatLogEntity = ChatLogEntity;
|
||||
30
AIWebQuickDeploy/dist/modules/chatLog/chatLog.module.js
vendored
Normal file
30
AIWebQuickDeploy/dist/modules/chatLog/chatLog.module.js
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
"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.ChatLogModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const chatGroup_entity_1 = require("../chatGroup/chatGroup.entity");
|
||||
const user_entity_1 = require("../user/user.entity");
|
||||
const chatLog_controller_1 = require("./chatLog.controller");
|
||||
const chatLog_entity_1 = require("./chatLog.entity");
|
||||
const chatLog_service_1 = require("./chatLog.service");
|
||||
let ChatLogModule = class ChatLogModule {
|
||||
};
|
||||
ChatLogModule = __decorate([
|
||||
(0, common_1.Global)(),
|
||||
(0, common_1.Module)({
|
||||
imports: [
|
||||
typeorm_1.TypeOrmModule.forFeature([chatLog_entity_1.ChatLogEntity, user_entity_1.UserEntity, chatGroup_entity_1.ChatGroupEntity]),
|
||||
],
|
||||
controllers: [chatLog_controller_1.ChatLogController],
|
||||
providers: [chatLog_service_1.ChatLogService],
|
||||
exports: [chatLog_service_1.ChatLogService],
|
||||
})
|
||||
], ChatLogModule);
|
||||
exports.ChatLogModule = ChatLogModule;
|
||||
390
AIWebQuickDeploy/dist/modules/chatLog/chatLog.service.js
vendored
Normal file
390
AIWebQuickDeploy/dist/modules/chatLog/chatLog.service.js
vendored
Normal file
@@ -0,0 +1,390 @@
|
||||
"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.ChatLogService = void 0;
|
||||
const balance_constant_1 = require("../../common/constants/balance.constant");
|
||||
const utils_1 = require("../../common/utils");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const exceljs_1 = require("exceljs");
|
||||
const typeorm_2 = require("typeorm");
|
||||
const chatGroup_entity_1 = require("../chatGroup/chatGroup.entity");
|
||||
const user_entity_1 = require("../user/user.entity");
|
||||
const chatLog_entity_1 = require("./chatLog.entity");
|
||||
const models_service_1 = require("../models/models.service");
|
||||
let ChatLogService = class ChatLogService {
|
||||
constructor(chatLogEntity, userEntity, chatGroupEntity, modelsService) {
|
||||
this.chatLogEntity = chatLogEntity;
|
||||
this.userEntity = userEntity;
|
||||
this.chatGroupEntity = chatGroupEntity;
|
||||
this.modelsService = modelsService;
|
||||
}
|
||||
async saveChatLog(logInfo) {
|
||||
const savedLog = await this.chatLogEntity.save(logInfo);
|
||||
return savedLog;
|
||||
}
|
||||
async updateChatLog(id, logInfo) {
|
||||
return await this.chatLogEntity.update({ id }, logInfo);
|
||||
}
|
||||
async findOneChatLog(id) {
|
||||
return await this.chatLogEntity.findOne({ where: { id } });
|
||||
}
|
||||
async querDrawLog(req, query) {
|
||||
const { id } = req.user;
|
||||
const { model } = query;
|
||||
const where = { userId: id, type: balance_constant_1.ChatType.PAINT };
|
||||
if (model) {
|
||||
where.model = model;
|
||||
if (model === 'DALL-E2') {
|
||||
where.model = (0, typeorm_2.In)(['DALL-E2', 'dall-e-3']);
|
||||
}
|
||||
}
|
||||
const data = await this.chatLogEntity.find({
|
||||
where,
|
||||
order: { id: 'DESC' },
|
||||
select: ['id', 'answer', 'prompt', 'model', 'type', 'fileInfo'],
|
||||
});
|
||||
data.forEach((r) => {
|
||||
if (r.type === 'paintCount') {
|
||||
const w = r.model === 'mj' ? 310 : 160;
|
||||
const imgType = r.answer.includes('cos') ? 'tencent' : 'ali';
|
||||
const compress = imgType === 'tencent'
|
||||
? `?imageView2/1/w/${w}/q/55`
|
||||
: `?x-oss-process=image/resize,w_${w}`;
|
||||
r.thumbImg = r.answer + compress;
|
||||
try {
|
||||
r.fileInfo = r.fileInfo ? JSON.parse(r.fileInfo) : null;
|
||||
}
|
||||
catch (error) {
|
||||
r.fileInfo = {};
|
||||
}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}
|
||||
async querAllDrawLog(params) {
|
||||
const { page = 1, size = 20, rec, userId, model } = params;
|
||||
const where = {
|
||||
type: 2,
|
||||
prompt: (0, typeorm_2.Not)(''),
|
||||
answer: (0, typeorm_2.Not)(''),
|
||||
fileInfo: (0, typeorm_2.Not)(''),
|
||||
};
|
||||
rec && Object.assign(where, { rec });
|
||||
userId && Object.assign(where, { userId });
|
||||
if (model) {
|
||||
where.model = model;
|
||||
}
|
||||
else {
|
||||
where.model = (0, typeorm_2.In)(['midjourney', 'dall-e-3', 'stable-diffusion']);
|
||||
}
|
||||
const [rows, count] = await this.chatLogEntity.findAndCount({
|
||||
order: { id: 'DESC' },
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
where,
|
||||
});
|
||||
const userIds = rows
|
||||
.map((item) => item.userId)
|
||||
.filter((id) => id < 100000);
|
||||
const userInfos = await this.userEntity.find({
|
||||
where: { id: (0, typeorm_2.In)(userIds) },
|
||||
select: ['id', 'username', 'avatar', 'email'],
|
||||
});
|
||||
rows.forEach((item) => {
|
||||
item.userInfo = userInfos.find((user) => user.id === item.userId);
|
||||
});
|
||||
rows.forEach((r) => {
|
||||
var _a;
|
||||
const w = r.model === 'midjourney' ? 310 : 160;
|
||||
const imgType = r.answer.includes('cos') ? 'tencent' : 'ali';
|
||||
const compress = imgType === 'tencent'
|
||||
? `?imageView2/1/w/${w}/q/55`
|
||||
: `?x-oss-process=image/resize,w_${w}`;
|
||||
r.thumbImg = r.answer + compress;
|
||||
try {
|
||||
const detailInfo = r.extend ? JSON.parse(r.extend) : null;
|
||||
if (detailInfo) {
|
||||
if (detailInfo) {
|
||||
r.isGroup = ((_a = detailInfo === null || detailInfo === void 0 ? void 0 : detailInfo.components[0]) === null || _a === void 0 ? void 0 : _a.components.length) === 5;
|
||||
}
|
||||
else {
|
||||
r.isGroup = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.log('querAllDrawLog Json parse error', error);
|
||||
}
|
||||
});
|
||||
return { rows, count };
|
||||
}
|
||||
async findOneDrawLog(params) {
|
||||
const { id } = params;
|
||||
const record = await this.chatLogEntity.findOne({ where: { id } });
|
||||
return record;
|
||||
}
|
||||
async recDrawImg(body) {
|
||||
const { id } = body;
|
||||
const l = await this.chatLogEntity.findOne({
|
||||
where: { id, type: balance_constant_1.ChatType.PAINT },
|
||||
});
|
||||
if (!l) {
|
||||
throw new common_1.HttpException('你推荐的图片不存在、请检查!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const rec = l.rec === 1 ? 0 : 1;
|
||||
const res = await this.chatLogEntity.update({ id }, { rec });
|
||||
if (res.affected > 0) {
|
||||
return `${rec ? '推荐' : '取消推荐'}图片成功!`;
|
||||
}
|
||||
throw new common_1.HttpException('你操作的图片不存在、请检查!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
async exportExcel(body, res) {
|
||||
const where = { type: balance_constant_1.ChatType.NORMAL_CHAT };
|
||||
const { page = 1, size = 30, prompt, email } = body;
|
||||
prompt && Object.assign(where, { prompt: (0, typeorm_2.Like)(`%${prompt}%`) });
|
||||
if (email) {
|
||||
const user = await this.userEntity.findOne({ where: { email } });
|
||||
(user === null || user === void 0 ? void 0 : user.id) && Object.assign(where, { userId: user.id });
|
||||
}
|
||||
const [rows, count] = await this.chatLogEntity.findAndCount({
|
||||
order: { id: 'DESC' },
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
where,
|
||||
});
|
||||
const userIds = rows.map((r) => r.userId);
|
||||
const userInfos = await this.userEntity.find({
|
||||
where: { id: (0, typeorm_2.In)(userIds) },
|
||||
});
|
||||
const data = rows.map((r) => {
|
||||
const userInfo = userInfos.find((u) => u.id === r.userId);
|
||||
return {
|
||||
username: userInfo ? userInfo.username : '',
|
||||
email: userInfo ? userInfo.email : '',
|
||||
prompt: r.prompt,
|
||||
answer: r.answer,
|
||||
createdAt: (0, utils_1.formatDate)(r.createdAt),
|
||||
};
|
||||
});
|
||||
const workbook = new exceljs_1.default.Workbook();
|
||||
const worksheet = workbook.addWorksheet('chatlog');
|
||||
worksheet.columns = [
|
||||
{ header: '用户名', key: 'username', width: 20 },
|
||||
{ header: '用户邮箱', key: 'email', width: 20 },
|
||||
{ header: '提问时间', key: 'createdAt', width: 20 },
|
||||
{ header: '提问问题', key: 'prompt', width: 80 },
|
||||
{ header: '回答答案', key: 'answer', width: 150 },
|
||||
];
|
||||
data.forEach((row) => worksheet.addRow(row));
|
||||
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=' + 'chat.xlsx');
|
||||
await workbook.xlsx.write(res);
|
||||
res.end();
|
||||
}
|
||||
async querAllChatLog(params, req) {
|
||||
const { page = 1, size = 20, userId, prompt } = params;
|
||||
const where = { type: balance_constant_1.ChatType.NORMAL_CHAT, prompt: (0, typeorm_2.Not)('') };
|
||||
userId && Object.assign(where, { userId });
|
||||
prompt && Object.assign(where, { prompt: (0, typeorm_2.Like)(`%${prompt}%`) });
|
||||
const [rows, count] = await this.chatLogEntity.findAndCount({
|
||||
order: { id: 'DESC' },
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
where,
|
||||
});
|
||||
const userIds = rows.map((item) => item.userId);
|
||||
const userInfo = await this.userEntity.find({
|
||||
where: { id: (0, typeorm_2.In)(userIds) },
|
||||
select: ['id', 'username', 'email'],
|
||||
});
|
||||
rows.forEach((item) => {
|
||||
const { username, email } = userInfo.find((u) => u.id === item.userId) || {};
|
||||
item.username = username;
|
||||
item.email = email;
|
||||
});
|
||||
req.user.role !== 'super' &&
|
||||
rows.forEach((t) => (t.email = (0, utils_1.maskEmail)(t.email)));
|
||||
rows.forEach((item) => {
|
||||
!item.email && (item.email = `${item === null || item === void 0 ? void 0 : item.userId}@aiweb.com`);
|
||||
!item.username && (item.username = `游客${item === null || item === void 0 ? void 0 : item.userId}`);
|
||||
});
|
||||
return { rows, count };
|
||||
}
|
||||
async chatList(req, params) {
|
||||
const { id } = req.user;
|
||||
const { groupId } = params;
|
||||
const where = { userId: id, isDelete: false };
|
||||
groupId && Object.assign(where, { groupId });
|
||||
if (groupId) {
|
||||
const count = await this.chatGroupEntity.count({
|
||||
where: { isDelete: false },
|
||||
});
|
||||
if (count === 0)
|
||||
return [];
|
||||
}
|
||||
const list = await this.chatLogEntity.find({ where });
|
||||
return list.map((item) => {
|
||||
const { prompt, role, answer, createdAt, model, modelName, type, status, action, drawId, id, fileInfo, ttsUrl, videoUrl, audioUrl, customId, pluginParam, modelAvatar, taskData, promptReference, } = item;
|
||||
return {
|
||||
chatId: id,
|
||||
dateTime: (0, utils_1.formatDate)(createdAt),
|
||||
text: role === 'user' ? prompt : answer,
|
||||
modelType: type,
|
||||
status: status,
|
||||
action: action,
|
||||
drawId: drawId,
|
||||
customId: customId,
|
||||
inversion: role === 'user',
|
||||
error: false,
|
||||
fileInfo: fileInfo,
|
||||
ttsUrl: ttsUrl,
|
||||
videoUrl: videoUrl,
|
||||
audioUrl: audioUrl,
|
||||
model: model,
|
||||
modelName: modelName,
|
||||
pluginParam: pluginParam,
|
||||
modelAvatar: modelAvatar,
|
||||
taskData: taskData,
|
||||
promptReference: promptReference,
|
||||
};
|
||||
});
|
||||
}
|
||||
async chatHistory(groupId, rounds) {
|
||||
if (rounds === 0) {
|
||||
return [];
|
||||
}
|
||||
const where = { isDelete: false, groupId: groupId };
|
||||
const list = await this.chatLogEntity.find({
|
||||
where,
|
||||
order: {
|
||||
createdAt: 'DESC',
|
||||
},
|
||||
take: rounds * 2,
|
||||
});
|
||||
const result = list
|
||||
.map((item) => {
|
||||
const { role, prompt, answer, fileInfo } = item;
|
||||
const record = {
|
||||
role: role,
|
||||
text: role === 'user' ? prompt : answer,
|
||||
fileInfo: fileInfo,
|
||||
};
|
||||
return record;
|
||||
})
|
||||
.reverse();
|
||||
return result;
|
||||
}
|
||||
async deleteChatLog(req, body) {
|
||||
const { id: userId } = req.user;
|
||||
const { id } = body;
|
||||
const c = await this.chatLogEntity.findOne({ where: { id, userId } });
|
||||
if (!c) {
|
||||
throw new common_1.HttpException('你删除的对话记录不存在、请检查!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const r = await this.chatLogEntity.update({ id }, { isDelete: true });
|
||||
if (r.affected > 0) {
|
||||
return '删除对话记录成功!';
|
||||
}
|
||||
else {
|
||||
throw new common_1.HttpException('你删除的对话记录不存在、请检查!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
async delByGroupId(req, body) {
|
||||
const { groupId } = body;
|
||||
const { id } = req.user;
|
||||
const g = await this.chatGroupEntity.findOne({
|
||||
where: { id: groupId, userId: id },
|
||||
});
|
||||
if (!g) {
|
||||
throw new common_1.HttpException('你删除的对话记录不存在、请检查!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const r = await this.chatLogEntity.update({ groupId }, { isDelete: true });
|
||||
if (r.affected > 0) {
|
||||
return '删除对话记录成功!';
|
||||
}
|
||||
if (r.affected === 0) {
|
||||
throw new common_1.HttpException('当前页面已经没有东西可以删除了!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
async deleteChatsAfterId(req, body) {
|
||||
const { id } = body;
|
||||
const { id: userId } = req.user;
|
||||
const chatLog = await this.chatLogEntity.findOne({ where: { id, userId } });
|
||||
if (!chatLog) {
|
||||
throw new common_1.HttpException('你删除的对话记录不存在、请检查!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const { groupId } = chatLog;
|
||||
const result = await this.chatLogEntity.update({ groupId, id: (0, typeorm_2.MoreThanOrEqual)(id) }, { isDelete: true });
|
||||
if (result.affected > 0) {
|
||||
return '删除对话记录成功!';
|
||||
}
|
||||
else {
|
||||
throw new common_1.HttpException('当前页面已经没有东西可以删除了!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
async byAppId(req, body) {
|
||||
const { id } = req.user;
|
||||
const { appId, page = 1, size = 10 } = body;
|
||||
const [rows, count] = await this.chatLogEntity.findAndCount({
|
||||
where: { userId: id, appId, role: 'assistant' },
|
||||
order: { id: 'DESC' },
|
||||
take: size,
|
||||
skip: (page - 1) * size,
|
||||
});
|
||||
return { rows, count };
|
||||
}
|
||||
async checkModelLimits(userId, model) {
|
||||
const ONE_HOUR_IN_MS = 3600 * 1000;
|
||||
const oneHourAgo = new Date(Date.now() - ONE_HOUR_IN_MS);
|
||||
try {
|
||||
const usageCount = await this.chatLogEntity.count({
|
||||
where: {
|
||||
userId: userId.id,
|
||||
model,
|
||||
createdAt: (0, typeorm_2.MoreThan)(oneHourAgo),
|
||||
},
|
||||
});
|
||||
const adjustedUsageCount = Math.ceil(usageCount / 2);
|
||||
common_1.Logger.log(`用户ID: ${userId.id} 一小时内调用 ${model} 模型 ${adjustedUsageCount + 1} 次`, 'ChatLogService');
|
||||
let modelInfo;
|
||||
if (model.startsWith('gpt-4-gizmo')) {
|
||||
modelInfo = await this.modelsService.getCurrentModelKeyInfo('gpts');
|
||||
}
|
||||
else {
|
||||
modelInfo = await this.modelsService.getCurrentModelKeyInfo(model);
|
||||
}
|
||||
const modelLimits = Number(modelInfo.modelLimits);
|
||||
common_1.Logger.log(`模型 ${model} 的使用次数限制为 ${modelLimits}`, 'ChatLogService');
|
||||
if (adjustedUsageCount > modelLimits) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`查询数据库出错 - 用户ID: ${userId.id}, 模型: ${model}, 错误信息: ${error.message}`, error.stack, 'ChatLogService');
|
||||
}
|
||||
}
|
||||
};
|
||||
ChatLogService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__param(0, (0, typeorm_1.InjectRepository)(chatLog_entity_1.ChatLogEntity)),
|
||||
__param(1, (0, typeorm_1.InjectRepository)(user_entity_1.UserEntity)),
|
||||
__param(2, (0, typeorm_1.InjectRepository)(chatGroup_entity_1.ChatGroupEntity)),
|
||||
__metadata("design:paramtypes", [typeorm_2.Repository,
|
||||
typeorm_2.Repository,
|
||||
typeorm_2.Repository,
|
||||
models_service_1.ModelsService])
|
||||
], ChatLogService);
|
||||
exports.ChatLogService = ChatLogService;
|
||||
22
AIWebQuickDeploy/dist/modules/chatLog/dto/chatList.dto.js
vendored
Normal file
22
AIWebQuickDeploy/dist/modules/chatLog/dto/chatList.dto.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"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.ChatListDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class ChatListDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '对话分组ID', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], ChatListDto.prototype, "groupId", void 0);
|
||||
exports.ChatListDto = ChatListDto;
|
||||
20
AIWebQuickDeploy/dist/modules/chatLog/dto/del.dto.js
vendored
Normal file
20
AIWebQuickDeploy/dist/modules/chatLog/dto/del.dto.js
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
"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.DelDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class DelDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '对话Id', required: true }),
|
||||
__metadata("design:type", Number)
|
||||
], DelDto.prototype, "id", void 0);
|
||||
exports.DelDto = DelDto;
|
||||
20
AIWebQuickDeploy/dist/modules/chatLog/dto/delByGroup.dto.js
vendored
Normal file
20
AIWebQuickDeploy/dist/modules/chatLog/dto/delByGroup.dto.js
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
"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.DelByGroupDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class DelByGroupDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '对话组Id', required: true }),
|
||||
__metadata("design:type", Number)
|
||||
], DelByGroupDto.prototype, "groupId", void 0);
|
||||
exports.DelByGroupDto = DelByGroupDto;
|
||||
37
AIWebQuickDeploy/dist/modules/chatLog/dto/exportExcelChatlog.dto.js
vendored
Normal file
37
AIWebQuickDeploy/dist/modules/chatLog/dto/exportExcelChatlog.dto.js
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
"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.ExportExcelChatlogDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class ExportExcelChatlogDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], ExportExcelChatlogDto.prototype, "page", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], ExportExcelChatlogDto.prototype, "size", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '您好', description: '用户询问的问题', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], ExportExcelChatlogDto.prototype, "prompt", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'J_longyan@163.com', description: '用户邮箱', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], ExportExcelChatlogDto.prototype, "email", void 0);
|
||||
exports.ExportExcelChatlogDto = ExportExcelChatlogDto;
|
||||
41
AIWebQuickDeploy/dist/modules/chatLog/dto/queryAllChatLog.dto.js
vendored
Normal file
41
AIWebQuickDeploy/dist/modules/chatLog/dto/queryAllChatLog.dto.js
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
"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.QuerAllChatLogDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class QuerAllChatLogDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAllChatLogDto.prototype, "page", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAllChatLogDto.prototype, "size", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 99, description: '对话的用户id', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAllChatLogDto.prototype, "userId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '您好', description: '用户询问的问题', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QuerAllChatLogDto.prototype, "prompt", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'user', description: '身份', required: false }),
|
||||
__metadata("design:type", String)
|
||||
], QuerAllChatLogDto.prototype, "role", void 0);
|
||||
exports.QuerAllChatLogDto = QuerAllChatLogDto;
|
||||
42
AIWebQuickDeploy/dist/modules/chatLog/dto/queryAllDrawLog.dto.js
vendored
Normal file
42
AIWebQuickDeploy/dist/modules/chatLog/dto/queryAllDrawLog.dto.js
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
"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.QuerAllDrawLogDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class QuerAllDrawLogDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAllDrawLogDto.prototype, "page", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAllDrawLogDto.prototype, "size", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '是否推荐0: 默认 1: 推荐', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAllDrawLogDto.prototype, "rec", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 99, description: '生成图片的用户id', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAllDrawLogDto.prototype, "userId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'DALL-E2', description: '生成图片使用的模型', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QuerAllDrawLogDto.prototype, "model", void 0);
|
||||
exports.QuerAllDrawLogDto = QuerAllDrawLogDto;
|
||||
32
AIWebQuickDeploy/dist/modules/chatLog/dto/queryByAppId.dto.js
vendored
Normal file
32
AIWebQuickDeploy/dist/modules/chatLog/dto/queryByAppId.dto.js
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
"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.QueryByAppIdDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class QueryByAppIdDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '应用Id', required: true }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QueryByAppIdDto.prototype, "appId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QueryByAppIdDto.prototype, "page", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QueryByAppIdDto.prototype, "size", void 0);
|
||||
exports.QueryByAppIdDto = QueryByAppIdDto;
|
||||
22
AIWebQuickDeploy/dist/modules/chatLog/dto/queryMyChatLog.dto.js
vendored
Normal file
22
AIWebQuickDeploy/dist/modules/chatLog/dto/queryMyChatLog.dto.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"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.QuerMyChatLogDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class QuerMyChatLogDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'mj', description: '使用的模型', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QuerMyChatLogDto.prototype, "model", void 0);
|
||||
exports.QuerMyChatLogDto = QuerMyChatLogDto;
|
||||
20
AIWebQuickDeploy/dist/modules/chatLog/dto/recDrawImg.dto.js
vendored
Normal file
20
AIWebQuickDeploy/dist/modules/chatLog/dto/recDrawImg.dto.js
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
"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.recDrawImgDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class recDrawImgDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '推荐图片的id' }),
|
||||
__metadata("design:type", Number)
|
||||
], recDrawImgDto.prototype, "id", void 0);
|
||||
exports.recDrawImgDto = recDrawImgDto;
|
||||
168
AIWebQuickDeploy/dist/modules/crami/crami.controller.js
vendored
Normal file
168
AIWebQuickDeploy/dist/modules/crami/crami.controller.js
vendored
Normal file
@@ -0,0 +1,168 @@
|
||||
"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.CramiController = void 0;
|
||||
const crami_service_1 = require("./crami.service");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const createPackage_dto_1 = require("./dto/createPackage.dto");
|
||||
const updatePackage_dto_1 = require("./dto/updatePackage.dto");
|
||||
const createCrami_dto_1 = require("./dto/createCrami.dto");
|
||||
const superAuth_guard_1 = require("../../common/auth/superAuth.guard");
|
||||
const jwtAuth_guard_1 = require("../../common/auth/jwtAuth.guard");
|
||||
const useCrami_dto_1 = require("./dto/useCrami.dto");
|
||||
const queryAllPackage_dto_1 = require("./dto/queryAllPackage.dto");
|
||||
const deletePackage_dto_1 = require("./dto/deletePackage.dto");
|
||||
const queryAllCrami_dto_1 = require("./dto/queryAllCrami.dto");
|
||||
const adminAuth_guard_1 = require("../../common/auth/adminAuth.guard");
|
||||
const batchDelCrami_dto_1 = require("./dto/batchDelCrami.dto");
|
||||
let CramiController = class CramiController {
|
||||
constructor(cramiService) {
|
||||
this.cramiService = cramiService;
|
||||
}
|
||||
async queryOnePackage(id) {
|
||||
return this.cramiService.queryOnePackage(id);
|
||||
}
|
||||
async queryAllPackage(query) {
|
||||
return this.cramiService.queryAllPackage(query);
|
||||
}
|
||||
async createPackage(body) {
|
||||
return this.cramiService.createPackage(body);
|
||||
}
|
||||
async updatePackage(body) {
|
||||
return this.cramiService.updatePackage(body);
|
||||
}
|
||||
async delPackage(body) {
|
||||
return this.cramiService.delPackage(body);
|
||||
}
|
||||
async createCrami(body) {
|
||||
return this.cramiService.createCrami(body);
|
||||
}
|
||||
async useCrami(req, body) {
|
||||
return this.cramiService.useCrami(req, body);
|
||||
}
|
||||
async queryAllCrami(params, req) {
|
||||
return this.cramiService.queryAllCrami(params, req);
|
||||
}
|
||||
async delCrami(id) {
|
||||
return this.cramiService.delCrami(id);
|
||||
}
|
||||
async batchDelCrami(body) {
|
||||
return this.cramiService.batchDelCrami(body);
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Get)('queryOnePackage'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询单个套餐' }),
|
||||
__param(0, (0, common_1.Query)('id')),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Number]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], CramiController.prototype, "queryOnePackage", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('queryAllPackage'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询所有套餐' }),
|
||||
__param(0, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [queryAllPackage_dto_1.QuerAllPackageDto]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], CramiController.prototype, "queryAllPackage", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('createPackage'),
|
||||
(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", [createPackage_dto_1.CreatePackageDto]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], CramiController.prototype, "createPackage", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('updatePackage'),
|
||||
(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", [updatePackage_dto_1.UpdatePackageDto]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], CramiController.prototype, "updatePackage", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('delPackage'),
|
||||
(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", [deletePackage_dto_1.DeletePackageDto]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], CramiController.prototype, "delPackage", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('createCrami'),
|
||||
(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", [createCrami_dto_1.CreatCramiDto]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], CramiController.prototype, "createCrami", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('useCrami'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '使用卡密' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, useCrami_dto_1.UseCramiDto]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], CramiController.prototype, "useCrami", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('queryAllCrami'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询所有卡密' }),
|
||||
(0, common_1.UseGuards)(adminAuth_guard_1.AdminAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Query)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [queryAllCrami_dto_1.QuerAllCramiDto, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], CramiController.prototype, "queryAllCrami", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('delCrami'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '删除卡密' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)('id')),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Number]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], CramiController.prototype, "delCrami", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('batchDelCrami'),
|
||||
(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", [batchDelCrami_dto_1.BatchDelCramiDto]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], CramiController.prototype, "batchDelCrami", null);
|
||||
CramiController = __decorate([
|
||||
(0, swagger_1.ApiTags)('Crami'),
|
||||
(0, common_1.Controller)('crami'),
|
||||
__metadata("design:paramtypes", [crami_service_1.CramiService])
|
||||
], CramiController);
|
||||
exports.CramiController = CramiController;
|
||||
56
AIWebQuickDeploy/dist/modules/crami/crami.entity.js
vendored
Normal file
56
AIWebQuickDeploy/dist/modules/crami/crami.entity.js
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
"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.CramiEntity = void 0;
|
||||
const typeorm_1 = require("typeorm");
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
let CramiEntity = class CramiEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ unique: true, comment: '存储卡密CDK编码', length: 50 }),
|
||||
__metadata("design:type", String)
|
||||
], CramiEntity.prototype, "code", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '卡密CDK类型:1: 普通 | 2: 单人可使用一次 ', default: 1 }),
|
||||
__metadata("design:type", Number)
|
||||
], CramiEntity.prototype, "cramiType", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '卡密CDK类型: 默认套餐类型 | 不填就是自定义类型', nullable: true }),
|
||||
__metadata("design:type", Number)
|
||||
], CramiEntity.prototype, "packageId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '卡密CDK状态,如已使用、未使用等', default: 0 }),
|
||||
__metadata("design:type", Number)
|
||||
], CramiEntity.prototype, "status", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '卡密使用账户用户ID信息', nullable: true }),
|
||||
__metadata("design:type", Number)
|
||||
], CramiEntity.prototype, "useId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '卡密有效期天数、从生成创建的时候开始计算,设为0则不限时间', default: 0 }),
|
||||
__metadata("design:type", Number)
|
||||
], CramiEntity.prototype, "days", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '卡密模型3额度', nullable: true }),
|
||||
__metadata("design:type", Number)
|
||||
], CramiEntity.prototype, "model3Count", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '卡密模型4额度', nullable: true }),
|
||||
__metadata("design:type", Number)
|
||||
], CramiEntity.prototype, "model4Count", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '卡密MJ绘画额度', nullable: true }),
|
||||
__metadata("design:type", Number)
|
||||
], CramiEntity.prototype, "drawMjCount", void 0);
|
||||
CramiEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'crami' })
|
||||
], CramiEntity);
|
||||
exports.CramiEntity = CramiEntity;
|
||||
49
AIWebQuickDeploy/dist/modules/crami/crami.module.js
vendored
Normal file
49
AIWebQuickDeploy/dist/modules/crami/crami.module.js
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
"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.CramiModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const chatGroup_entity_1 = require("../chatGroup/chatGroup.entity");
|
||||
const chatLog_entity_1 = require("../chatLog/chatLog.entity");
|
||||
const config_entity_1 = require("../globalConfig/config.entity");
|
||||
const user_entity_1 = require("../user/user.entity");
|
||||
const accountLog_entity_1 = require("../userBalance/accountLog.entity");
|
||||
const balance_entity_1 = require("../userBalance/balance.entity");
|
||||
const fingerprint_entity_1 = require("../userBalance/fingerprint.entity");
|
||||
const userBalance_entity_1 = require("../userBalance/userBalance.entity");
|
||||
const userBalance_service_1 = require("../userBalance/userBalance.service");
|
||||
const crami_controller_1 = require("./crami.controller");
|
||||
const crami_entity_1 = require("./crami.entity");
|
||||
const crami_service_1 = require("./crami.service");
|
||||
const cramiPackage_entity_1 = require("./cramiPackage.entity");
|
||||
let CramiModule = class CramiModule {
|
||||
};
|
||||
CramiModule = __decorate([
|
||||
(0, common_1.Global)(),
|
||||
(0, common_1.Module)({
|
||||
imports: [
|
||||
typeorm_1.TypeOrmModule.forFeature([
|
||||
crami_entity_1.CramiEntity,
|
||||
cramiPackage_entity_1.CramiPackageEntity,
|
||||
user_entity_1.UserEntity,
|
||||
balance_entity_1.BalanceEntity,
|
||||
accountLog_entity_1.AccountLogEntity,
|
||||
config_entity_1.ConfigEntity,
|
||||
userBalance_entity_1.UserBalanceEntity,
|
||||
fingerprint_entity_1.FingerprintLogEntity,
|
||||
chatLog_entity_1.ChatLogEntity,
|
||||
chatGroup_entity_1.ChatGroupEntity,
|
||||
]),
|
||||
],
|
||||
providers: [crami_service_1.CramiService, userBalance_service_1.UserBalanceService],
|
||||
controllers: [crami_controller_1.CramiController],
|
||||
exports: [crami_service_1.CramiService],
|
||||
})
|
||||
], CramiModule);
|
||||
exports.CramiModule = CramiModule;
|
||||
214
AIWebQuickDeploy/dist/modules/crami/crami.service.js
vendored
Normal file
214
AIWebQuickDeploy/dist/modules/crami/crami.service.js
vendored
Normal file
@@ -0,0 +1,214 @@
|
||||
"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.CramiService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const crami_entity_1 = require("./crami.entity");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const typeorm_2 = require("typeorm");
|
||||
const cramiPackage_entity_1 = require("./cramiPackage.entity");
|
||||
const utils_1 = require("../../common/utils");
|
||||
const user_entity_1 = require("../user/user.entity");
|
||||
const userBalance_service_1 = require("../userBalance/userBalance.service");
|
||||
const balance_constant_1 = require("../../common/constants/balance.constant");
|
||||
let CramiService = class CramiService {
|
||||
constructor(cramiEntity, cramiPackageEntity, userEntity, userBalanceService) {
|
||||
this.cramiEntity = cramiEntity;
|
||||
this.cramiPackageEntity = cramiPackageEntity;
|
||||
this.userEntity = userEntity;
|
||||
this.userBalanceService = userBalanceService;
|
||||
}
|
||||
async queryOnePackage(id) {
|
||||
return await this.cramiPackageEntity.findOne({ where: { id } });
|
||||
}
|
||||
async queryAllPackage(query) {
|
||||
try {
|
||||
const { page = 1, size = 10, name, status, type } = query;
|
||||
const where = {};
|
||||
name && Object.assign(where, { name: (0, typeorm_2.Like)(`%${name}%`) });
|
||||
status && Object.assign(where, { status });
|
||||
if (type) {
|
||||
if (type > 0) {
|
||||
Object.assign(where, { days: (0, typeorm_2.MoreThan)(0) });
|
||||
}
|
||||
else {
|
||||
Object.assign(where, { days: (0, typeorm_2.LessThanOrEqual)(0) });
|
||||
}
|
||||
}
|
||||
const [rows, count] = await this.cramiPackageEntity.findAndCount({
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
where,
|
||||
order: { order: 'DESC' },
|
||||
});
|
||||
return { rows, count };
|
||||
}
|
||||
catch (error) {
|
||||
console.log('error: ', error);
|
||||
}
|
||||
}
|
||||
async createPackage(body) {
|
||||
const { name, weight } = body;
|
||||
const p = await this.cramiPackageEntity.findOne({ where: [{ name }, { weight }] });
|
||||
if (p) {
|
||||
throw new common_1.HttpException('套餐名称或套餐等级重复、请检查!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
try {
|
||||
return await this.cramiPackageEntity.save(body);
|
||||
}
|
||||
catch (error) {
|
||||
console.log('error: ', error);
|
||||
throw new common_1.HttpException(error, common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
async updatePackage(body) {
|
||||
const { id, name, weight } = body;
|
||||
const op = await this.cramiPackageEntity.findOne({ where: { id } });
|
||||
if (!op) {
|
||||
throw new common_1.HttpException('当前套餐不存在、请检查你的输入参数!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const count = await this.cramiPackageEntity.count({
|
||||
where: [
|
||||
{ name, id: (0, typeorm_2.Not)(id) },
|
||||
{ weight, id: (0, typeorm_2.Not)(id) },
|
||||
],
|
||||
});
|
||||
if (count) {
|
||||
throw new common_1.HttpException('套餐名称或套餐等级重复、请检查!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const res = await this.cramiPackageEntity.update({ id }, body);
|
||||
if (res.affected > 0) {
|
||||
return '更新套餐成功!';
|
||||
}
|
||||
else {
|
||||
throw new common_1.HttpException('更新套餐失败、请重试!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
async delPackage(body) {
|
||||
const { id } = body;
|
||||
const count = await this.cramiEntity.count({ where: { packageId: id } });
|
||||
if (count) {
|
||||
throw new common_1.HttpException('当前套餐下存在卡密、请先删除卡密后才可删除套餐!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return await this.cramiPackageEntity.delete({ id });
|
||||
}
|
||||
async createCrami(body) {
|
||||
const { packageId, count = 1 } = body;
|
||||
if (packageId) {
|
||||
const pkg = await this.cramiPackageEntity.findOne({ where: { id: packageId } });
|
||||
if (!pkg) {
|
||||
throw new common_1.HttpException('当前套餐不存在、请确认您选择的套餐是否存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const { days = -1, model3Count = 0, model4Count = 0, drawMjCount = 0 } = pkg;
|
||||
const baseCrami = { packageId, days, model3Count, model4Count, drawMjCount };
|
||||
return await this.generateCrami(baseCrami, count);
|
||||
}
|
||||
if (!packageId) {
|
||||
const { model3Count = 0, model4Count = 0, drawMjCount = 0 } = body;
|
||||
if ([model3Count, model4Count, drawMjCount].every((v) => !v)) {
|
||||
throw new common_1.HttpException('自定义卡密必须至少一项余额不为0️零!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const baseCrami = { days: -1, model3Count, model4Count, drawMjCount };
|
||||
return await this.generateCrami(baseCrami, count);
|
||||
}
|
||||
}
|
||||
async generateCrami(cramiInfo, count) {
|
||||
const cramiList = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
const code = (0, utils_1.generateCramiCode)();
|
||||
const crami = this.cramiEntity.create(Object.assign(Object.assign({}, cramiInfo), { code }));
|
||||
cramiList.push(crami);
|
||||
}
|
||||
return await this.cramiEntity.save(cramiList);
|
||||
}
|
||||
async useCrami(req, body) {
|
||||
const { id } = req.user;
|
||||
const crami = await this.cramiEntity.findOne({ where: { code: body.code } });
|
||||
if (!crami) {
|
||||
throw new common_1.HttpException('当前卡密不存在、请确认您输入的卡密是否正确!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const { status, days = -1, model3Count = 0, model4Count = 0, drawMjCount = 0, packageId } = crami;
|
||||
if (status === 1) {
|
||||
throw new common_1.HttpException('当前卡密已被使用、请确认您输入的卡密是否正确!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const balanceInfo = { model3Count, model4Count, drawMjCount, packageId };
|
||||
await this.userBalanceService.addBalanceToUser(id, Object.assign({}, balanceInfo), days);
|
||||
await this.userBalanceService.saveRecordRechargeLog({
|
||||
userId: id,
|
||||
rechargeType: balance_constant_1.RechargeType.PACKAGE_GIFT,
|
||||
model3Count,
|
||||
model4Count,
|
||||
drawMjCount,
|
||||
days,
|
||||
});
|
||||
await this.cramiEntity.update({ code: body.code }, { useId: id, status: 1 });
|
||||
return '使用卡密成功';
|
||||
}
|
||||
async queryAllCrami(params, req) {
|
||||
const { page = 1, size = 10, status, useId } = params;
|
||||
const where = {};
|
||||
status && Object.assign(where, { status });
|
||||
useId && Object.assign(where, { useId });
|
||||
const [rows, count] = await this.cramiEntity.findAndCount({
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
order: { createdAt: 'DESC' },
|
||||
where,
|
||||
});
|
||||
const userIds = rows.map((t) => t.useId);
|
||||
const packageIds = rows.map((t) => t.packageId);
|
||||
const userInfos = await this.userEntity.find({ where: { id: (0, typeorm_2.In)(userIds) } });
|
||||
const packageInfos = await this.cramiPackageEntity.find({ where: { id: (0, typeorm_2.In)(packageIds) } });
|
||||
rows.forEach((t) => {
|
||||
var _a, _b, _c;
|
||||
t.username = (_a = userInfos.find((u) => u.id === t.useId)) === null || _a === void 0 ? void 0 : _a.username;
|
||||
t.email = (_b = userInfos.find((u) => u.id === t.useId)) === null || _b === void 0 ? void 0 : _b.email;
|
||||
t.packageName = (_c = packageInfos.find((p) => p.id === t.packageId)) === null || _c === void 0 ? void 0 : _c.name;
|
||||
});
|
||||
req.user.role !== 'super' && rows.forEach((t) => (t.email = (0, utils_1.maskEmail)(t.email)));
|
||||
req.user.role !== 'super' && rows.forEach((t) => (t.code = (0, utils_1.maskCrami)(t.code)));
|
||||
return { rows, count };
|
||||
}
|
||||
async delCrami(id) {
|
||||
const c = await this.cramiEntity.findOne({ where: { id } });
|
||||
if (!c) {
|
||||
throw new common_1.HttpException('当前卡密不存在、请确认您要删除的卡密是否存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (c.status === 1) {
|
||||
throw new common_1.HttpException('当前卡密已被使用、已使用的卡密禁止删除!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return await this.cramiEntity.delete({ id });
|
||||
}
|
||||
async batchDelCrami(body) {
|
||||
const { ids } = body;
|
||||
const res = await this.cramiEntity.delete(ids);
|
||||
if (res.affected > 0) {
|
||||
return '删除卡密成功!';
|
||||
}
|
||||
else {
|
||||
throw new common_1.HttpException('删除卡密失败、请重试!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
};
|
||||
CramiService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__param(0, (0, typeorm_1.InjectRepository)(crami_entity_1.CramiEntity)),
|
||||
__param(1, (0, typeorm_1.InjectRepository)(cramiPackage_entity_1.CramiPackageEntity)),
|
||||
__param(2, (0, typeorm_1.InjectRepository)(user_entity_1.UserEntity)),
|
||||
__metadata("design:paramtypes", [typeorm_2.Repository,
|
||||
typeorm_2.Repository,
|
||||
typeorm_2.Repository,
|
||||
userBalance_service_1.UserBalanceService])
|
||||
], CramiService);
|
||||
exports.CramiService = CramiService;
|
||||
64
AIWebQuickDeploy/dist/modules/crami/cramiPackage.entity.js
vendored
Normal file
64
AIWebQuickDeploy/dist/modules/crami/cramiPackage.entity.js
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
"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.CramiPackageEntity = void 0;
|
||||
const typeorm_1 = require("typeorm");
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
let CramiPackageEntity = class CramiPackageEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ unique: true, comment: '套餐名称' }),
|
||||
__metadata("design:type", String)
|
||||
], CramiPackageEntity.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '套餐介绍详细信息' }),
|
||||
__metadata("design:type", String)
|
||||
], CramiPackageEntity.prototype, "des", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '套餐封面图片', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], CramiPackageEntity.prototype, "coverImg", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '套餐价格¥', type: 'decimal', scale: 2, precision: 10 }),
|
||||
__metadata("design:type", Number)
|
||||
], CramiPackageEntity.prototype, "price", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '套餐排序、数字越大越靠前', default: 100 }),
|
||||
__metadata("design:type", Number)
|
||||
], CramiPackageEntity.prototype, "order", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '套餐是否启用中 0:禁用 1:启用', default: 1 }),
|
||||
__metadata("design:type", Number)
|
||||
], CramiPackageEntity.prototype, "status", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '套餐权重、数字越大表示套餐等级越高越贵', unique: true }),
|
||||
__metadata("design:type", Number)
|
||||
], CramiPackageEntity.prototype, "weight", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '卡密有效期天数、从使用的时候开始计算,设为-1则不限时间', default: 0 }),
|
||||
__metadata("design:type", Number)
|
||||
], CramiPackageEntity.prototype, "days", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '套餐包含的模型3数量', default: 0, nullable: true }),
|
||||
__metadata("design:type", Number)
|
||||
], CramiPackageEntity.prototype, "model3Count", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '套餐包含的模型4数量', default: 0, nullable: true }),
|
||||
__metadata("design:type", Number)
|
||||
], CramiPackageEntity.prototype, "model4Count", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '套餐包含的MJ绘画数量', default: 0, nullable: true }),
|
||||
__metadata("design:type", Number)
|
||||
], CramiPackageEntity.prototype, "drawMjCount", void 0);
|
||||
CramiPackageEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'crami_package' })
|
||||
], CramiPackageEntity);
|
||||
exports.CramiPackageEntity = CramiPackageEntity;
|
||||
23
AIWebQuickDeploy/dist/modules/crami/dto/batchDelCrami.dto.js
vendored
Normal file
23
AIWebQuickDeploy/dist/modules/crami/dto/batchDelCrami.dto.js
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
"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.BatchDelCramiDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class BatchDelCramiDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '要删除的套餐Ids', required: true }),
|
||||
(0, class_validator_1.IsArray)({ message: '参数类型为数组' }),
|
||||
(0, class_validator_1.ArrayMinSize)(1, { message: '最短长度为1' }),
|
||||
__metadata("design:type", Array)
|
||||
], BatchDelCramiDto.prototype, "ids", void 0);
|
||||
exports.BatchDelCramiDto = BatchDelCramiDto;
|
||||
49
AIWebQuickDeploy/dist/modules/crami/dto/createCrami.dto.js
vendored
Normal file
49
AIWebQuickDeploy/dist/modules/crami/dto/createCrami.dto.js
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
"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.CreatCramiDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class CreatCramiDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '套餐类型', required: true }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '套餐类型必须是number' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], CreatCramiDto.prototype, "packageId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '单次生成卡密数量' }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '创建卡密的张数数量' }),
|
||||
(0, class_validator_1.Max)(50, { message: '单次创建卡密的张数数量不能超过50张' }),
|
||||
(0, class_validator_1.Min)(1, { message: '单次创建卡密的张数数量不能少于1张' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], CreatCramiDto.prototype, "count", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 0, description: '卡密携带模型3额度' }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '卡密携带的余额必须是number' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], CreatCramiDto.prototype, "model3Count", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 100, description: '卡密携带模型4额度' }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '卡密携带额度类型必须是number' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], CreatCramiDto.prototype, "model4Count", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 3, description: '卡密携带MJ绘画额度' }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '卡密携带额度类型必须是number' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], CreatCramiDto.prototype, "drawMjCount", void 0);
|
||||
exports.CreatCramiDto = CreatCramiDto;
|
||||
81
AIWebQuickDeploy/dist/modules/crami/dto/createPackage.dto.js
vendored
Normal file
81
AIWebQuickDeploy/dist/modules/crami/dto/createPackage.dto.js
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
"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.CreatePackageDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_transformer_1 = require("class-transformer");
|
||||
class CreatePackageDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '基础套餐100次卡', description: '套餐名称', required: true }),
|
||||
(0, class_validator_1.IsDefined)({ message: '套餐名称是必传参数' }),
|
||||
__metadata("design:type", String)
|
||||
], CreatePackageDto.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: '这是一个100次对话余额的套餐,我们将为您额外赠送3次绘画余额,活动期间,我们将在套餐基础上额外赠送您十次对话余额和1次绘画余额',
|
||||
description: '套餐详情描述',
|
||||
required: true,
|
||||
}),
|
||||
(0, class_validator_1.IsDefined)({ message: '套餐描述是必传参数' }),
|
||||
__metadata("design:type", String)
|
||||
], CreatePackageDto.prototype, "des", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 7, default: 0, description: '套餐等级设置' }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '套餐等级权重必须为数字' }),
|
||||
__metadata("design:type", Number)
|
||||
], CreatePackageDto.prototype, "weight", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '套餐扣费类型 1:按次数 2:按Token', required: true }),
|
||||
__metadata("design:type", Number)
|
||||
], CreatePackageDto.prototype, "deductionType", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'https://xxxx.png', description: '套餐封面图片' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], CreatePackageDto.prototype, "coverImg", void 0);
|
||||
__decorate([
|
||||
(0, class_transformer_1.Transform)(({ value }) => parseFloat(value)),
|
||||
__metadata("design:type", Number)
|
||||
], CreatePackageDto.prototype, "price", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 100, description: '套餐排序、数字越大越靠前' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], CreatePackageDto.prototype, "order", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '套餐状态 0:禁用 1:启用', required: true }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '套餐状态必须是Number' }),
|
||||
(0, class_validator_1.IsIn)([0, 1], { message: '套餐状态错误' }),
|
||||
__metadata("design:type", Number)
|
||||
], CreatePackageDto.prototype, "status", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 7, default: 0, description: '套餐有效期 -1为永久不过期' }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '套餐有效期天数类型必须是number' }),
|
||||
__metadata("design:type", Number)
|
||||
], CreatePackageDto.prototype, "days", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1000, default: 0, description: '模型3对话次数' }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '模型3对话次数必须是number类型' }),
|
||||
__metadata("design:type", Number)
|
||||
], CreatePackageDto.prototype, "model3Count", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, default: 0, description: '模型4对话次数' }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '模型4对话次数必须是number类型' }),
|
||||
__metadata("design:type", Number)
|
||||
], CreatePackageDto.prototype, "model4Count", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, default: 0, description: 'MJ绘画次数' }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: 'MJ绘画次数必须是number类型' }),
|
||||
__metadata("design:type", Number)
|
||||
], CreatePackageDto.prototype, "drawMjCount", void 0);
|
||||
exports.CreatePackageDto = CreatePackageDto;
|
||||
22
AIWebQuickDeploy/dist/modules/crami/dto/deletePackage.dto.js
vendored
Normal file
22
AIWebQuickDeploy/dist/modules/crami/dto/deletePackage.dto.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"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.DeletePackageDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class DeletePackageDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '要修改的套餐Id', required: true }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '套餐ID必须是Number' }),
|
||||
__metadata("design:type", Number)
|
||||
], DeletePackageDto.prototype, "id", void 0);
|
||||
exports.DeletePackageDto = DeletePackageDto;
|
||||
37
AIWebQuickDeploy/dist/modules/crami/dto/queryAllCrami.dto.js
vendored
Normal file
37
AIWebQuickDeploy/dist/modules/crami/dto/queryAllCrami.dto.js
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
"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.QuerAllCramiDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class QuerAllCramiDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAllCramiDto.prototype, "page", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAllCramiDto.prototype, "size", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '使用人Id', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAllCramiDto.prototype, "useId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '卡密状态 0:未使用 1:已消费', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAllCramiDto.prototype, "status", void 0);
|
||||
exports.QuerAllCramiDto = QuerAllCramiDto;
|
||||
42
AIWebQuickDeploy/dist/modules/crami/dto/queryAllPackage.dto.js
vendored
Normal file
42
AIWebQuickDeploy/dist/modules/crami/dto/queryAllPackage.dto.js
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
"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.QuerAllPackageDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class QuerAllPackageDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAllPackageDto.prototype, "page", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAllPackageDto.prototype, "size", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'name', description: '套餐名称', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QuerAllPackageDto.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '套餐状态 0:禁用 1:启用', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAllPackageDto.prototype, "status", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '套餐类型 -1:永久套餐 1:限时套餐', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAllPackageDto.prototype, "type", void 0);
|
||||
exports.QuerAllPackageDto = QuerAllPackageDto;
|
||||
23
AIWebQuickDeploy/dist/modules/crami/dto/updatePackage.dto.js
vendored
Normal file
23
AIWebQuickDeploy/dist/modules/crami/dto/updatePackage.dto.js
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
"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.UpdatePackageDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const createPackage_dto_1 = require("./createPackage.dto");
|
||||
class UpdatePackageDto extends createPackage_dto_1.CreatePackageDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '要修改的套餐Id', required: true }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '套餐ID必须是Number' }),
|
||||
__metadata("design:type", Number)
|
||||
], UpdatePackageDto.prototype, "id", void 0);
|
||||
exports.UpdatePackageDto = UpdatePackageDto;
|
||||
22
AIWebQuickDeploy/dist/modules/crami/dto/useCrami.dto.js
vendored
Normal file
22
AIWebQuickDeploy/dist/modules/crami/dto/useCrami.dto.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"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.UseCramiDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class UseCramiDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'ffar684rv254fs4f', description: '卡密信息', required: true }),
|
||||
(0, class_validator_1.IsDefined)({ message: '套餐名称是必传参数' }),
|
||||
__metadata("design:type", String)
|
||||
], UseCramiDto.prototype, "code", void 0);
|
||||
exports.UseCramiDto = UseCramiDto;
|
||||
50
AIWebQuickDeploy/dist/modules/database/database.module.js
vendored
Normal file
50
AIWebQuickDeploy/dist/modules/database/database.module.js
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
"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 DatabaseModule_1;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DatabaseModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const typeorm_2 = require("typeorm");
|
||||
const database_service_1 = require("./database.service");
|
||||
let DatabaseModule = DatabaseModule_1 = class DatabaseModule {
|
||||
constructor(connection) {
|
||||
this.connection = connection;
|
||||
this.logger = new common_1.Logger(DatabaseModule_1.name);
|
||||
}
|
||||
onModuleInit() {
|
||||
const { database } = this.connection.options;
|
||||
this.logger.log(`Your MySQL database named ${database} has been connected`);
|
||||
}
|
||||
};
|
||||
DatabaseModule = DatabaseModule_1 = __decorate([
|
||||
(0, common_1.Module)({
|
||||
imports: [
|
||||
typeorm_1.TypeOrmModule.forRootAsync({
|
||||
useFactory: () => ({
|
||||
type: 'mysql',
|
||||
host: process.env.DB_HOST,
|
||||
port: parseInt(process.env.DB_PORT, 10),
|
||||
username: process.env.DB_USER,
|
||||
password: process.env.DB_PASS,
|
||||
database: process.env.DB_DATABASE,
|
||||
entities: [__dirname + '/../**/*.entity{.ts,.js}'],
|
||||
logging: false,
|
||||
charset: 'utf8mb4',
|
||||
timezone: '+08:00',
|
||||
}),
|
||||
}),
|
||||
],
|
||||
providers: [database_service_1.DatabaseService],
|
||||
}),
|
||||
__metadata("design:paramtypes", [typeorm_2.DataSource])
|
||||
], DatabaseModule);
|
||||
exports.DatabaseModule = DatabaseModule;
|
||||
198
AIWebQuickDeploy/dist/modules/database/database.service.js
vendored
Normal file
198
AIWebQuickDeploy/dist/modules/database/database.service.js
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
"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.DatabaseService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const bcrypt = require("bcryptjs");
|
||||
const typeorm_1 = require("typeorm");
|
||||
let DatabaseService = class DatabaseService {
|
||||
constructor(connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
async onModuleInit() {
|
||||
await this.checkSuperAdmin();
|
||||
await this.checkSiteBaseConfig();
|
||||
}
|
||||
async checkSuperAdmin() {
|
||||
const user = await this.connection.query(`SELECT * FROM users WHERE role = 'super'`);
|
||||
if (!user || user.length === 0) {
|
||||
const superPassword = bcrypt.hashSync('123456', 10);
|
||||
const adminPassword = bcrypt.hashSync('123456', 10);
|
||||
const superEmail = 'super';
|
||||
const adminEmail = 'admin';
|
||||
const superUserinfo = {
|
||||
username: 'super',
|
||||
password: superPassword,
|
||||
status: 1,
|
||||
email: superEmail,
|
||||
sex: 1,
|
||||
role: 'super',
|
||||
};
|
||||
const adminUserinfo = {
|
||||
username: 'admin',
|
||||
password: adminPassword,
|
||||
status: 0,
|
||||
email: adminEmail,
|
||||
sex: 1,
|
||||
role: 'admin',
|
||||
};
|
||||
await this.createDefaultUser(superUserinfo);
|
||||
await this.createDefaultUser(adminUserinfo);
|
||||
}
|
||||
}
|
||||
async createDefaultUser(userInfo) {
|
||||
try {
|
||||
const { username, password, status, email, role } = userInfo;
|
||||
const user = await this.connection.query(`INSERT INTO users (username, password, status, email, role) VALUES ('${username}', '${password}', '${status}', '${email}', '${role}')`);
|
||||
const userId = user.insertId;
|
||||
await this.connection.query(`INSERT INTO balance (userId, balance, usesLeft, paintCount) VALUES ('${userId}', 0, 1000, 100)`);
|
||||
common_1.Logger.log(`初始化创建${role}用户成功、用户名为[${username}]、初始密码为[${username === 'super' ? 'super' : '123456'}] ==============> 请注意查阅`, 'DatabaseService');
|
||||
}
|
||||
catch (error) {
|
||||
console.log('error: ', error);
|
||||
throw new common_1.HttpException('创建默认超级管理员失败!', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
async checkSiteBaseConfig() {
|
||||
const keys = ['siteName', 'robotAvatar'];
|
||||
const result = await this.connection.query(`
|
||||
SELECT COUNT(*) AS count FROM config WHERE \`configKey\` IN (${keys
|
||||
.map((k) => `'${k}'`)
|
||||
.join(',')})
|
||||
`);
|
||||
const count = parseInt(result[0].count);
|
||||
if (count === 0) {
|
||||
await this.createBaseSiteConfig();
|
||||
}
|
||||
}
|
||||
async createBaseSiteConfig() {
|
||||
try {
|
||||
const code = ``;
|
||||
const noticeInfo = `
|
||||
#### AIWeb 欢迎您
|
||||
- 欢迎使用 AIWeb
|
||||
- 初始管理员账号密码 super 123456 【前台后台登录都可以修改】
|
||||
- 初始预览账号密码 admin 123456 【为后台查看账号 仅可查看部分非敏感数据】
|
||||
`;
|
||||
const defaultConfig = [
|
||||
{ configKey: 'siteName', configVal: '', public: 1, encry: 0 },
|
||||
{ configKey: 'robotAvatar', configVal: '', public: 1, encry: 0 },
|
||||
{
|
||||
configKey: 'userDefautlAvatar',
|
||||
configVal: '',
|
||||
public: 0,
|
||||
encry: 0,
|
||||
},
|
||||
{ configKey: 'baiduCode', configVal: code, public: 1, encry: 0 },
|
||||
{ configKey: 'baiduSiteId', configVal: '', public: 0, encry: 0 },
|
||||
{
|
||||
configKey: 'baiduToken',
|
||||
configVal: '',
|
||||
public: 0,
|
||||
encry: 0,
|
||||
},
|
||||
{ configKey: 'buyCramiAddress', configVal: '', public: 1, encry: 0 },
|
||||
{
|
||||
configKey: 'openaiBaseUrl',
|
||||
configVal: 'https://api.lightai.io',
|
||||
public: 0,
|
||||
encry: 0,
|
||||
},
|
||||
{ configKey: 'openaiTimeout', configVal: '300', public: 0, encry: 0 },
|
||||
{ configKey: 'openaiBaseKey', configVal: 'sk-', public: 0, encry: 0 },
|
||||
{
|
||||
configKey: 'mjTranslatePrompt',
|
||||
configVal: `Translate any given phrase from any language into English. For instance, when I input '{可爱的熊猫}', you should output '{cute panda}', with no period at the end.`,
|
||||
public: 0,
|
||||
encry: 0,
|
||||
},
|
||||
{ configKey: 'noticeInfo', configVal: noticeInfo, public: 1, encry: 0 },
|
||||
{
|
||||
configKey: 'registerSendStatus',
|
||||
configVal: '1',
|
||||
public: 1,
|
||||
encry: 0,
|
||||
},
|
||||
{
|
||||
configKey: 'registerSendModel3Count',
|
||||
configVal: '30',
|
||||
public: 1,
|
||||
encry: 0,
|
||||
},
|
||||
{
|
||||
configKey: 'registerSendModel4Count',
|
||||
configVal: '3',
|
||||
public: 1,
|
||||
encry: 0,
|
||||
},
|
||||
{
|
||||
configKey: 'registerSendDrawMjCount',
|
||||
configVal: '3',
|
||||
public: 1,
|
||||
encry: 0,
|
||||
},
|
||||
{
|
||||
configKey: 'firstRegisterSendStatus',
|
||||
configVal: '1',
|
||||
public: 1,
|
||||
encry: 0,
|
||||
},
|
||||
{
|
||||
configKey: 'firstRegisterSendRank',
|
||||
configVal: '500',
|
||||
public: 1,
|
||||
encry: 0,
|
||||
},
|
||||
{
|
||||
configKey: 'firstRregisterSendModel3Count',
|
||||
configVal: '10',
|
||||
public: 1,
|
||||
encry: 0,
|
||||
},
|
||||
{
|
||||
configKey: 'firstRregisterSendModel4Count',
|
||||
configVal: '10',
|
||||
public: 1,
|
||||
encry: 0,
|
||||
},
|
||||
{
|
||||
configKey: 'firstRregisterSendDrawMjCount',
|
||||
configVal: '10',
|
||||
public: 1,
|
||||
encry: 0,
|
||||
},
|
||||
{ configKey: 'isVerifyEmail', configVal: '1', public: 1, encry: 0 },
|
||||
{ configKey: 'model3Name', configVal: '普通积分', public: 1, encry: 0 },
|
||||
{ configKey: 'model4Name', configVal: '高级积分', public: 1, encry: 0 },
|
||||
{ configKey: 'drawMjName', configVal: '绘画积分', public: 1, encry: 0 },
|
||||
{
|
||||
configKey: 'drawingStyles',
|
||||
configVal: '油画风格,像素风格,赛博朋克,动漫,日系,超现实主义,油画,卡通,插画,海报,写实,扁平,中国风,水墨画,唯美二次元,印象派,炫彩插画,像素艺术,艺术创想,色彩主义,数字艺术',
|
||||
public: 1,
|
||||
encry: 0,
|
||||
},
|
||||
];
|
||||
const res = await this.connection.query(`INSERT INTO config (configKey, configVal, public, encry) VALUES ${defaultConfig
|
||||
.map((d) => `('${d.configKey}', '${d.configVal.replace(/'/g, "\\'")}', '${d.public}', '${d.encry}')`)
|
||||
.join(', ')}`);
|
||||
common_1.Logger.log(`初始化网站配置信息成功、如您需要修改网站配置信息,请前往管理系统系统配置设置 ==============> 请注意查阅`, 'DatabaseService');
|
||||
}
|
||||
catch (error) {
|
||||
console.log('error: ', error);
|
||||
throw new common_1.HttpException('创建默认网站配置失败!', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
};
|
||||
DatabaseService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [typeorm_1.Connection])
|
||||
], DatabaseService);
|
||||
exports.DatabaseService = DatabaseService;
|
||||
95
AIWebQuickDeploy/dist/modules/database/initDatabase.js
vendored
Normal file
95
AIWebQuickDeploy/dist/modules/database/initDatabase.js
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initDatabase = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const dotenv_1 = require("dotenv");
|
||||
const mysql = require("mysql2/promise");
|
||||
const typeorm_1 = require("typeorm");
|
||||
(0, dotenv_1.config)();
|
||||
const dataSourceOptions = {
|
||||
type: 'mysql',
|
||||
port: parseInt(process.env.DB_PORT, 10),
|
||||
host: process.env.DB_HOST,
|
||||
username: process.env.DB_USER,
|
||||
password: process.env.DB_PASS,
|
||||
database: process.env.DB_DATABASE,
|
||||
entities: [__dirname + '/../**/*.entity{.ts,.js}'],
|
||||
logging: false,
|
||||
synchronize: true,
|
||||
charset: 'utf8mb4',
|
||||
timezone: '+08:00',
|
||||
};
|
||||
async function validateDatabase() {
|
||||
const conn = await mysql.createConnection({
|
||||
host: process.env.DB_HOST,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASS,
|
||||
port: parseInt(process.env.DB_PORT, 10),
|
||||
});
|
||||
try {
|
||||
const [rows] = (await conn.execute(`SHOW DATABASES LIKE '${process.env.DB_DATABASE}'`));
|
||||
if (Array.isArray(rows) && rows.length === 0) {
|
||||
await conn.execute(`CREATE DATABASE ${process.env.DB_DATABASE}`);
|
||||
common_1.Logger.log(`数据库创建成功[${process.env.DB_DATABASE}]`, 'Database');
|
||||
}
|
||||
else {
|
||||
common_1.Logger.log(`数据库已存在[${process.env.DB_DATABASE}]`, 'Database');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error('Error during database validation:', error, 'Database');
|
||||
}
|
||||
finally {
|
||||
await conn.end();
|
||||
}
|
||||
}
|
||||
async function updateColumnType() {
|
||||
const conn = await mysql.createConnection({
|
||||
host: process.env.DB_HOST,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASS,
|
||||
port: parseInt(process.env.DB_PORT, 10),
|
||||
database: process.env.DB_DATABASE,
|
||||
});
|
||||
async function checkAndUpdateColumnType(tableName, columnName) {
|
||||
try {
|
||||
const [rows] = (await conn.execute(`SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND COLUMN_NAME = ?`, [tableName, columnName]));
|
||||
if (rows.length > 0 && rows[0].DATA_TYPE !== 'text') {
|
||||
await conn.execute(`ALTER TABLE ?? MODIFY COLUMN ?? TEXT`, [
|
||||
tableName,
|
||||
columnName,
|
||||
]);
|
||||
common_1.Logger.log(`Column ${columnName} type updated to TEXT in table ${tableName}`, 'Database');
|
||||
}
|
||||
else {
|
||||
common_1.Logger.log(`Column ${columnName} is already of type TEXT in table ${tableName}`, 'Database');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`Error updating column type in table ${tableName}:`, error);
|
||||
}
|
||||
}
|
||||
try {
|
||||
await checkAndUpdateColumnType('config', 'configVal');
|
||||
await checkAndUpdateColumnType('app', 'coverImg');
|
||||
}
|
||||
finally {
|
||||
await conn.end();
|
||||
}
|
||||
}
|
||||
async function initDatabase() {
|
||||
await validateDatabase();
|
||||
await updateColumnType();
|
||||
const dataSource = new typeorm_1.DataSource(dataSourceOptions);
|
||||
try {
|
||||
await dataSource.initialize();
|
||||
common_1.Logger.log('Database connected and synchronized successfully', 'Database');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error('Error during TypeORM initialization:', error);
|
||||
}
|
||||
finally {
|
||||
await dataSource.destroy();
|
||||
}
|
||||
}
|
||||
exports.initDatabase = initDatabase;
|
||||
46
AIWebQuickDeploy/dist/modules/globalConfig/config.entity.js
vendored
Normal file
46
AIWebQuickDeploy/dist/modules/globalConfig/config.entity.js
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
"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.ConfigEntity = void 0;
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
const typeorm_1 = require("typeorm");
|
||||
let ConfigEntity = class ConfigEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ length: 255, comment: '配置名称', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ConfigEntity.prototype, "configKey", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ type: 'text', comment: '配置内容', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ConfigEntity.prototype, "configVal", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({
|
||||
default: 0,
|
||||
comment: '配置是否公开,公开内容对前端项目展示 0:不公开 1:公开',
|
||||
}),
|
||||
__metadata("design:type", Number)
|
||||
], ConfigEntity.prototype, "public", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({
|
||||
default: 0,
|
||||
comment: '配置是否加密,加密内容仅仅super权限可看 0:不加 1:加',
|
||||
}),
|
||||
__metadata("design:type", Number)
|
||||
], ConfigEntity.prototype, "encry", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ default: 1, comment: '配置状态 0:关闭 1:启用' }),
|
||||
__metadata("design:type", Number)
|
||||
], ConfigEntity.prototype, "status", void 0);
|
||||
ConfigEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'config' })
|
||||
], ConfigEntity);
|
||||
exports.ConfigEntity = ConfigEntity;
|
||||
25
AIWebQuickDeploy/dist/modules/globalConfig/dto/queryConfig.dto.js
vendored
Normal file
25
AIWebQuickDeploy/dist/modules/globalConfig/dto/queryConfig.dto.js
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
"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.QueryConfigDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const class_transformer_1 = require("class-transformer");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class QueryConfigDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: ['siteName', 'qqNumber'], description: '想要查询的配置key' }),
|
||||
(0, class_validator_1.IsArray)(),
|
||||
(0, class_validator_1.ArrayNotEmpty)(),
|
||||
(0, class_transformer_1.Type)(() => String),
|
||||
__metadata("design:type", Array)
|
||||
], QueryConfigDto.prototype, "keys", void 0);
|
||||
exports.QueryConfigDto = QueryConfigDto;
|
||||
29
AIWebQuickDeploy/dist/modules/globalConfig/dto/setConfig.dto.js
vendored
Normal file
29
AIWebQuickDeploy/dist/modules/globalConfig/dto/setConfig.dto.js
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
"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.SetConfigDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_transformer_1 = require("class-transformer");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class SetConfigDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: [{ configKey: 'siteName', configVal: 'AIWeb' }],
|
||||
description: '设置配置信息',
|
||||
}),
|
||||
(0, class_validator_1.IsArray)(),
|
||||
(0, class_validator_1.ArrayNotEmpty)(),
|
||||
(0, class_validator_1.ValidateNested)({ each: true }),
|
||||
(0, class_transformer_1.Type)(() => Object),
|
||||
__metadata("design:type", Array)
|
||||
], SetConfigDto.prototype, "settings", void 0);
|
||||
exports.SetConfigDto = SetConfigDto;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user