This commit is contained in:
vastxie
2024-07-31 14:12:56 +08:00
parent dd0e1dafd5
commit c831009379
366 changed files with 1881 additions and 1540 deletions

View File

@@ -13,21 +13,21 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
};
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 jwtAuth_guard_1 = require("../../common/auth/jwtAuth.guard");
const chatLog_service_1 = require("./chatLog.service");
const queryAllDrawLog_dto_1 = require("./dto/queryAllDrawLog.dto");
const queryAllChatLog_dto_1 = require("./dto/queryAllChatLog.dto");
const recDrawImg_dto_1 = require("./dto/recDrawImg.dto");
const superAuth_guard_1 = require("../../common/auth/superAuth.guard");
const adminAuth_guard_1 = require("../../common/auth/adminAuth.guard");
const queryMyChatLog_dto_1 = require("./dto/queryMyChatLog.dto");
const exportExcelChatlog_dto_1 = require("./dto/exportExcelChatlog.dto");
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;
@@ -56,6 +56,9 @@ let ChatLogController = class ChatLogController {
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);
}
@@ -143,6 +146,17 @@ __decorate([
__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: '查询某个应用的问答记录' }),

View File

@@ -283,7 +283,6 @@ let ChatLogService = class ChatLogService {
return record;
})
.reverse();
common_1.Logger.debug('处理后的结果:', JSON.stringify(result, null, 2));
return result;
}
async deleteChatLog(req, body) {
@@ -318,6 +317,22 @@ let ChatLogService = class ChatLogService {
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;
@@ -330,8 +345,8 @@ let ChatLogService = class ChatLogService {
return { rows, count };
}
async checkModelLimits(userId, model) {
const oneHourAgo = new Date(Date.now() - 3600 * 1000);
let adjustedUsageCount;
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: {
@@ -340,15 +355,24 @@ let ChatLogService = class ChatLogService {
createdAt: (0, typeorm_2.MoreThan)(oneHourAgo),
},
});
adjustedUsageCount = Math.ceil(usageCount / 2);
common_1.Logger.debug(`用户ID: ${userId.id} 模型: ${model} 一小时内已调用: ${adjustedUsageCount}`);
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}, 模型: ${model}, 错误信息: ${error.message}`);
}
const modelInfo = await this.modelsService.getCurrentModelKeyInfo(model);
if (adjustedUsageCount > modelInfo.modelLimits) {
throw new common_1.HttpException('1 小时内请求次数过多,请稍后再试!', common_1.HttpStatus.TOO_MANY_REQUESTS);
common_1.Logger.error(`查询数据库出错 - 用户ID: ${userId.id}, 模型: ${model}, 错误信息: ${error.message}`, error.stack, 'ChatLogService');
}
}
};