YiAi/YiAiQuickDeploy/dist/modules/chatLog/chatLog.service.js

1 line
15 KiB
JavaScript

'use strict';const _0x58f634=_0xe1b1;(function(_0x462fae,_0x4b83e5){const _0x40d11f=_0xe1b1,_0x3a4d66=_0x462fae();while(!![]){try{const _0x26a9f6=parseInt(_0x40d11f(0x190))/0x1*(-parseInt(_0x40d11f(0x1a8))/0x2)+-parseInt(_0x40d11f(0x1a4))/0x3+-parseInt(_0x40d11f(0x15b))/0x4+parseInt(_0x40d11f(0x19d))/0x5+parseInt(_0x40d11f(0x193))/0x6+-parseInt(_0x40d11f(0x17f))/0x7+parseInt(_0x40d11f(0x17d))/0x8;if(_0x26a9f6===_0x4b83e5)break;else _0x3a4d66['push'](_0x3a4d66['shift']());}catch(_0x17de01){_0x3a4d66['push'](_0x3a4d66['shift']());}}}(_0x6401,0x90a30));var __decorate=this&&this[_0x58f634(0x15c)]||function(_0x3dd651,_0x1b84d7,_0x4a46d5,_0x29f189){const _0xf86590=_0x58f634;var _0xc42335=arguments[_0xf86590(0x199)],_0x437af3=_0xc42335<0x3?_0x1b84d7:_0x29f189===null?_0x29f189=Object['getOwnPropertyDescriptor'](_0x1b84d7,_0x4a46d5):_0x29f189,_0x54a986;if(typeof Reflect===_0xf86590(0x16f)&&typeof Reflect[_0xf86590(0x159)]===_0xf86590(0x153))_0x437af3=Reflect[_0xf86590(0x159)](_0x3dd651,_0x1b84d7,_0x4a46d5,_0x29f189);else{for(var _0x3a25f0=_0x3dd651[_0xf86590(0x199)]-0x1;_0x3a25f0>=0x0;_0x3a25f0--)if(_0x54a986=_0x3dd651[_0x3a25f0])_0x437af3=(_0xc42335<0x3?_0x54a986(_0x437af3):_0xc42335>0x3?_0x54a986(_0x1b84d7,_0x4a46d5,_0x437af3):_0x54a986(_0x1b84d7,_0x4a46d5))||_0x437af3;}return _0xc42335>0x3&&_0x437af3&&Object['defineProperty'](_0x1b84d7,_0x4a46d5,_0x437af3),_0x437af3;},__metadata=this&&this[_0x58f634(0x146)]||function(_0x4734a8,_0x47328d){const _0xd8142e=_0x58f634;if(typeof Reflect===_0xd8142e(0x16f)&&typeof Reflect[_0xd8142e(0x141)]==='function')return Reflect['metadata'](_0x4734a8,_0x47328d);},__param=this&&this['__param']||function(_0x3495f5,_0xe0d8){return function(_0x2f21e0,_0xd08702){_0xe0d8(_0x2f21e0,_0xd08702,_0x3495f5);};};function _0x6401(){const _0x2df397=['querAllDrawLog','CHAT_TYPE','querAllChatLog','includes','HttpStatus','affected','DESC','13984960ttPfVe','username','3946460XDUGvg','extend','回答答案','Like','tencent','../../common/constants/balance.constant','chatList','UserEntity','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','model','你删除的对话记录不存在、请检查!','querDrawLog','role','isGroup','dall-e-3','DALL-E2','find','11kZnXPM','save','cos','2723682wKodvH','DeductionKey','group','图片成功!','design:paramtypes','当前页面已经没有东西可以删除了!','length','用户名','email','Repository','3247980zaPEGq','ali','fileInfo','update','./chatLog.entity','parse','用户邮箱','2759397THotUO','super','Not','../../common/utils','126618fmlJPw','xlsx','HttpException','InjectRepository','chatlog','write','?imageView2/1/w/','userEntity','end','metadata','?x-oss-process=image/resize,w_','Content-Type','forEach','__esModule','__metadata','default','BAD_REQUEST','maskEmail','PAINT_TYPE','thumbImg','formatDate','提问时间','删除对话记录成功!','deleteChatLog','findAndCount','typeorm','setHeader','function','user','exportExcel','@nestjs/typeorm','delByGroupId','count','decorate','message_id','317012RUYSQW','__decorate','log','Workbook','querAllDrawLog\x20Json\x20parse\x20error','userId','paintCount','Injectable','recDrawImg','components','defineProperty','提问问题','chatGroupEntity','你推荐的图片不存在、请检查!','findOne','assign','@nestjs/common','byAppId','addWorksheet','ChatLogEntity','object','chatLogEntity','attachment;\x20filename=','map','answer','columns','ChatLogService'];_0x6401=function(){return _0x2df397;};return _0x6401();}Object[_0x58f634(0x165)](exports,_0x58f634(0x145),{'value':!![]}),exports[_0x58f634(0x175)]=void 0x0;const common_1=require(_0x58f634(0x16b)),typeorm_1=require(_0x58f634(0x156)),chatLog_entity_1=require(_0x58f634(0x1a1)),typeorm_2=require(_0x58f634(0x151)),balance_constant_1=require(_0x58f634(0x184)),user_entity_1=require('../user/user.entity'),utils_1=require(_0x58f634(0x1a7)),exceljs_1=require('exceljs'),chatGroup_entity_1=require('../chatGroup/chatGroup.entity');function _0xe1b1(_0x21b9fe,_0x1b746d){const _0x6401a8=_0x6401();return _0xe1b1=function(_0xe1b1d0,_0x128c65){_0xe1b1d0=_0xe1b1d0-0x141;let _0xefca66=_0x6401a8[_0xe1b1d0];return _0xefca66;},_0xe1b1(_0x21b9fe,_0x1b746d);}let ChatLogService=class ChatLogService{constructor(_0x479b8d,_0x2d486e,_0x3b5c1a){const _0x48c427=_0x58f634;this[_0x48c427(0x170)]=_0x479b8d,this[_0x48c427(0x1af)]=_0x2d486e,this[_0x48c427(0x167)]=_0x3b5c1a;}async['saveChatLog'](_0x221299){const _0x11bf67=_0x58f634;return await this[_0x11bf67(0x170)][_0x11bf67(0x191)](_0x221299);}async[_0x58f634(0x18a)](_0x2c2f29,_0x3c4d57){const _0x33fa0f=_0x58f634,{id:_0x14f655}=_0x2c2f29['user'],{model:_0x514c6f}=_0x3c4d57,_0x4692c4={'userId':_0x14f655,'type':balance_constant_1[_0x33fa0f(0x194)][_0x33fa0f(0x14a)]};_0x514c6f&&(_0x4692c4[_0x33fa0f(0x188)]=_0x514c6f,_0x514c6f===_0x33fa0f(0x18e)&&(_0x4692c4[_0x33fa0f(0x188)]=(0x0,typeorm_2['In'])([_0x33fa0f(0x18e),_0x33fa0f(0x18d)])));const _0x393915=await this[_0x33fa0f(0x170)]['find']({'where':_0x4692c4,'order':{'id':_0x33fa0f(0x17c)},'select':['id',_0x33fa0f(0x173),'prompt',_0x33fa0f(0x15a),_0x33fa0f(0x195),'model','extend','type',_0x33fa0f(0x19f)]});return _0x393915['forEach'](_0x1942a0=>{const _0xec7851=_0x33fa0f;if(_0x1942a0['type']===_0xec7851(0x161)){const _0x54362f=_0x1942a0[_0xec7851(0x188)]==='mj'?0x136:0xa0,_0x44b074=_0x1942a0[_0xec7851(0x173)][_0xec7851(0x179)](_0xec7851(0x192))?_0xec7851(0x183):_0xec7851(0x19e),_0xfaadeb=_0x44b074===_0xec7851(0x183)?_0xec7851(0x1ae)+_0x54362f+'/q/55':_0xec7851(0x142)+_0x54362f;_0x1942a0[_0xec7851(0x14b)]=_0x1942a0[_0xec7851(0x173)]+_0xfaadeb;try{_0x1942a0[_0xec7851(0x19f)]=_0x1942a0[_0xec7851(0x19f)]?JSON[_0xec7851(0x1a2)](_0x1942a0[_0xec7851(0x19f)]):null;}catch(_0x1858da){_0x1942a0[_0xec7851(0x19f)]={};}}}),_0x393915;}async[_0x58f634(0x176)](_0x24744c){const _0x35591a=_0x58f634,{page:page=0x1,size:size=0x14,rec:_0x1fa941,userId:_0x388753,model:_0x2fde43}=_0x24744c,_0x78daed={'type':balance_constant_1[_0x35591a(0x194)]['PAINT_TYPE'],'prompt':(0x0,typeorm_2[_0x35591a(0x1a6)])(''),'answer':(0x0,typeorm_2[_0x35591a(0x1a6)])('')};_0x1fa941&&Object[_0x35591a(0x16a)](_0x78daed,{'rec':_0x1fa941}),_0x388753&&Object[_0x35591a(0x16a)](_0x78daed,{'userId':_0x388753});_0x2fde43&&(_0x78daed[_0x35591a(0x188)]=_0x2fde43,_0x2fde43===_0x35591a(0x18e)&&(_0x78daed[_0x35591a(0x188)]=(0x0,typeorm_2['In'])([_0x35591a(0x18e),_0x35591a(0x18d)])));const [_0x107dcd,_0x2d290a]=await this[_0x35591a(0x170)][_0x35591a(0x150)]({'order':{'id':_0x35591a(0x17c)},'skip':(page-0x1)*size,'take':size,'where':_0x78daed});return _0x107dcd[_0x35591a(0x144)](_0x50e1a2=>{const _0x416185=_0x35591a;var _0xd5d2a3;if(_0x50e1a2['type']===_0x416185(0x161)){const _0x36d671=_0x50e1a2['model']==='mj'?0x136:0xa0,_0x5be503=_0x50e1a2['answer'][_0x416185(0x179)](_0x416185(0x192))?_0x416185(0x183):_0x416185(0x19e),_0x10b83d=_0x5be503===_0x416185(0x183)?_0x416185(0x1ae)+_0x36d671+'/q/55':_0x416185(0x142)+_0x36d671;_0x50e1a2[_0x416185(0x14b)]=_0x50e1a2['answer']+_0x10b83d;try{const _0x83391=_0x50e1a2['extend']?JSON['parse'](_0x50e1a2[_0x416185(0x180)]):null;_0x83391&&(_0x83391?_0x50e1a2['isGroup']=((_0xd5d2a3=_0x83391===null||_0x83391===void 0x0?void 0x0:_0x83391['components'][0x0])===null||_0xd5d2a3===void 0x0?void 0x0:_0xd5d2a3[_0x416185(0x164)][_0x416185(0x199)])===0x5:_0x50e1a2[_0x416185(0x18c)]=![]);}catch(_0x511128){console[_0x416185(0x15d)](_0x416185(0x15f),_0x511128);}}}),{'rows':_0x107dcd,'count':_0x2d290a};}async[_0x58f634(0x163)](_0x1ac3ab){const _0x5b27c1=_0x58f634,{id:_0x37650e}=_0x1ac3ab,_0x3bee15=await this[_0x5b27c1(0x170)]['findOne']({'where':{'id':_0x37650e,'type':balance_constant_1['DeductionKey'][_0x5b27c1(0x14a)]}});if(!_0x3bee15)throw new common_1['HttpException'](_0x5b27c1(0x168),common_1[_0x5b27c1(0x17a)]['BAD_REQUEST']);const _0x3bb138=_0x3bee15['rec']===0x1?0x0:0x1,_0x589657=await this[_0x5b27c1(0x170)][_0x5b27c1(0x1a0)]({'id':_0x37650e},{'rec':_0x3bb138});if(_0x589657[_0x5b27c1(0x17b)]>0x0)return(_0x3bb138?'推荐':'取消推荐')+_0x5b27c1(0x196);throw new common_1[(_0x5b27c1(0x1aa))]('你操作的图片不存在、请检查!',common_1[_0x5b27c1(0x17a)][_0x5b27c1(0x148)]);}async[_0x58f634(0x155)](_0x33df03,_0x3121e0){const _0x4b4e77=_0x58f634,_0x2aa4de={'type':balance_constant_1[_0x4b4e77(0x194)][_0x4b4e77(0x177)]},{page:page=0x1,size:size=0x1e,prompt:_0x19f57a,email:_0x586fe0}=_0x33df03;_0x19f57a&&Object[_0x4b4e77(0x16a)](_0x2aa4de,{'prompt':(0x0,typeorm_2[_0x4b4e77(0x182)])('%'+_0x19f57a+'%')});if(_0x586fe0){const _0x46e27d=await this['userEntity'][_0x4b4e77(0x169)]({'where':{'email':_0x586fe0}});(_0x46e27d===null||_0x46e27d===void 0x0?void 0x0:_0x46e27d['id'])&&Object['assign'](_0x2aa4de,{'userId':_0x46e27d['id']});}const [_0x434e0f,_0xf915f0]=await this[_0x4b4e77(0x170)][_0x4b4e77(0x150)]({'order':{'id':_0x4b4e77(0x17c)},'skip':(page-0x1)*size,'take':size,'where':_0x2aa4de}),_0x3ccba9=_0x434e0f[_0x4b4e77(0x172)](_0x1d2f30=>_0x1d2f30['userId']),_0x48535f=await this[_0x4b4e77(0x1af)]['find']({'where':{'id':(0x0,typeorm_2['In'])(_0x3ccba9)}}),_0x796913=_0x434e0f[_0x4b4e77(0x172)](_0x477728=>{const _0x1f9cfd=_0x4b4e77,_0x48a44e=_0x48535f[_0x1f9cfd(0x18f)](_0x4c9dae=>_0x4c9dae['id']===_0x477728[_0x1f9cfd(0x160)]);return{'username':_0x48a44e?_0x48a44e['username']:'','email':_0x48a44e?_0x48a44e[_0x1f9cfd(0x19b)]:'','prompt':_0x477728['prompt'],'answer':_0x477728['answer'],'createdAt':(0x0,utils_1[_0x1f9cfd(0x14c)])(_0x477728['createdAt'])};}),_0x527c65=new exceljs_1[(_0x4b4e77(0x147))][(_0x4b4e77(0x15e))](),_0x2c4024=_0x527c65[_0x4b4e77(0x16d)](_0x4b4e77(0x1ac));_0x2c4024[_0x4b4e77(0x174)]=[{'header':_0x4b4e77(0x19a),'key':_0x4b4e77(0x17e),'width':0x14},{'header':_0x4b4e77(0x1a3),'key':_0x4b4e77(0x19b),'width':0x14},{'header':_0x4b4e77(0x14d),'key':'createdAt','width':0x14},{'header':_0x4b4e77(0x166),'key':'prompt','width':0x50},{'header':_0x4b4e77(0x181),'key':_0x4b4e77(0x173),'width':0x96}],_0x796913['forEach'](_0x53de21=>_0x2c4024['addRow'](_0x53de21)),_0x3121e0[_0x4b4e77(0x152)](_0x4b4e77(0x143),_0x4b4e77(0x187)),_0x3121e0[_0x4b4e77(0x152)]('Content-Disposition',_0x4b4e77(0x171)+'chat.xlsx'),await _0x527c65[_0x4b4e77(0x1a9)][_0x4b4e77(0x1ad)](_0x3121e0),_0x3121e0[_0x4b4e77(0x1b0)]();}async[_0x58f634(0x178)](_0x2a4195,_0x8960db){const _0x6e66a0=_0x58f634,{page:page=0x1,size:size=0x14,userId:_0x4244f0,prompt:_0x2a0903}=_0x2a4195,_0x588387={'type':balance_constant_1[_0x6e66a0(0x194)][_0x6e66a0(0x177)],'prompt':(0x0,typeorm_2['Not'])('')};_0x4244f0&&Object[_0x6e66a0(0x16a)](_0x588387,{'userId':_0x4244f0}),_0x2a0903&&Object[_0x6e66a0(0x16a)](_0x588387,{'prompt':(0x0,typeorm_2[_0x6e66a0(0x182)])('%'+_0x2a0903+'%')});const [_0x2ad616,_0x4f7038]=await this[_0x6e66a0(0x170)]['findAndCount']({'order':{'id':_0x6e66a0(0x17c)},'skip':(page-0x1)*size,'take':size,'where':_0x588387}),_0x5be6a4=_0x2ad616[_0x6e66a0(0x172)](_0x284026=>_0x284026[_0x6e66a0(0x160)]),_0x2451a2=await this[_0x6e66a0(0x1af)][_0x6e66a0(0x18f)]({'where':{'id':(0x0,typeorm_2['In'])(_0x5be6a4)},'select':['id',_0x6e66a0(0x17e),_0x6e66a0(0x19b)]});return _0x2ad616[_0x6e66a0(0x144)](_0x4f9269=>{const _0x371bcc=_0x6e66a0,{username:_0x57e1f2,email:_0x4fa3d4}=_0x2451a2[_0x371bcc(0x18f)](_0x28045e=>_0x28045e['id']===_0x4f9269[_0x371bcc(0x160)])||{};_0x4f9269[_0x371bcc(0x17e)]=_0x57e1f2,_0x4f9269[_0x371bcc(0x19b)]=_0x4fa3d4;}),_0x8960db['user'][_0x6e66a0(0x18b)]!==_0x6e66a0(0x1a5)&&_0x2ad616[_0x6e66a0(0x144)](_0xd5e823=>_0xd5e823[_0x6e66a0(0x19b)]=(0x0,utils_1[_0x6e66a0(0x149)])(_0xd5e823[_0x6e66a0(0x19b)])),_0x2ad616['forEach'](_0x54e984=>{const _0x3f946e=_0x6e66a0;!_0x54e984[_0x3f946e(0x19b)]&&(_0x54e984[_0x3f946e(0x19b)]=(_0x54e984===null||_0x54e984===void 0x0?void 0x0:_0x54e984[_0x3f946e(0x160)])+'@nine.com'),!_0x54e984['username']&&(_0x54e984[_0x3f946e(0x17e)]='游客'+(_0x54e984===null||_0x54e984===void 0x0?void 0x0:_0x54e984[_0x3f946e(0x160)]));}),{'rows':_0x2ad616,'count':_0x4f7038};}async[_0x58f634(0x185)](_0x349f02,_0x3d65de){const _0x460198=_0x58f634,{id:_0x474c20}=_0x349f02[_0x460198(0x154)],{groupId:_0x306567}=_0x3d65de,_0x55aaa4={'userId':_0x474c20,'isDelete':![]};_0x306567&&Object[_0x460198(0x16a)](_0x55aaa4,{'groupId':_0x306567});if(_0x306567){const _0x21f014=await this[_0x460198(0x167)][_0x460198(0x158)]({'where':{'isDelete':![]}});if(_0x21f014===0x0)return[];}const _0x57472e=await this[_0x460198(0x170)]['find']({'where':_0x55aaa4});return _0x57472e[_0x460198(0x172)](_0x1552b8=>{const _0x16bd0c=_0x460198,{prompt:_0x26f14c,role:_0x40374c,answer:_0x492ba8,createdAt:_0x44dd36,model:_0x28a06d,conversationOptions:_0x236728,requestOptions:_0x481d4f,id:_0x2b9637,imageUrl:_0x3f72b5}=_0x1552b8;let _0x4dcf4c=null,_0xfd9681=null;try{_0x4dcf4c=JSON[_0x16bd0c(0x1a2)](_0x236728),_0xfd9681=JSON[_0x16bd0c(0x1a2)](_0x481d4f);}catch(_0x462967){}return{'chatId':_0x2b9637,'dateTime':(0x0,utils_1['formatDate'])(_0x44dd36),'text':_0x40374c===_0x16bd0c(0x154)?_0x26f14c:_0x492ba8,'inversion':_0x40374c==='user','error':![],'conversationOptions':_0x4dcf4c,'requestOptions':_0xfd9681,'imageUrl':_0x3f72b5,'model':_0x28a06d};});}async[_0x58f634(0x14f)](_0x18f1ad,_0x2fff09){const _0x18deba=_0x58f634,{id:_0x20a07c}=_0x18f1ad[_0x18deba(0x154)],{id:_0x5384bb}=_0x2fff09,_0x4bb0e5=await this[_0x18deba(0x170)][_0x18deba(0x169)]({'where':{'id':_0x5384bb,'userId':_0x20a07c}});if(!_0x4bb0e5)throw new common_1['HttpException'](_0x18deba(0x189),common_1[_0x18deba(0x17a)][_0x18deba(0x148)]);const _0x5e37f8=await this[_0x18deba(0x170)][_0x18deba(0x1a0)]({'id':_0x5384bb},{'isDelete':!![]});if(_0x5e37f8[_0x18deba(0x17b)]>0x0)return _0x18deba(0x14e);else throw new common_1[(_0x18deba(0x1aa))](_0x18deba(0x189),common_1[_0x18deba(0x17a)][_0x18deba(0x148)]);}async[_0x58f634(0x157)](_0x4f4d0c,_0x4668e1){const _0x234c1c=_0x58f634,{groupId:_0x5529b6}=_0x4668e1,{id:_0x5b96c8}=_0x4f4d0c[_0x234c1c(0x154)],_0xc4c83e=await this[_0x234c1c(0x167)][_0x234c1c(0x169)]({'where':{'id':_0x5529b6,'userId':_0x5b96c8}});if(!_0xc4c83e)throw new common_1[(_0x234c1c(0x1aa))]('你删除的对话记录不存在、请检查!',common_1['HttpStatus'][_0x234c1c(0x148)]);const _0x234ad9=await this[_0x234c1c(0x170)][_0x234c1c(0x1a0)]({'groupId':_0x5529b6},{'isDelete':!![]});if(_0x234ad9[_0x234c1c(0x17b)]>0x0)return _0x234c1c(0x14e);if(_0x234ad9['affected']===0x0)throw new common_1[(_0x234c1c(0x1aa))](_0x234c1c(0x198),common_1[_0x234c1c(0x17a)][_0x234c1c(0x148)]);}async[_0x58f634(0x16c)](_0x52c8df,_0x411a93){const _0x21ae56=_0x58f634,{id:_0x439a9c}=_0x52c8df[_0x21ae56(0x154)],{appId:_0x767f51,page:page=0x1,size:size=0xa}=_0x411a93,[_0x437661,_0x36342e]=await this['chatLogEntity']['findAndCount']({'where':{'userId':_0x439a9c,'appId':_0x767f51,'role':'assistant'},'order':{'id':_0x21ae56(0x17c)},'take':size,'skip':(page-0x1)*size});return{'rows':_0x437661,'count':_0x36342e};}};ChatLogService=__decorate([(0x0,common_1[_0x58f634(0x162)])(),__param(0x0,(0x0,typeorm_1['InjectRepository'])(chatLog_entity_1[_0x58f634(0x16e)])),__param(0x1,(0x0,typeorm_1[_0x58f634(0x1ab)])(user_entity_1[_0x58f634(0x186)])),__param(0x2,(0x0,typeorm_1[_0x58f634(0x1ab)])(chatGroup_entity_1['ChatGroupEntity'])),__metadata(_0x58f634(0x197),[typeorm_2['Repository'],typeorm_2[_0x58f634(0x19c)],typeorm_2[_0x58f634(0x19c)]])],ChatLogService),exports[_0x58f634(0x175)]=ChatLogService;