YiAi/YiAiQuickDeploy/dist/modules/chatLog/chatLog.service.js
2024-02-06 13:43:30 +08:00

1 line
15 KiB
JavaScript

'use strict';const _0x32f1de=_0x336b;function _0x336b(_0x57c56e,_0x8acc7d){const _0x26b379=_0x26b3();return _0x336b=function(_0x336b62,_0x1a6373){_0x336b62=_0x336b62-0xbe;let _0x3a0a50=_0x26b379[_0x336b62];return _0x3a0a50;},_0x336b(_0x57c56e,_0x8acc7d);}(function(_0x2f6579,_0x4c513f){const _0x1c4dc1=_0x336b,_0x2aa1bb=_0x2f6579();while(!![]){try{const _0x252563=-parseInt(_0x1c4dc1(0xc9))/0x1*(-parseInt(_0x1c4dc1(0x122))/0x2)+parseInt(_0x1c4dc1(0x101))/0x3+parseInt(_0x1c4dc1(0x106))/0x4+parseInt(_0x1c4dc1(0xca))/0x5*(parseInt(_0x1c4dc1(0x114))/0x6)+parseInt(_0x1c4dc1(0xc6))/0x7+parseInt(_0x1c4dc1(0x107))/0x8+-parseInt(_0x1c4dc1(0xcf))/0x9*(parseInt(_0x1c4dc1(0x12b))/0xa);if(_0x252563===_0x4c513f)break;else _0x2aa1bb['push'](_0x2aa1bb['shift']());}catch(_0x55e939){_0x2aa1bb['push'](_0x2aa1bb['shift']());}}}(_0x26b3,0x9d5ff));var __decorate=this&&this[_0x32f1de(0xd7)]||function(_0x1c6e1f,_0x3675e1,_0x604160,_0x575ebe){const _0xbe1e14=_0x32f1de;var _0x525204=arguments['length'],_0x2816a6=_0x525204<0x3?_0x3675e1:_0x575ebe===null?_0x575ebe=Object[_0xbe1e14(0x109)](_0x3675e1,_0x604160):_0x575ebe,_0x3105c2;if(typeof Reflect===_0xbe1e14(0xc5)&&typeof Reflect[_0xbe1e14(0x11c)]===_0xbe1e14(0xf2))_0x2816a6=Reflect[_0xbe1e14(0x11c)](_0x1c6e1f,_0x3675e1,_0x604160,_0x575ebe);else{for(var _0xe194f=_0x1c6e1f['length']-0x1;_0xe194f>=0x0;_0xe194f--)if(_0x3105c2=_0x1c6e1f[_0xe194f])_0x2816a6=(_0x525204<0x3?_0x3105c2(_0x2816a6):_0x525204>0x3?_0x3105c2(_0x3675e1,_0x604160,_0x2816a6):_0x3105c2(_0x3675e1,_0x604160))||_0x2816a6;}return _0x525204>0x3&&_0x2816a6&&Object['defineProperty'](_0x3675e1,_0x604160,_0x2816a6),_0x2816a6;},__metadata=this&&this[_0x32f1de(0x127)]||function(_0x2721df,_0x4ffc1e){const _0x3ce48f=_0x32f1de;if(typeof Reflect===_0x3ce48f(0xc5)&&typeof Reflect['metadata']===_0x3ce48f(0xf2))return Reflect[_0x3ce48f(0x121)](_0x2721df,_0x4ffc1e);},__param=this&&this[_0x32f1de(0xc1)]||function(_0x873d73,_0x4f3fe4){return function(_0x370473,_0x19a1af){_0x4f3fe4(_0x370473,_0x19a1af,_0x873d73);};};Object[_0x32f1de(0xc4)](exports,_0x32f1de(0x10f),{'value':!![]}),exports[_0x32f1de(0xee)]=void 0x0;const common_1=require(_0x32f1de(0x11e)),typeorm_1=require('@nestjs/typeorm'),chatLog_entity_1=require('./chatLog.entity'),typeorm_2=require(_0x32f1de(0xfb)),balance_constant_1=require(_0x32f1de(0xf3)),user_entity_1=require(_0x32f1de(0xed)),utils_1=require(_0x32f1de(0xe5)),exceljs_1=require('exceljs'),chatGroup_entity_1=require('../chatGroup/chatGroup.entity');let ChatLogService=class ChatLogService{constructor(_0x73ccc9,_0x2d2fb4,_0x21f0aa){const _0x471dab=_0x32f1de;this['chatLogEntity']=_0x73ccc9,this[_0x471dab(0xeb)]=_0x2d2fb4,this[_0x471dab(0x125)]=_0x21f0aa;}async[_0x32f1de(0x11b)](_0x529c42){const _0x3acdfb=_0x32f1de;return await this[_0x3acdfb(0xfe)][_0x3acdfb(0xc3)](_0x529c42);}async[_0x32f1de(0x102)](_0x515498,_0x4cc1dd){const _0x4ec256=_0x32f1de,{id:_0x5c4ec}=_0x515498['user'],{model:_0x24646a}=_0x4cc1dd,_0x1d4952={'userId':_0x5c4ec,'type':balance_constant_1[_0x4ec256(0x120)][_0x4ec256(0x12d)]};_0x24646a&&(_0x1d4952[_0x4ec256(0x112)]=_0x24646a,_0x24646a===_0x4ec256(0x103)&&(_0x1d4952['model']=(0x0,typeorm_2['In'])([_0x4ec256(0x103),_0x4ec256(0xdd)])));const _0x177230=await this[_0x4ec256(0xfe)][_0x4ec256(0xf9)]({'where':_0x1d4952,'order':{'id':'DESC'},'select':['id',_0x4ec256(0x115),_0x4ec256(0xd9),_0x4ec256(0x129),_0x4ec256(0xde),_0x4ec256(0x112),_0x4ec256(0xe6),_0x4ec256(0xe8),_0x4ec256(0x117)]});return _0x177230['forEach'](_0x4903e1=>{const _0xd17ddd=_0x4ec256;if(_0x4903e1[_0xd17ddd(0xe8)]===_0xd17ddd(0xbe)){const _0x40b3bc=_0x4903e1[_0xd17ddd(0x112)]==='mj'?0x136:0xa0,_0x1563f5=_0x4903e1[_0xd17ddd(0x115)]['includes'](_0xd17ddd(0xc8))?_0xd17ddd(0xfa):'ali',_0x548902=_0x1563f5===_0xd17ddd(0xfa)?_0xd17ddd(0xfc)+_0x40b3bc+_0xd17ddd(0xc7):'?x-oss-process=image/resize,w_'+_0x40b3bc;_0x4903e1['thumbImg']=_0x4903e1['answer']+_0x548902;try{_0x4903e1['fileInfo']=_0x4903e1[_0xd17ddd(0x117)]?JSON[_0xd17ddd(0x12a)](_0x4903e1[_0xd17ddd(0x117)]):null;}catch(_0x329abc){_0x4903e1[_0xd17ddd(0x117)]={};}}}),_0x177230;}async[_0x32f1de(0xdc)](_0x302440){const _0x4febb0=_0x32f1de,{page:page=0x1,size:size=0x14,rec:_0x1a5ab3,userId:_0x3917f8,model:_0x2049d1}=_0x302440,_0x4faf94={'type':balance_constant_1['DeductionKey']['PAINT_TYPE'],'prompt':(0x0,typeorm_2[_0x4febb0(0xe4)])(''),'answer':(0x0,typeorm_2['Not'])('')};_0x1a5ab3&&Object[_0x4febb0(0x128)](_0x4faf94,{'rec':_0x1a5ab3}),_0x3917f8&&Object[_0x4febb0(0x128)](_0x4faf94,{'userId':_0x3917f8});_0x2049d1&&(_0x4faf94['model']=_0x2049d1,_0x2049d1===_0x4febb0(0x103)&&(_0x4faf94[_0x4febb0(0x112)]=(0x0,typeorm_2['In'])(['DALL-E2','dall-e-3'])));const [_0xa317af,_0x59cba0]=await this[_0x4febb0(0xfe)][_0x4febb0(0xda)]({'order':{'id':_0x4febb0(0x113)},'skip':(page-0x1)*size,'take':size,'where':_0x4faf94});return _0xa317af[_0x4febb0(0xd3)](_0xc91b5d=>{const _0x57b1d8=_0x4febb0;var _0x32146a;if(_0xc91b5d[_0x57b1d8(0xe8)]===_0x57b1d8(0xbe)){const _0x89a08b=_0xc91b5d[_0x57b1d8(0x112)]==='mj'?0x136:0xa0,_0x13bb2f=_0xc91b5d[_0x57b1d8(0x115)]['includes'](_0x57b1d8(0xc8))?_0x57b1d8(0xfa):_0x57b1d8(0x126),_0x1d9373=_0x13bb2f===_0x57b1d8(0xfa)?_0x57b1d8(0xfc)+_0x89a08b+'/q/55':'?x-oss-process=image/resize,w_'+_0x89a08b;_0xc91b5d[_0x57b1d8(0x10c)]=_0xc91b5d[_0x57b1d8(0x115)]+_0x1d9373;try{const _0x2f16d8=_0xc91b5d['extend']?JSON[_0x57b1d8(0x12a)](_0xc91b5d['extend']):null;_0x2f16d8&&(_0x2f16d8?_0xc91b5d[_0x57b1d8(0xf5)]=((_0x32146a=_0x2f16d8===null||_0x2f16d8===void 0x0?void 0x0:_0x2f16d8['components'][0x0])===null||_0x32146a===void 0x0?void 0x0:_0x32146a[_0x57b1d8(0x105)]['length'])===0x5:_0xc91b5d[_0x57b1d8(0xf5)]=![]);}catch(_0x5b9769){console[_0x57b1d8(0xc2)]('querAllDrawLog\x20Json\x20parse\x20error',_0x5b9769);}}}),{'rows':_0xa317af,'count':_0x59cba0};}async[_0x32f1de(0x123)](_0x15308a){const _0x11587b=_0x32f1de,{id:_0x1446e5}=_0x15308a,_0x1fe60a=await this[_0x11587b(0xfe)][_0x11587b(0xf8)]({'where':{'id':_0x1446e5,'type':balance_constant_1[_0x11587b(0x120)][_0x11587b(0x12d)]}});if(!_0x1fe60a)throw new common_1['HttpException'](_0x11587b(0xf6),common_1[_0x11587b(0x116)][_0x11587b(0x10d)]);const _0xab8ecb=_0x1fe60a[_0x11587b(0xd4)]===0x1?0x0:0x1,_0x4748fa=await this[_0x11587b(0xfe)][_0x11587b(0xdb)]({'id':_0x1446e5},{'rec':_0xab8ecb});if(_0x4748fa[_0x11587b(0xf1)]>0x0)return(_0xab8ecb?'推荐':_0x11587b(0x108))+_0x11587b(0x11f);throw new common_1['HttpException'](_0x11587b(0x124),common_1['HttpStatus'][_0x11587b(0x10d)]);}async[_0x32f1de(0xce)](_0x52bd3b,_0x32955b){const _0x49a4a4=_0x32f1de,_0x5c9c3a={'type':balance_constant_1[_0x49a4a4(0x120)][_0x49a4a4(0x118)]},{page:page=0x1,size:size=0x1e,prompt:_0x2ddea,email:_0x154be4}=_0x52bd3b;_0x2ddea&&Object['assign'](_0x5c9c3a,{'prompt':(0x0,typeorm_2['Like'])('%'+_0x2ddea+'%')});if(_0x154be4){const _0x3f5a76=await this['userEntity'][_0x49a4a4(0xf8)]({'where':{'email':_0x154be4}});(_0x3f5a76===null||_0x3f5a76===void 0x0?void 0x0:_0x3f5a76['id'])&&Object[_0x49a4a4(0x128)](_0x5c9c3a,{'userId':_0x3f5a76['id']});}const [_0x1e67a0,_0x1d0325]=await this[_0x49a4a4(0xfe)][_0x49a4a4(0xda)]({'order':{'id':'DESC'},'skip':(page-0x1)*size,'take':size,'where':_0x5c9c3a}),_0x24dbcb=_0x1e67a0[_0x49a4a4(0xd0)](_0x2802e6=>_0x2802e6[_0x49a4a4(0x119)]),_0x204d5f=await this[_0x49a4a4(0xeb)][_0x49a4a4(0xf9)]({'where':{'id':(0x0,typeorm_2['In'])(_0x24dbcb)}}),_0x2e2167=_0x1e67a0[_0x49a4a4(0xd0)](_0x3d1681=>{const _0x183e8a=_0x49a4a4,_0x392f7b=_0x204d5f[_0x183e8a(0xf9)](_0x2fcd08=>_0x2fcd08['id']===_0x3d1681[_0x183e8a(0x119)]);return{'username':_0x392f7b?_0x392f7b[_0x183e8a(0xcb)]:'','email':_0x392f7b?_0x392f7b['email']:'','prompt':_0x3d1681[_0x183e8a(0xd9)],'answer':_0x3d1681[_0x183e8a(0x115)],'createdAt':(0x0,utils_1[_0x183e8a(0xf0)])(_0x3d1681['createdAt'])};}),_0x3e8d45=new exceljs_1[(_0x49a4a4(0xc0))]['Workbook'](),_0x138a24=_0x3e8d45['addWorksheet'](_0x49a4a4(0x11a));_0x138a24[_0x49a4a4(0xef)]=[{'header':_0x49a4a4(0xd2),'key':_0x49a4a4(0xcb),'width':0x14},{'header':_0x49a4a4(0xec),'key':_0x49a4a4(0xbf),'width':0x14},{'header':_0x49a4a4(0xe7),'key':_0x49a4a4(0xe2),'width':0x14},{'header':'提问问题','key':_0x49a4a4(0xd9),'width':0x50},{'header':_0x49a4a4(0x10e),'key':_0x49a4a4(0x115),'width':0x96}],_0x2e2167['forEach'](_0x15fc9b=>_0x138a24[_0x49a4a4(0xe0)](_0x15fc9b)),_0x32955b[_0x49a4a4(0xd1)](_0x49a4a4(0x10b),_0x49a4a4(0xf4)),_0x32955b[_0x49a4a4(0xd1)]('Content-Disposition',_0x49a4a4(0xdf)+_0x49a4a4(0x110)),await _0x3e8d45[_0x49a4a4(0xe3)]['write'](_0x32955b),_0x32955b[_0x49a4a4(0x12c)]();}async[_0x32f1de(0xd6)](_0x516754,_0x32c4f9){const _0x29f8fd=_0x32f1de,{page:page=0x1,size:size=0x14,userId:_0x1c4253,prompt:_0x3366ea}=_0x516754,_0x54ad72={'type':balance_constant_1[_0x29f8fd(0x120)]['CHAT_TYPE'],'prompt':(0x0,typeorm_2['Not'])('')};_0x1c4253&&Object[_0x29f8fd(0x128)](_0x54ad72,{'userId':_0x1c4253}),_0x3366ea&&Object['assign'](_0x54ad72,{'prompt':(0x0,typeorm_2[_0x29f8fd(0xd5)])('%'+_0x3366ea+'%')});const [_0x202fe3,_0x24474b]=await this[_0x29f8fd(0xfe)][_0x29f8fd(0xda)]({'order':{'id':'DESC'},'skip':(page-0x1)*size,'take':size,'where':_0x54ad72}),_0x5bd1d9=_0x202fe3[_0x29f8fd(0xd0)](_0x13519b=>_0x13519b[_0x29f8fd(0x119)]),_0x3f1ab8=await this[_0x29f8fd(0xeb)][_0x29f8fd(0xf9)]({'where':{'id':(0x0,typeorm_2['In'])(_0x5bd1d9)},'select':['id',_0x29f8fd(0xcb),'email']});return _0x202fe3[_0x29f8fd(0xd3)](_0x3681fe=>{const _0x5cbce1=_0x29f8fd,{username:_0x1254c4,email:_0x2a3782}=_0x3f1ab8[_0x5cbce1(0xf9)](_0x60171d=>_0x60171d['id']===_0x3681fe[_0x5cbce1(0x119)])||{};_0x3681fe[_0x5cbce1(0xcb)]=_0x1254c4,_0x3681fe['email']=_0x2a3782;}),_0x32c4f9[_0x29f8fd(0xea)][_0x29f8fd(0xe1)]!=='super'&&_0x202fe3[_0x29f8fd(0xd3)](_0x3824d2=>_0x3824d2[_0x29f8fd(0xbf)]=(0x0,utils_1['maskEmail'])(_0x3824d2['email'])),_0x202fe3['forEach'](_0x51c4f9=>{const _0x4214a1=_0x29f8fd;!_0x51c4f9[_0x4214a1(0xbf)]&&(_0x51c4f9['email']=(_0x51c4f9===null||_0x51c4f9===void 0x0?void 0x0:_0x51c4f9[_0x4214a1(0x119)])+_0x4214a1(0x104)),!_0x51c4f9[_0x4214a1(0xcb)]&&(_0x51c4f9[_0x4214a1(0xcb)]='游客'+(_0x51c4f9===null||_0x51c4f9===void 0x0?void 0x0:_0x51c4f9['userId']));}),{'rows':_0x202fe3,'count':_0x24474b};}async[_0x32f1de(0xe9)](_0x1bf3e8,_0x116b14){const _0x478978=_0x32f1de,{id:_0x224192}=_0x1bf3e8[_0x478978(0xea)],{groupId:_0x5085a1}=_0x116b14,_0x7d2136={'userId':_0x224192,'isDelete':![]};_0x5085a1&&Object[_0x478978(0x128)](_0x7d2136,{'groupId':_0x5085a1});if(_0x5085a1){const _0x3e45c3=await this[_0x478978(0x125)][_0x478978(0x111)]({'where':{'isDelete':![]}});if(_0x3e45c3===0x0)return[];}const _0xfce8ef=await this[_0x478978(0xfe)][_0x478978(0xf9)]({'where':_0x7d2136});return _0xfce8ef[_0x478978(0xd0)](_0x34943f=>{const _0x3f1991=_0x478978,{prompt:_0x525aa2,role:_0x552535,answer:_0x32ab2b,createdAt:_0x1a8ab6,model:_0x2a6b07,conversationOptions:_0x48eef8,requestOptions:_0x734d15,id:_0x3e17f9,imageUrl:_0x3686ee}=_0x34943f;let _0x2eed67=null,_0x258a61=null;try{_0x2eed67=JSON['parse'](_0x48eef8),_0x258a61=JSON[_0x3f1991(0x12a)](_0x734d15);}catch(_0x3fcf54){}return{'chatId':_0x3e17f9,'dateTime':(0x0,utils_1[_0x3f1991(0xf0)])(_0x1a8ab6),'text':_0x552535===_0x3f1991(0xea)?_0x525aa2:_0x32ab2b,'inversion':_0x552535===_0x3f1991(0xea),'error':![],'conversationOptions':_0x2eed67,'requestOptions':_0x258a61,'imageUrl':_0x3686ee,'model':_0x2a6b07};});}async['deleteChatLog'](_0x59afd0,_0x4fd98a){const _0xcfd009=_0x32f1de,{id:_0xc56262}=_0x59afd0[_0xcfd009(0xea)],{id:_0x89c021}=_0x4fd98a,_0x2e0882=await this[_0xcfd009(0xfe)][_0xcfd009(0xf8)]({'where':{'id':_0x89c021,'userId':_0xc56262}});if(!_0x2e0882)throw new common_1[(_0xcfd009(0xfd))](_0xcfd009(0x10a),common_1[_0xcfd009(0x116)][_0xcfd009(0x10d)]);const _0xbbc120=await this[_0xcfd009(0xfe)][_0xcfd009(0xdb)]({'id':_0x89c021},{'isDelete':!![]});if(_0xbbc120['affected']>0x0)return _0xcfd009(0xcc);else throw new common_1[(_0xcfd009(0xfd))](_0xcfd009(0x10a),common_1[_0xcfd009(0x116)][_0xcfd009(0x10d)]);}async['delByGroupId'](_0x1a4b02,_0x221ee0){const _0x1ec18b=_0x32f1de,{groupId:_0x186bd8}=_0x221ee0,{id:_0x263050}=_0x1a4b02[_0x1ec18b(0xea)],_0x4935b4=await this[_0x1ec18b(0x125)][_0x1ec18b(0xf8)]({'where':{'id':_0x186bd8,'userId':_0x263050}});if(!_0x4935b4)throw new common_1[(_0x1ec18b(0xfd))]('你删除的对话记录不存在、请检查!',common_1[_0x1ec18b(0x116)][_0x1ec18b(0x10d)]);const _0x2589e9=await this[_0x1ec18b(0xfe)][_0x1ec18b(0xdb)]({'groupId':_0x186bd8},{'isDelete':!![]});if(_0x2589e9[_0x1ec18b(0xf1)]>0x0)return _0x1ec18b(0xcc);if(_0x2589e9[_0x1ec18b(0xf1)]===0x0)throw new common_1[(_0x1ec18b(0xfd))]('当前页面已经没有东西可以删除了!',common_1['HttpStatus'][_0x1ec18b(0x10d)]);}async[_0x32f1de(0x100)](_0x28a7fa,_0x1d24ce){const _0x15cee2=_0x32f1de,{id:_0x54aa3e}=_0x28a7fa[_0x15cee2(0xea)],{appId:_0x387849,page:page=0x1,size:size=0xa}=_0x1d24ce,[_0x5741c3,_0x474725]=await this[_0x15cee2(0xfe)][_0x15cee2(0xda)]({'where':{'userId':_0x54aa3e,'appId':_0x387849,'role':'assistant'},'order':{'id':_0x15cee2(0x113)},'take':size,'skip':(page-0x1)*size});return{'rows':_0x5741c3,'count':_0x474725};}};ChatLogService=__decorate([(0x0,common_1[_0x32f1de(0xf7)])(),__param(0x0,(0x0,typeorm_1[_0x32f1de(0x11d)])(chatLog_entity_1[_0x32f1de(0xcd)])),__param(0x1,(0x0,typeorm_1['InjectRepository'])(user_entity_1['UserEntity'])),__param(0x2,(0x0,typeorm_1[_0x32f1de(0x11d)])(chatGroup_entity_1[_0x32f1de(0xd8)])),__metadata('design:paramtypes',[typeorm_2['Repository'],typeorm_2[_0x32f1de(0xff)],typeorm_2[_0x32f1de(0xff)]])],ChatLogService),exports[_0x32f1de(0xee)]=ChatLogService;function _0x26b3(){const _0x49b653=['你操作的图片不存在、请检查!','chatGroupEntity','ali','__metadata','assign','message_id','parse','1152310xPmvSX','end','PAINT_TYPE','paintCount','email','default','__param','log','save','defineProperty','object','3041507zOASeS','/q/55','cos','18728eaYkby','356930AyxFLh','username','删除对话记录成功!','ChatLogEntity','exportExcel','117yxaEoM','map','setHeader','用户名','forEach','rec','Like','querAllChatLog','__decorate','ChatGroupEntity','prompt','findAndCount','update','querAllDrawLog','dall-e-3','group','attachment;\x20filename=','addRow','role','createdAt','xlsx','Not','../../common/utils','extend','提问时间','type','chatList','user','userEntity','用户邮箱','../user/user.entity','ChatLogService','columns','formatDate','affected','function','../../common/constants/balance.constant','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','isGroup','你推荐的图片不存在、请检查!','Injectable','findOne','find','tencent','typeorm','?imageView2/1/w/','HttpException','chatLogEntity','Repository','byAppId','632541clrLbZ','querDrawLog','DALL-E2','@nine.com','components','1966548qqvXlO','6753000iAIFVt','取消推荐','getOwnPropertyDescriptor','你删除的对话记录不存在、请检查!','Content-Type','thumbImg','BAD_REQUEST','回答答案','__esModule','chat.xlsx','count','model','DESC','12bhNokr','answer','HttpStatus','fileInfo','CHAT_TYPE','userId','chatlog','saveChatLog','decorate','InjectRepository','@nestjs/common','图片成功!','DeductionKey','metadata','2oCnIXF','recDrawImg'];_0x26b3=function(){return _0x49b653;};return _0x26b3();}