This commit is contained in:
vastxie
2024-07-07 13:09:08 +08:00
parent 086e5aed3c
commit 4fef3663e4
1131 changed files with 11143 additions and 10769 deletions

View File

@@ -23,13 +23,21 @@ __decorate([
__metadata("design:type", String)
], ChatLogEntity.prototype, "model", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '使用类型1: 普通对话 2: 绘图 3: 拓展性对话', nullable: true, default: 1 }),
(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)
@@ -67,19 +75,15 @@ __decorate([
__metadata("design:type", String)
], ChatLogEntity.prototype, "role", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '当前绘制任务进度', nullable: true }),
(0, typeorm_1.Column)({ comment: '任务进度', nullable: true }),
__metadata("design:type", String)
], ChatLogEntity.prototype, "progress", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '当前绘制任务的耗时', nullable: true }),
__metadata("design:type", Number)
], ChatLogEntity.prototype, "durationSpent", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '当前绘制任务的状态', nullable: true, default: 3 }),
(0, typeorm_1.Column)({ comment: '任务状态', nullable: true, default: 3 }),
__metadata("design:type", Number)
], ChatLogEntity.prototype, "status", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: 'mj绘画的动作、绘图、放大、变换、图生图', nullable: true }),
(0, typeorm_1.Column)({ comment: '任务类型', nullable: true }),
__metadata("design:type", String)
], ChatLogEntity.prototype, "action", void 0);
__decorate([
@@ -91,11 +95,7 @@ __decorate([
__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, "drawRatio", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '对话或绘图附带的链接', nullable: true, type: 'text' }),
(0, typeorm_1.Column)({ comment: '文件信息', nullable: true, type: 'text' }),
__metadata("design:type", String)
], ChatLogEntity.prototype, "fileInfo", void 0);
__decorate([
@@ -118,6 +118,22 @@ __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);
ChatLogEntity = __decorate([
(0, typeorm_1.Entity)({ name: 'chatlog' })
], ChatLogEntity);

View File

@@ -8,19 +8,26 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChatLogModule = void 0;
const common_1 = require("@nestjs/common");
const chatLog_service_1 = require("./chatLog.service");
const typeorm_1 = require("@nestjs/typeorm");
const chatLog_entity_1 = require("./chatLog.entity");
const chatLog_controller_1 = require("./chatLog.controller");
const user_entity_1 = require("../user/user.entity");
const badwords_entity_1 = require("../badwords/badwords.entity");
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, badwords_entity_1.BadWordsEntity, chatGroup_entity_1.ChatGroupEntity])],
imports: [
typeorm_1.TypeOrmModule.forFeature([
chatLog_entity_1.ChatLogEntity,
user_entity_1.UserEntity,
badwords_entity_1.BadWordsEntity,
chatGroup_entity_1.ChatGroupEntity,
]),
],
controllers: [chatLog_controller_1.ChatLogController],
providers: [chatLog_service_1.ChatLogService],
exports: [chatLog_service_1.ChatLogService],

View File

@@ -59,7 +59,9 @@ let ChatLogService = class ChatLogService {
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}`;
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;
@@ -73,23 +75,43 @@ let ChatLogService = class ChatLogService {
}
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)(''), };
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}`;
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;
@@ -115,7 +137,9 @@ let ChatLogService = class ChatLogService {
}
async recDrawImg(body) {
const { id } = body;
const l = await this.chatLogEntity.findOne({ where: { id, type: balance_constant_1.ChatType.PAINT } });
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);
}
@@ -141,7 +165,9 @@ let ChatLogService = class ChatLogService {
where,
});
const userIds = rows.map((r) => r.userId);
const userInfos = await this.userEntity.find({ where: { id: (0, typeorm_2.In)(userIds) } });
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 {
@@ -179,15 +205,19 @@ let ChatLogService = class ChatLogService {
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'] });
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)));
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}@nine.com`);
!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 };
@@ -198,13 +228,15 @@ let ChatLogService = class ChatLogService {
const where = { userId: id, isDelete: false };
groupId && Object.assign(where, { groupId });
if (groupId) {
const count = await this.chatGroupEntity.count({ where: { isDelete: false } });
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, customId, pluginParam } = item;
const { prompt, role, answer, createdAt, model, modelName, type, status, action, drawId, id, fileInfo, ttsUrl, videoUrl, audioUrl, customId, pluginParam, modelAvatar, taskData, } = item;
return {
chatId: id,
dateTime: (0, utils_1.formatDate)(createdAt),
@@ -218,9 +250,13 @@ let ChatLogService = class ChatLogService {
error: false,
fileInfo: fileInfo,
ttsUrl: ttsUrl,
videoUrl: videoUrl,
audioUrl: audioUrl,
model: model,
modelName: modelName,
pluginParam: pluginParam,
modelAvatar: modelAvatar,
taskData: taskData,
};
});
}
@@ -232,18 +268,23 @@ let ChatLogService = class ChatLogService {
const list = await this.chatLogEntity.find({
where,
order: {
createdAt: 'DESC'
createdAt: 'DESC',
},
take: rounds * 2
take: rounds * 2,
});
return list.map((item) => {
const result = list
.map((item) => {
const { role, prompt, answer, fileInfo } = item;
return {
const record = {
role: role,
text: role === 'user' ? prompt : answer,
fileInfo: fileInfo,
};
}).reverse();
return record;
})
.reverse();
common_1.Logger.debug('处理后的结果:', JSON.stringify(result, null, 2));
return result;
}
async deleteChatLog(req, body) {
const { id: userId } = req.user;
@@ -263,7 +304,9 @@ let ChatLogService = class ChatLogService {
async delByGroupId(req, body) {
const { groupId } = body;
const { id } = req.user;
const g = await this.chatGroupEntity.findOne({ where: { id: groupId, userId: id } });
const g = await this.chatGroupEntity.findOne({
where: { id: groupId, userId: id },
});
if (!g) {
throw new common_1.HttpException('你删除的对话记录不存在、请检查!', common_1.HttpStatus.BAD_REQUEST);
}
@@ -295,7 +338,7 @@ let ChatLogService = class ChatLogService {
userId: userId.id,
model,
createdAt: (0, typeorm_2.MoreThan)(oneHourAgo),
}
},
});
adjustedUsageCount = Math.ceil(usageCount / 2);
common_1.Logger.debug(`用户ID: ${userId.id} 模型: ${model} 一小时内已调用: ${adjustedUsageCount}`);