YiAi/YiAiQuickDeploy/dist/modules/chatLog/chatLog.service.js
2024-07-02 16:38:26 +08:00

1 line
15 KiB
JavaScript

'use strict';const _0x42f541=_0x3d62;(function(_0x419ad2,_0x508f0a){const _0x429b39=_0x3d62,_0x16871c=_0x419ad2();while(!![]){try{const _0x18683a=-parseInt(_0x429b39(0xdd))/0x1*(-parseInt(_0x429b39(0xd3))/0x2)+-parseInt(_0x429b39(0xdb))/0x3*(-parseInt(_0x429b39(0xa2))/0x4)+parseInt(_0x429b39(0xf6))/0x5*(-parseInt(_0x429b39(0x98))/0x6)+parseInt(_0x429b39(0xa6))/0x7*(parseInt(_0x429b39(0x97))/0x8)+parseInt(_0x429b39(0xf7))/0x9+-parseInt(_0x429b39(0xce))/0xa+-parseInt(_0x429b39(0xda))/0xb*(-parseInt(_0x429b39(0xd9))/0xc);if(_0x18683a===_0x508f0a)break;else _0x16871c['push'](_0x16871c['shift']());}catch(_0x2dfc2d){_0x16871c['push'](_0x16871c['shift']());}}}(_0x202f,0x47bf3));var __decorate=this&&this[_0x42f541(0xca)]||function(_0x1b05c4,_0x26208a,_0x20348c,_0x129b1f){const _0x47e2cb=_0x42f541;var _0x5bf8db=arguments[_0x47e2cb(0xc8)],_0x790b8=_0x5bf8db<0x3?_0x26208a:_0x129b1f===null?_0x129b1f=Object[_0x47e2cb(0xed)](_0x26208a,_0x20348c):_0x129b1f,_0x2372fa;if(typeof Reflect===_0x47e2cb(0xaa)&&typeof Reflect[_0x47e2cb(0xba)]==='function')_0x790b8=Reflect[_0x47e2cb(0xba)](_0x1b05c4,_0x26208a,_0x20348c,_0x129b1f);else{for(var _0x40936e=_0x1b05c4['length']-0x1;_0x40936e>=0x0;_0x40936e--)if(_0x2372fa=_0x1b05c4[_0x40936e])_0x790b8=(_0x5bf8db<0x3?_0x2372fa(_0x790b8):_0x5bf8db>0x3?_0x2372fa(_0x26208a,_0x20348c,_0x790b8):_0x2372fa(_0x26208a,_0x20348c))||_0x790b8;}return _0x5bf8db>0x3&&_0x790b8&&Object[_0x47e2cb(0x104)](_0x26208a,_0x20348c,_0x790b8),_0x790b8;},__metadata=this&&this[_0x42f541(0xf4)]||function(_0x356579,_0x37a1f5){const _0x26e750=_0x42f541;if(typeof Reflect===_0x26e750(0xaa)&&typeof Reflect[_0x26e750(0xc1)]===_0x26e750(0xa8))return Reflect[_0x26e750(0xc1)](_0x356579,_0x37a1f5);},__param=this&&this['__param']||function(_0x63066f,_0x3f1778){return function(_0x5f540d,_0x25e785){_0x3f1778(_0x5f540d,_0x25e785,_0x63066f);};};Object[_0x42f541(0x104)](exports,_0x42f541(0xb8),{'value':!![]}),exports[_0x42f541(0xcd)]=void 0x0;function _0x202f(){const _0x283e5b=['exceljs','default','affected','你删除的对话记录不存在、请检查!','typeorm','Not','defineProperty','图片成功!','super','end','InjectRepository','chatList','HttpStatus','find','email','assign','rec','@nestjs/common','prompt','8thUcgV','9426VmNQZv','xlsx','map','attachment;\x20filename=','chatLogEntity','save','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','answer','setHeader','@nestjs/typeorm','5996Knvkhi','querAllDrawLog','design:paramtypes','chatlog','907431ykuBdH','/q/55','function','你操作的图片不存在、请检查!','object','cos','@nine.com','formatDate','CHAT_TYPE','findOne','assistant','./chatLog.entity','../../common/constants/balance.constant','type','当前页面已经没有东西可以删除了!','fileInfo','includes','user','__esModule','DeductionKey','decorate','log','DESC','用户名','model','chat.xlsx','?imageView2/1/w/','metadata','BAD_REQUEST','querDrawLog','userId','HttpException','count','ChatLogEntity','length','删除对话记录成功!','__decorate','addRow','提问时间','ChatLogService','510470jDRQQo','Content-Type','message_id','Like','delByGroupId','38842toGfIx','userEntity','exportExcel','Repository','columns','components','5916rsgsJQ','2156UdOpGY','228gLFWcp','dall-e-3','16DIYspV','recDrawImg','tencent','isGroup','../chatGroup/chatGroup.entity','Workbook','username','findAndCount','querAllChatLog','update','Content-Disposition','createdAt','你推荐的图片不存在、请检查!','../user/user.entity','?x-oss-process=image/resize,w_','forEach','getOwnPropertyDescriptor','ChatGroupEntity','用户邮箱','extend','../../common/utils','PAINT_TYPE','DALL-E2','__metadata','chatGroupEntity','1535UhRHTQ','1586682qwkpQe','addWorksheet','parse','thumbImg','byAppId','ali','write'];_0x202f=function(){return _0x283e5b;};return _0x202f();}function _0x3d62(_0x5c67b7,_0x5c80ed){const _0x202f50=_0x202f();return _0x3d62=function(_0x3d623e,_0x77c3bb){_0x3d623e=_0x3d623e-0x95;let _0x2d3ca8=_0x202f50[_0x3d623e];return _0x2d3ca8;},_0x3d62(_0x5c67b7,_0x5c80ed);}const common_1=require(_0x42f541(0x95)),typeorm_1=require(_0x42f541(0xa1)),chatLog_entity_1=require(_0x42f541(0xb1)),typeorm_2=require(_0x42f541(0x102)),balance_constant_1=require(_0x42f541(0xb2)),user_entity_1=require(_0x42f541(0xea)),utils_1=require(_0x42f541(0xf1)),exceljs_1=require(_0x42f541(0xfe)),chatGroup_entity_1=require(_0x42f541(0xe1));let ChatLogService=class ChatLogService{constructor(_0x113f2d,_0x265f4c,_0x3002ce){const _0x2912bf=_0x42f541;this['chatLogEntity']=_0x113f2d,this['userEntity']=_0x265f4c,this[_0x2912bf(0xf5)]=_0x3002ce;}async['saveChatLog'](_0x2a818d){const _0x328669=_0x42f541;return await this[_0x328669(0x9c)][_0x328669(0x9d)](_0x2a818d);}async[_0x42f541(0xc3)](_0x3bd497,_0x1ce5db){const _0x147cf5=_0x42f541,{id:_0x32f6f9}=_0x3bd497['user'],{model:_0x3a9b62}=_0x1ce5db,_0x50d605={'userId':_0x32f6f9,'type':balance_constant_1[_0x147cf5(0xb9)][_0x147cf5(0xf2)]};_0x3a9b62&&(_0x50d605[_0x147cf5(0xbe)]=_0x3a9b62,_0x3a9b62==='DALL-E2'&&(_0x50d605[_0x147cf5(0xbe)]=(0x0,typeorm_2['In'])([_0x147cf5(0xf3),_0x147cf5(0xdc)])));const _0x551dd1=await this[_0x147cf5(0x9c)][_0x147cf5(0x10b)]({'where':_0x50d605,'order':{'id':_0x147cf5(0xbc)},'select':['id',_0x147cf5(0x9f),_0x147cf5(0x96),_0x147cf5(0xd0),'group',_0x147cf5(0xbe),'extend',_0x147cf5(0xb3),_0x147cf5(0xb5)]});return _0x551dd1[_0x147cf5(0xec)](_0x285019=>{const _0x29398f=_0x147cf5;if(_0x285019[_0x29398f(0xb3)]==='paintCount'){const _0x2f33ae=_0x285019[_0x29398f(0xbe)]==='mj'?0x136:0xa0,_0x4b6646=_0x285019[_0x29398f(0x9f)][_0x29398f(0xb6)](_0x29398f(0xab))?'tencent':_0x29398f(0xfc),_0x1327a=_0x4b6646===_0x29398f(0xdf)?_0x29398f(0xc0)+_0x2f33ae+_0x29398f(0xa7):'?x-oss-process=image/resize,w_'+_0x2f33ae;_0x285019['thumbImg']=_0x285019[_0x29398f(0x9f)]+_0x1327a;try{_0x285019[_0x29398f(0xb5)]=_0x285019['fileInfo']?JSON[_0x29398f(0xf9)](_0x285019[_0x29398f(0xb5)]):null;}catch(_0x2a25a3){_0x285019[_0x29398f(0xb5)]={};}}}),_0x551dd1;}async[_0x42f541(0xa3)](_0x67b5fc){const _0x1a8030=_0x42f541,{page:page=0x1,size:size=0x14,rec:_0x9b9646,userId:_0x7290c,model:_0xe66a7b}=_0x67b5fc,_0x2e9b23={'type':balance_constant_1[_0x1a8030(0xb9)][_0x1a8030(0xf2)],'prompt':(0x0,typeorm_2['Not'])(''),'answer':(0x0,typeorm_2[_0x1a8030(0x103)])('')};_0x9b9646&&Object['assign'](_0x2e9b23,{'rec':_0x9b9646}),_0x7290c&&Object[_0x1a8030(0x10d)](_0x2e9b23,{'userId':_0x7290c});_0xe66a7b&&(_0x2e9b23[_0x1a8030(0xbe)]=_0xe66a7b,_0xe66a7b===_0x1a8030(0xf3)&&(_0x2e9b23[_0x1a8030(0xbe)]=(0x0,typeorm_2['In'])([_0x1a8030(0xf3),_0x1a8030(0xdc)])));const [_0x58af53,_0x1150e1]=await this[_0x1a8030(0x9c)][_0x1a8030(0xe4)]({'order':{'id':_0x1a8030(0xbc)},'skip':(page-0x1)*size,'take':size,'where':_0x2e9b23});return _0x58af53[_0x1a8030(0xec)](_0xbcfd6b=>{const _0x11d755=_0x1a8030;var _0x6cf07;if(_0xbcfd6b[_0x11d755(0xb3)]==='paintCount'){const _0x47292c=_0xbcfd6b['model']==='mj'?0x136:0xa0,_0x38a240=_0xbcfd6b['answer'][_0x11d755(0xb6)](_0x11d755(0xab))?_0x11d755(0xdf):_0x11d755(0xfc),_0x47de87=_0x38a240===_0x11d755(0xdf)?_0x11d755(0xc0)+_0x47292c+'/q/55':_0x11d755(0xeb)+_0x47292c;_0xbcfd6b[_0x11d755(0xfa)]=_0xbcfd6b[_0x11d755(0x9f)]+_0x47de87;try{const _0x26e1b2=_0xbcfd6b[_0x11d755(0xf0)]?JSON[_0x11d755(0xf9)](_0xbcfd6b[_0x11d755(0xf0)]):null;_0x26e1b2&&(_0x26e1b2?_0xbcfd6b[_0x11d755(0xe0)]=((_0x6cf07=_0x26e1b2===null||_0x26e1b2===void 0x0?void 0x0:_0x26e1b2[_0x11d755(0xd8)][0x0])===null||_0x6cf07===void 0x0?void 0x0:_0x6cf07[_0x11d755(0xd8)]['length'])===0x5:_0xbcfd6b[_0x11d755(0xe0)]=![]);}catch(_0x290de9){console[_0x11d755(0xbb)]('querAllDrawLog\x20Json\x20parse\x20error',_0x290de9);}}}),{'rows':_0x58af53,'count':_0x1150e1};}async[_0x42f541(0xde)](_0x15cc48){const _0x4a04ec=_0x42f541,{id:_0x26148f}=_0x15cc48,_0x498517=await this['chatLogEntity'][_0x4a04ec(0xaf)]({'where':{'id':_0x26148f,'type':balance_constant_1[_0x4a04ec(0xb9)][_0x4a04ec(0xf2)]}});if(!_0x498517)throw new common_1[(_0x4a04ec(0xc5))](_0x4a04ec(0xe9),common_1[_0x4a04ec(0x10a)][_0x4a04ec(0xc2)]);const _0x19b13b=_0x498517[_0x4a04ec(0x10e)]===0x1?0x0:0x1,_0x4e9a3c=await this['chatLogEntity']['update']({'id':_0x26148f},{'rec':_0x19b13b});if(_0x4e9a3c[_0x4a04ec(0x100)]>0x0)return(_0x19b13b?'推荐':'取消推荐')+_0x4a04ec(0x105);throw new common_1[(_0x4a04ec(0xc5))](_0x4a04ec(0xa9),common_1[_0x4a04ec(0x10a)][_0x4a04ec(0xc2)]);}async[_0x42f541(0xd5)](_0x3d0d4b,_0x209423){const _0x2825c3=_0x42f541,_0xd9efe5={'type':balance_constant_1[_0x2825c3(0xb9)][_0x2825c3(0xae)]},{page:page=0x1,size:size=0x1e,prompt:_0x1ac749,email:_0x55dbcc}=_0x3d0d4b;_0x1ac749&&Object[_0x2825c3(0x10d)](_0xd9efe5,{'prompt':(0x0,typeorm_2[_0x2825c3(0xd1)])('%'+_0x1ac749+'%')});if(_0x55dbcc){const _0x47849d=await this[_0x2825c3(0xd4)][_0x2825c3(0xaf)]({'where':{'email':_0x55dbcc}});(_0x47849d===null||_0x47849d===void 0x0?void 0x0:_0x47849d['id'])&&Object[_0x2825c3(0x10d)](_0xd9efe5,{'userId':_0x47849d['id']});}const [_0x1b372d,_0x272625]=await this['chatLogEntity'][_0x2825c3(0xe4)]({'order':{'id':'DESC'},'skip':(page-0x1)*size,'take':size,'where':_0xd9efe5}),_0x276527=_0x1b372d[_0x2825c3(0x9a)](_0x485363=>_0x485363[_0x2825c3(0xc4)]),_0x1e1d99=await this[_0x2825c3(0xd4)][_0x2825c3(0x10b)]({'where':{'id':(0x0,typeorm_2['In'])(_0x276527)}}),_0x32e7d7=_0x1b372d['map'](_0x127f00=>{const _0x447c9c=_0x2825c3,_0x122241=_0x1e1d99['find'](_0x2fa45f=>_0x2fa45f['id']===_0x127f00['userId']);return{'username':_0x122241?_0x122241['username']:'','email':_0x122241?_0x122241['email']:'','prompt':_0x127f00[_0x447c9c(0x96)],'answer':_0x127f00[_0x447c9c(0x9f)],'createdAt':(0x0,utils_1[_0x447c9c(0xad)])(_0x127f00[_0x447c9c(0xe8)])};}),_0x323cdd=new exceljs_1[(_0x2825c3(0xff))][(_0x2825c3(0xe2))](),_0x2fcb1d=_0x323cdd[_0x2825c3(0xf8)](_0x2825c3(0xa5));_0x2fcb1d[_0x2825c3(0xd7)]=[{'header':_0x2825c3(0xbd),'key':'username','width':0x14},{'header':_0x2825c3(0xef),'key':_0x2825c3(0x10c),'width':0x14},{'header':_0x2825c3(0xcc),'key':_0x2825c3(0xe8),'width':0x14},{'header':'提问问题','key':'prompt','width':0x50},{'header':'回答答案','key':'answer','width':0x96}],_0x32e7d7['forEach'](_0x3417cd=>_0x2fcb1d[_0x2825c3(0xcb)](_0x3417cd)),_0x209423['setHeader'](_0x2825c3(0xcf),_0x2825c3(0x9e)),_0x209423[_0x2825c3(0xa0)](_0x2825c3(0xe7),_0x2825c3(0x9b)+_0x2825c3(0xbf)),await _0x323cdd[_0x2825c3(0x99)][_0x2825c3(0xfd)](_0x209423),_0x209423[_0x2825c3(0x107)]();}async[_0x42f541(0xe5)](_0x3135fa,_0xcccc23){const _0x8c9d1d=_0x42f541,{page:page=0x1,size:size=0x14,userId:_0x9edf10,prompt:_0x127cd7}=_0x3135fa,_0x3cfbd9={'type':balance_constant_1[_0x8c9d1d(0xb9)][_0x8c9d1d(0xae)],'prompt':(0x0,typeorm_2[_0x8c9d1d(0x103)])('')};_0x9edf10&&Object[_0x8c9d1d(0x10d)](_0x3cfbd9,{'userId':_0x9edf10}),_0x127cd7&&Object[_0x8c9d1d(0x10d)](_0x3cfbd9,{'prompt':(0x0,typeorm_2[_0x8c9d1d(0xd1)])('%'+_0x127cd7+'%')});const [_0x2d7d95,_0xf8795d]=await this[_0x8c9d1d(0x9c)][_0x8c9d1d(0xe4)]({'order':{'id':_0x8c9d1d(0xbc)},'skip':(page-0x1)*size,'take':size,'where':_0x3cfbd9}),_0x1ab7fb=_0x2d7d95[_0x8c9d1d(0x9a)](_0x30e834=>_0x30e834['userId']),_0x591a19=await this['userEntity'][_0x8c9d1d(0x10b)]({'where':{'id':(0x0,typeorm_2['In'])(_0x1ab7fb)},'select':['id','username',_0x8c9d1d(0x10c)]});return _0x2d7d95['forEach'](_0xa5c03a=>{const _0x1112fd=_0x8c9d1d,{username:_0x250ff7,email:_0x4c0802}=_0x591a19[_0x1112fd(0x10b)](_0xc524a1=>_0xc524a1['id']===_0xa5c03a[_0x1112fd(0xc4)])||{};_0xa5c03a[_0x1112fd(0xe3)]=_0x250ff7,_0xa5c03a[_0x1112fd(0x10c)]=_0x4c0802;}),_0xcccc23[_0x8c9d1d(0xb7)]['role']!==_0x8c9d1d(0x106)&&_0x2d7d95['forEach'](_0x125a8e=>_0x125a8e[_0x8c9d1d(0x10c)]=(0x0,utils_1['maskEmail'])(_0x125a8e[_0x8c9d1d(0x10c)])),_0x2d7d95[_0x8c9d1d(0xec)](_0x39f489=>{const _0x142c68=_0x8c9d1d;!_0x39f489[_0x142c68(0x10c)]&&(_0x39f489[_0x142c68(0x10c)]=(_0x39f489===null||_0x39f489===void 0x0?void 0x0:_0x39f489['userId'])+_0x142c68(0xac)),!_0x39f489['username']&&(_0x39f489['username']='游客'+(_0x39f489===null||_0x39f489===void 0x0?void 0x0:_0x39f489[_0x142c68(0xc4)]));}),{'rows':_0x2d7d95,'count':_0xf8795d};}async[_0x42f541(0x109)](_0x2aecde,_0xe7dadb){const _0x47482e=_0x42f541,{id:_0x53c3c0}=_0x2aecde['user'],{groupId:_0x1b20d7}=_0xe7dadb,_0x1c8434={'userId':_0x53c3c0,'isDelete':![]};_0x1b20d7&&Object[_0x47482e(0x10d)](_0x1c8434,{'groupId':_0x1b20d7});if(_0x1b20d7){const _0x5115f9=await this[_0x47482e(0xf5)][_0x47482e(0xc6)]({'where':{'isDelete':![]}});if(_0x5115f9===0x0)return[];}const _0x423a7e=await this['chatLogEntity']['find']({'where':_0x1c8434});return _0x423a7e[_0x47482e(0x9a)](_0x19d762=>{const _0x2a836b=_0x47482e,{prompt:_0x12e63a,role:_0x5ab019,answer:_0x25ce21,createdAt:_0x24fb0d,model:_0xcec369,conversationOptions:_0x13cd02,requestOptions:_0x131a3d,id:_0x226d4e,imageUrl:_0x580349}=_0x19d762;let _0x16e6dd=null,_0x569e1a=null;try{_0x16e6dd=JSON[_0x2a836b(0xf9)](_0x13cd02),_0x569e1a=JSON[_0x2a836b(0xf9)](_0x131a3d);}catch(_0x3e8af5){}return{'chatId':_0x226d4e,'dateTime':(0x0,utils_1[_0x2a836b(0xad)])(_0x24fb0d),'text':_0x5ab019==='user'?_0x12e63a:_0x25ce21,'inversion':_0x5ab019==='user','error':![],'conversationOptions':_0x16e6dd,'requestOptions':_0x569e1a,'imageUrl':_0x580349,'model':_0xcec369};});}async['deleteChatLog'](_0x28587,_0x20202e){const _0x3fae45=_0x42f541,{id:_0x48fe3c}=_0x28587['user'],{id:_0x250796}=_0x20202e,_0x501abc=await this[_0x3fae45(0x9c)][_0x3fae45(0xaf)]({'where':{'id':_0x250796,'userId':_0x48fe3c}});if(!_0x501abc)throw new common_1['HttpException'](_0x3fae45(0x101),common_1['HttpStatus'][_0x3fae45(0xc2)]);const _0x3a6ba1=await this[_0x3fae45(0x9c)]['update']({'id':_0x250796},{'isDelete':!![]});if(_0x3a6ba1[_0x3fae45(0x100)]>0x0)return'删除对话记录成功!';else throw new common_1['HttpException'](_0x3fae45(0x101),common_1[_0x3fae45(0x10a)]['BAD_REQUEST']);}async[_0x42f541(0xd2)](_0x591df2,_0x36759c){const _0x2df748=_0x42f541,{groupId:_0xb1243a}=_0x36759c,{id:_0x4eb307}=_0x591df2[_0x2df748(0xb7)],_0x4090a5=await this[_0x2df748(0xf5)][_0x2df748(0xaf)]({'where':{'id':_0xb1243a,'userId':_0x4eb307}});if(!_0x4090a5)throw new common_1[(_0x2df748(0xc5))]('你删除的对话记录不存在、请检查!',common_1[_0x2df748(0x10a)][_0x2df748(0xc2)]);const _0x1b8fe4=await this[_0x2df748(0x9c)][_0x2df748(0xe6)]({'groupId':_0xb1243a},{'isDelete':!![]});if(_0x1b8fe4[_0x2df748(0x100)]>0x0)return _0x2df748(0xc9);if(_0x1b8fe4[_0x2df748(0x100)]===0x0)throw new common_1[(_0x2df748(0xc5))](_0x2df748(0xb4),common_1[_0x2df748(0x10a)][_0x2df748(0xc2)]);}async[_0x42f541(0xfb)](_0x479633,_0x3f7602){const _0x8efcd9=_0x42f541,{id:_0x122c89}=_0x479633[_0x8efcd9(0xb7)],{appId:_0x21d072,page:page=0x1,size:size=0xa}=_0x3f7602,[_0x303986,_0x4b3bb5]=await this[_0x8efcd9(0x9c)][_0x8efcd9(0xe4)]({'where':{'userId':_0x122c89,'appId':_0x21d072,'role':_0x8efcd9(0xb0)},'order':{'id':'DESC'},'take':size,'skip':(page-0x1)*size});return{'rows':_0x303986,'count':_0x4b3bb5};}};ChatLogService=__decorate([(0x0,common_1['Injectable'])(),__param(0x0,(0x0,typeorm_1[_0x42f541(0x108)])(chatLog_entity_1[_0x42f541(0xc7)])),__param(0x1,(0x0,typeorm_1[_0x42f541(0x108)])(user_entity_1['UserEntity'])),__param(0x2,(0x0,typeorm_1['InjectRepository'])(chatGroup_entity_1[_0x42f541(0xee)])),__metadata(_0x42f541(0xa4),[typeorm_2[_0x42f541(0xd6)],typeorm_2[_0x42f541(0xd6)],typeorm_2[_0x42f541(0xd6)]])],ChatLogService),exports['ChatLogService']=ChatLogService;