YiAi/YiAiQuickDeploy/dist/modules/chatLog/chatLog.service.js
2024-02-05 23:18:50 +08:00

1 line
15 KiB
JavaScript

'use strict';const _0x5c4b49=_0x3f6e;function _0x3f6e(_0x51bd6a,_0x319893){const _0xdaaa5d=_0xdaaa();return _0x3f6e=function(_0x3f6e7a,_0x508191){_0x3f6e7a=_0x3f6e7a-0xcf;let _0x55e1c5=_0xdaaa5d[_0x3f6e7a];return _0x55e1c5;},_0x3f6e(_0x51bd6a,_0x319893);}(function(_0x11d0a6,_0x1e848e){const _0x7611ba=_0x3f6e,_0x504885=_0x11d0a6();while(!![]){try{const _0x1f761b=parseInt(_0x7611ba(0xe0))/0x1+-parseInt(_0x7611ba(0xea))/0x2*(-parseInt(_0x7611ba(0xff))/0x3)+-parseInt(_0x7611ba(0x120))/0x4*(parseInt(_0x7611ba(0xdd))/0x5)+parseInt(_0x7611ba(0x10c))/0x6+parseInt(_0x7611ba(0x108))/0x7+parseInt(_0x7611ba(0x10e))/0x8*(parseInt(_0x7611ba(0x13a))/0x9)+-parseInt(_0x7611ba(0xd0))/0xa;if(_0x1f761b===_0x1e848e)break;else _0x504885['push'](_0x504885['shift']());}catch(_0x3e2b36){_0x504885['push'](_0x504885['shift']());}}}(_0xdaaa,0x39699));var __decorate=this&&this['__decorate']||function(_0x2409be,_0x1a6ccb,_0x53167f,_0x4f2fc2){const _0x879c63=_0x3f6e;var _0x8839cc=arguments[_0x879c63(0x11c)],_0x4bc4ef=_0x8839cc<0x3?_0x1a6ccb:_0x4f2fc2===null?_0x4f2fc2=Object[_0x879c63(0x12b)](_0x1a6ccb,_0x53167f):_0x4f2fc2,_0x3e8799;if(typeof Reflect===_0x879c63(0x115)&&typeof Reflect[_0x879c63(0xde)]===_0x879c63(0xec))_0x4bc4ef=Reflect['decorate'](_0x2409be,_0x1a6ccb,_0x53167f,_0x4f2fc2);else{for(var _0x72d093=_0x2409be[_0x879c63(0x11c)]-0x1;_0x72d093>=0x0;_0x72d093--)if(_0x3e8799=_0x2409be[_0x72d093])_0x4bc4ef=(_0x8839cc<0x3?_0x3e8799(_0x4bc4ef):_0x8839cc>0x3?_0x3e8799(_0x1a6ccb,_0x53167f,_0x4bc4ef):_0x3e8799(_0x1a6ccb,_0x53167f))||_0x4bc4ef;}return _0x8839cc>0x3&&_0x4bc4ef&&Object['defineProperty'](_0x1a6ccb,_0x53167f,_0x4bc4ef),_0x4bc4ef;},__metadata=this&&this[_0x5c4b49(0x10b)]||function(_0x4f3fed,_0x485ff8){const _0x445629=_0x5c4b49;if(typeof Reflect===_0x445629(0x115)&&typeof Reflect[_0x445629(0x12e)]===_0x445629(0xec))return Reflect[_0x445629(0x12e)](_0x4f3fed,_0x485ff8);},__param=this&&this[_0x5c4b49(0x101)]||function(_0x4f8858,_0x3e8f38){return function(_0x2895af,_0xf1cdfe){_0x3e8f38(_0x2895af,_0xf1cdfe,_0x4f8858);};};Object['defineProperty'](exports,_0x5c4b49(0xe7),{'value':!![]}),exports[_0x5c4b49(0xeb)]=void 0x0;function _0xdaaa(){const _0x124e1a=['setHeader','model','extend','xlsx','删除对话记录成功!','你操作的图片不存在、请检查!','answer','提问时间','HttpStatus','1829637TKtyal','paintCount','username','role','DALL-E2','6297450MUfJLd','userId','fileInfo','attachment;\x20filename=','log','用户邮箱','findOne','CHAT_TYPE','BAD_REQUEST','提问问题','thumbImg','type','InjectRepository','1765rLiRbm','decorate','affected','151502wWeMEY','assign','forEach','@nestjs/common','components','design:paramtypes','isGroup','__esModule','save','Not','143132QRxQCb','ChatLogService','function','/q/55','你推荐的图片不存在、请检查!','exportExcel','formatDate','map','?imageView2/1/w/','图片成功!','delByGroupId','你删除的对话记录不存在、请检查!','update','Repository','Content-Type','chatlog','ali','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','tencent','../user/user.entity','super','15tPjyRi','write','__param','?x-oss-process=image/resize,w_','userEntity','group','cos','chatGroupEntity','end','1013152cvCUcj','当前页面已经没有东西可以删除了!','../../common/constants/balance.constant','__metadata','134226kKiVis','chat.xlsx','8MBeQEM','querAllChatLog','../chatGroup/chatGroup.entity','prompt','includes','recDrawImg','用户名','object','@nine.com','Workbook','createdAt','Like','回答答案','@nestjs/typeorm','length','DESC','chatLogEntity','byAppId','168NkbuRZ','find','PAINT_TYPE','HttpException','message_id','ChatGroupEntity','chatList','findAndCount','parse','email','deleteChatLog','getOwnPropertyDescriptor','rec','dall-e-3','metadata','user','DeductionKey'];_0xdaaa=function(){return _0x124e1a;};return _0xdaaa();}const common_1=require(_0x5c4b49(0xe3)),typeorm_1=require(_0x5c4b49(0x11b)),chatLog_entity_1=require('./chatLog.entity'),typeorm_2=require('typeorm'),balance_constant_1=require(_0x5c4b49(0x10a)),user_entity_1=require(_0x5c4b49(0xfd)),utils_1=require('../../common/utils'),exceljs_1=require('exceljs'),chatGroup_entity_1=require(_0x5c4b49(0x110));let ChatLogService=class ChatLogService{constructor(_0x355521,_0x4dc03,_0x4c510b){const _0x32c6ab=_0x5c4b49;this[_0x32c6ab(0x11e)]=_0x355521,this['userEntity']=_0x4dc03,this[_0x32c6ab(0x106)]=_0x4c510b;}async['saveChatLog'](_0x509a76){const _0x5a5562=_0x5c4b49;return await this[_0x5a5562(0x11e)][_0x5a5562(0xe8)](_0x509a76);}async['querDrawLog'](_0x81f74f,_0x4d0a12){const _0x3abeb7=_0x5c4b49,{id:_0x125dda}=_0x81f74f[_0x3abeb7(0x12f)],{model:_0x15ab41}=_0x4d0a12,_0x1fcd31={'userId':_0x125dda,'type':balance_constant_1[_0x3abeb7(0x130)][_0x3abeb7(0x122)]};_0x15ab41&&(_0x1fcd31[_0x3abeb7(0x132)]=_0x15ab41,_0x15ab41===_0x3abeb7(0xcf)&&(_0x1fcd31['model']=(0x0,typeorm_2['In'])(['DALL-E2',_0x3abeb7(0x12d)])));const _0x16cf9e=await this[_0x3abeb7(0x11e)][_0x3abeb7(0x121)]({'where':_0x1fcd31,'order':{'id':_0x3abeb7(0x11d)},'select':['id',_0x3abeb7(0x137),'prompt',_0x3abeb7(0x124),_0x3abeb7(0x104),_0x3abeb7(0x132),_0x3abeb7(0x133),_0x3abeb7(0xdb),_0x3abeb7(0xd2)]});return _0x16cf9e[_0x3abeb7(0xe2)](_0x362247=>{const _0x5a0b7d=_0x3abeb7;if(_0x362247['type']==='paintCount'){const _0x4d213f=_0x362247['model']==='mj'?0x136:0xa0,_0x43997b=_0x362247['answer'][_0x5a0b7d(0x112)](_0x5a0b7d(0x105))?'tencent':'ali',_0x2900c4=_0x43997b===_0x5a0b7d(0xfc)?_0x5a0b7d(0xf2)+_0x4d213f+_0x5a0b7d(0xed):_0x5a0b7d(0x102)+_0x4d213f;_0x362247[_0x5a0b7d(0xda)]=_0x362247['answer']+_0x2900c4;try{_0x362247[_0x5a0b7d(0xd2)]=_0x362247['fileInfo']?JSON[_0x5a0b7d(0x128)](_0x362247[_0x5a0b7d(0xd2)]):null;}catch(_0x33d3db){_0x362247[_0x5a0b7d(0xd2)]={};}}}),_0x16cf9e;}async['querAllDrawLog'](_0x5890bd){const _0x40e434=_0x5c4b49,{page:page=0x1,size:size=0x14,rec:_0x3bc529,userId:_0x28736d,model:_0x172d26}=_0x5890bd,_0x2cb849={'type':balance_constant_1[_0x40e434(0x130)][_0x40e434(0x122)],'prompt':(0x0,typeorm_2['Not'])(''),'answer':(0x0,typeorm_2['Not'])('')};_0x3bc529&&Object[_0x40e434(0xe1)](_0x2cb849,{'rec':_0x3bc529}),_0x28736d&&Object[_0x40e434(0xe1)](_0x2cb849,{'userId':_0x28736d});_0x172d26&&(_0x2cb849[_0x40e434(0x132)]=_0x172d26,_0x172d26===_0x40e434(0xcf)&&(_0x2cb849['model']=(0x0,typeorm_2['In'])([_0x40e434(0xcf),_0x40e434(0x12d)])));const [_0x446dd6,_0xc86ab6]=await this[_0x40e434(0x11e)][_0x40e434(0x127)]({'order':{'id':_0x40e434(0x11d)},'skip':(page-0x1)*size,'take':size,'where':_0x2cb849});return _0x446dd6[_0x40e434(0xe2)](_0x23eed8=>{const _0x395e07=_0x40e434;var _0x4927d2;if(_0x23eed8[_0x395e07(0xdb)]===_0x395e07(0x13b)){const _0x20a133=_0x23eed8[_0x395e07(0x132)]==='mj'?0x136:0xa0,_0x159654=_0x23eed8[_0x395e07(0x137)][_0x395e07(0x112)](_0x395e07(0x105))?_0x395e07(0xfc):_0x395e07(0xfa),_0x30c068=_0x159654==='tencent'?_0x395e07(0xf2)+_0x20a133+_0x395e07(0xed):_0x395e07(0x102)+_0x20a133;_0x23eed8[_0x395e07(0xda)]=_0x23eed8[_0x395e07(0x137)]+_0x30c068;try{const _0x5e0c04=_0x23eed8[_0x395e07(0x133)]?JSON[_0x395e07(0x128)](_0x23eed8[_0x395e07(0x133)]):null;_0x5e0c04&&(_0x5e0c04?_0x23eed8[_0x395e07(0xe6)]=((_0x4927d2=_0x5e0c04===null||_0x5e0c04===void 0x0?void 0x0:_0x5e0c04[_0x395e07(0xe4)][0x0])===null||_0x4927d2===void 0x0?void 0x0:_0x4927d2[_0x395e07(0xe4)][_0x395e07(0x11c)])===0x5:_0x23eed8[_0x395e07(0xe6)]=![]);}catch(_0x32e745){console[_0x395e07(0xd4)]('querAllDrawLog\x20Json\x20parse\x20error',_0x32e745);}}}),{'rows':_0x446dd6,'count':_0xc86ab6};}async[_0x5c4b49(0x113)](_0x419fc0){const _0x6c43c4=_0x5c4b49,{id:_0x5777b7}=_0x419fc0,_0xd1378b=await this['chatLogEntity'][_0x6c43c4(0xd6)]({'where':{'id':_0x5777b7,'type':balance_constant_1[_0x6c43c4(0x130)][_0x6c43c4(0x122)]}});if(!_0xd1378b)throw new common_1[(_0x6c43c4(0x123))](_0x6c43c4(0xee),common_1[_0x6c43c4(0x139)][_0x6c43c4(0xd8)]);const _0x111df0=_0xd1378b[_0x6c43c4(0x12c)]===0x1?0x0:0x1,_0x1136d8=await this[_0x6c43c4(0x11e)][_0x6c43c4(0xf6)]({'id':_0x5777b7},{'rec':_0x111df0});if(_0x1136d8[_0x6c43c4(0xdf)]>0x0)return(_0x111df0?'推荐':'取消推荐')+_0x6c43c4(0xf3);throw new common_1[(_0x6c43c4(0x123))](_0x6c43c4(0x136),common_1[_0x6c43c4(0x139)][_0x6c43c4(0xd8)]);}async[_0x5c4b49(0xef)](_0x567826,_0x1996cc){const _0x29e102=_0x5c4b49,_0x32498a={'type':balance_constant_1[_0x29e102(0x130)]['CHAT_TYPE']},{page:page=0x1,size:size=0x1e,prompt:_0x383840,email:_0x10bee3}=_0x567826;_0x383840&&Object[_0x29e102(0xe1)](_0x32498a,{'prompt':(0x0,typeorm_2[_0x29e102(0x119)])('%'+_0x383840+'%')});if(_0x10bee3){const _0x2b0815=await this[_0x29e102(0x103)][_0x29e102(0xd6)]({'where':{'email':_0x10bee3}});(_0x2b0815===null||_0x2b0815===void 0x0?void 0x0:_0x2b0815['id'])&&Object[_0x29e102(0xe1)](_0x32498a,{'userId':_0x2b0815['id']});}const [_0x31bfbe,_0x26c988]=await this[_0x29e102(0x11e)]['findAndCount']({'order':{'id':_0x29e102(0x11d)},'skip':(page-0x1)*size,'take':size,'where':_0x32498a}),_0x2d476d=_0x31bfbe[_0x29e102(0xf1)](_0xc598ab=>_0xc598ab['userId']),_0x2319e9=await this[_0x29e102(0x103)][_0x29e102(0x121)]({'where':{'id':(0x0,typeorm_2['In'])(_0x2d476d)}}),_0x406cfe=_0x31bfbe['map'](_0xbb6481=>{const _0x1a22b3=_0x29e102,_0x37aa7a=_0x2319e9['find'](_0x3bbc4b=>_0x3bbc4b['id']===_0xbb6481[_0x1a22b3(0xd1)]);return{'username':_0x37aa7a?_0x37aa7a[_0x1a22b3(0x13c)]:'','email':_0x37aa7a?_0x37aa7a[_0x1a22b3(0x129)]:'','prompt':_0xbb6481['prompt'],'answer':_0xbb6481['answer'],'createdAt':(0x0,utils_1[_0x1a22b3(0xf0)])(_0xbb6481[_0x1a22b3(0x118)])};}),_0x379f77=new exceljs_1['default'][(_0x29e102(0x117))](),_0xbcdaef=_0x379f77['addWorksheet'](_0x29e102(0xf9));_0xbcdaef['columns']=[{'header':_0x29e102(0x114),'key':'username','width':0x14},{'header':_0x29e102(0xd5),'key':_0x29e102(0x129),'width':0x14},{'header':_0x29e102(0x138),'key':_0x29e102(0x118),'width':0x14},{'header':_0x29e102(0xd9),'key':_0x29e102(0x111),'width':0x50},{'header':_0x29e102(0x11a),'key':_0x29e102(0x137),'width':0x96}],_0x406cfe['forEach'](_0x1668a1=>_0xbcdaef['addRow'](_0x1668a1)),_0x1996cc[_0x29e102(0x131)](_0x29e102(0xf8),_0x29e102(0xfb)),_0x1996cc['setHeader']('Content-Disposition',_0x29e102(0xd3)+_0x29e102(0x10d)),await _0x379f77[_0x29e102(0x134)][_0x29e102(0x100)](_0x1996cc),_0x1996cc[_0x29e102(0x107)]();}async[_0x5c4b49(0x10f)](_0x28dba2,_0x36979c){const _0x1347a0=_0x5c4b49,{page:page=0x1,size:size=0x14,userId:_0x252948,prompt:_0x498bb1}=_0x28dba2,_0x3e5507={'type':balance_constant_1[_0x1347a0(0x130)][_0x1347a0(0xd7)],'prompt':(0x0,typeorm_2[_0x1347a0(0xe9)])('')};_0x252948&&Object[_0x1347a0(0xe1)](_0x3e5507,{'userId':_0x252948}),_0x498bb1&&Object[_0x1347a0(0xe1)](_0x3e5507,{'prompt':(0x0,typeorm_2[_0x1347a0(0x119)])('%'+_0x498bb1+'%')});const [_0x4d98e3,_0x52f61a]=await this['chatLogEntity'][_0x1347a0(0x127)]({'order':{'id':_0x1347a0(0x11d)},'skip':(page-0x1)*size,'take':size,'where':_0x3e5507}),_0x47b2a8=_0x4d98e3[_0x1347a0(0xf1)](_0x2232f0=>_0x2232f0[_0x1347a0(0xd1)]),_0x377fb1=await this['userEntity'][_0x1347a0(0x121)]({'where':{'id':(0x0,typeorm_2['In'])(_0x47b2a8)},'select':['id','username',_0x1347a0(0x129)]});return _0x4d98e3[_0x1347a0(0xe2)](_0x4bb082=>{const _0xa9a779=_0x1347a0,{username:_0x29a72d,email:_0x5a1bdf}=_0x377fb1['find'](_0x490298=>_0x490298['id']===_0x4bb082['userId'])||{};_0x4bb082[_0xa9a779(0x13c)]=_0x29a72d,_0x4bb082[_0xa9a779(0x129)]=_0x5a1bdf;}),_0x36979c['user'][_0x1347a0(0x13d)]!==_0x1347a0(0xfe)&&_0x4d98e3[_0x1347a0(0xe2)](_0x656651=>_0x656651[_0x1347a0(0x129)]=(0x0,utils_1['maskEmail'])(_0x656651[_0x1347a0(0x129)])),_0x4d98e3['forEach'](_0x3e1a1f=>{const _0x508279=_0x1347a0;!_0x3e1a1f[_0x508279(0x129)]&&(_0x3e1a1f['email']=(_0x3e1a1f===null||_0x3e1a1f===void 0x0?void 0x0:_0x3e1a1f[_0x508279(0xd1)])+_0x508279(0x116)),!_0x3e1a1f[_0x508279(0x13c)]&&(_0x3e1a1f[_0x508279(0x13c)]='游客'+(_0x3e1a1f===null||_0x3e1a1f===void 0x0?void 0x0:_0x3e1a1f[_0x508279(0xd1)]));}),{'rows':_0x4d98e3,'count':_0x52f61a};}async[_0x5c4b49(0x126)](_0x30527b,_0x1446dd){const _0x164ae0=_0x5c4b49,{id:_0x15e516}=_0x30527b[_0x164ae0(0x12f)],{groupId:_0x54fa2f}=_0x1446dd,_0x35e2e3={'userId':_0x15e516,'isDelete':![]};_0x54fa2f&&Object[_0x164ae0(0xe1)](_0x35e2e3,{'groupId':_0x54fa2f});if(_0x54fa2f){const _0x2b57be=await this[_0x164ae0(0x106)]['count']({'where':{'isDelete':![]}});if(_0x2b57be===0x0)return[];}const _0x3ff24=await this['chatLogEntity'][_0x164ae0(0x121)]({'where':_0x35e2e3});return _0x3ff24[_0x164ae0(0xf1)](_0x557dc3=>{const _0x5ac085=_0x164ae0,{prompt:_0x560760,role:_0x4c86ee,answer:_0x38bbcf,createdAt:_0x8f5801,model:_0x174982,conversationOptions:_0x369b83,requestOptions:_0x228f8c,id:_0xa44e97,imageUrl:_0x2d86f8}=_0x557dc3;let _0x548edb=null,_0x55589c=null;try{_0x548edb=JSON[_0x5ac085(0x128)](_0x369b83),_0x55589c=JSON[_0x5ac085(0x128)](_0x228f8c);}catch(_0x11167b){}return{'chatId':_0xa44e97,'dateTime':(0x0,utils_1[_0x5ac085(0xf0)])(_0x8f5801),'text':_0x4c86ee===_0x5ac085(0x12f)?_0x560760:_0x38bbcf,'inversion':_0x4c86ee===_0x5ac085(0x12f),'error':![],'conversationOptions':_0x548edb,'requestOptions':_0x55589c,'imageUrl':_0x2d86f8,'model':_0x174982};});}async[_0x5c4b49(0x12a)](_0x19afe3,_0x1612d0){const _0x150808=_0x5c4b49,{id:_0x28dbf0}=_0x19afe3[_0x150808(0x12f)],{id:_0x4762ea}=_0x1612d0,_0x5dd9ff=await this['chatLogEntity'][_0x150808(0xd6)]({'where':{'id':_0x4762ea,'userId':_0x28dbf0}});if(!_0x5dd9ff)throw new common_1[(_0x150808(0x123))](_0x150808(0xf5),common_1['HttpStatus'][_0x150808(0xd8)]);const _0x4e3c73=await this[_0x150808(0x11e)][_0x150808(0xf6)]({'id':_0x4762ea},{'isDelete':!![]});if(_0x4e3c73[_0x150808(0xdf)]>0x0)return _0x150808(0x135);else throw new common_1['HttpException'](_0x150808(0xf5),common_1[_0x150808(0x139)][_0x150808(0xd8)]);}async[_0x5c4b49(0xf4)](_0x1e9ae7,_0x4863bd){const _0x4c0abd=_0x5c4b49,{groupId:_0x2d9064}=_0x4863bd,{id:_0x46f1d0}=_0x1e9ae7[_0x4c0abd(0x12f)],_0x2ef518=await this['chatGroupEntity'][_0x4c0abd(0xd6)]({'where':{'id':_0x2d9064,'userId':_0x46f1d0}});if(!_0x2ef518)throw new common_1[(_0x4c0abd(0x123))](_0x4c0abd(0xf5),common_1[_0x4c0abd(0x139)][_0x4c0abd(0xd8)]);const _0x569a8d=await this[_0x4c0abd(0x11e)]['update']({'groupId':_0x2d9064},{'isDelete':!![]});if(_0x569a8d[_0x4c0abd(0xdf)]>0x0)return _0x4c0abd(0x135);if(_0x569a8d['affected']===0x0)throw new common_1[(_0x4c0abd(0x123))](_0x4c0abd(0x109),common_1[_0x4c0abd(0x139)][_0x4c0abd(0xd8)]);}async[_0x5c4b49(0x11f)](_0x4ec573,_0x4b239f){const _0x3e0b87=_0x5c4b49,{id:_0x3ab47c}=_0x4ec573[_0x3e0b87(0x12f)],{appId:_0x4cbab9,page:page=0x1,size:size=0xa}=_0x4b239f,[_0x2c50c9,_0x1ed230]=await this[_0x3e0b87(0x11e)][_0x3e0b87(0x127)]({'where':{'userId':_0x3ab47c,'appId':_0x4cbab9,'role':'assistant'},'order':{'id':_0x3e0b87(0x11d)},'take':size,'skip':(page-0x1)*size});return{'rows':_0x2c50c9,'count':_0x1ed230};}};ChatLogService=__decorate([(0x0,common_1['Injectable'])(),__param(0x0,(0x0,typeorm_1[_0x5c4b49(0xdc)])(chatLog_entity_1['ChatLogEntity'])),__param(0x1,(0x0,typeorm_1[_0x5c4b49(0xdc)])(user_entity_1['UserEntity'])),__param(0x2,(0x0,typeorm_1[_0x5c4b49(0xdc)])(chatGroup_entity_1[_0x5c4b49(0x125)])),__metadata(_0x5c4b49(0xe5),[typeorm_2[_0x5c4b49(0xf7)],typeorm_2[_0x5c4b49(0xf7)],typeorm_2[_0x5c4b49(0xf7)]])],ChatLogService),exports['ChatLogService']=ChatLogService;