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

1 line
5.7 KiB
JavaScript

'use strict';const _0x2147c3=_0x1c46;function _0x1c46(_0x12e9d7,_0x43d04f){const _0x3055dc=_0x3055();return _0x1c46=function(_0x1c4681,_0x1bb91c){_0x1c4681=_0x1c4681-0x175;let _0x3b3b63=_0x3055dc[_0x1c4681];return _0x3b3b63;},_0x1c46(_0x12e9d7,_0x43d04f);}(function(_0x2559aa,_0x39998d){const _0x4a7786=_0x1c46,_0x113aa7=_0x2559aa();while(!![]){try{const _0x4b6a54=parseInt(_0x4a7786(0x1ab))/0x1*(parseInt(_0x4a7786(0x197))/0x2)+-parseInt(_0x4a7786(0x17f))/0x3+-parseInt(_0x4a7786(0x180))/0x4*(-parseInt(_0x4a7786(0x1ac))/0x5)+parseInt(_0x4a7786(0x18e))/0x6+parseInt(_0x4a7786(0x1a7))/0x7*(parseInt(_0x4a7786(0x19b))/0x8)+-parseInt(_0x4a7786(0x188))/0x9+-parseInt(_0x4a7786(0x18d))/0xa;if(_0x4b6a54===_0x39998d)break;else _0x113aa7['push'](_0x113aa7['shift']());}catch(_0x390074){_0x113aa7['push'](_0x113aa7['shift']());}}}(_0x3055,0x4c0a6));function _0x3055(){const _0x23b949=['default','__decorate','push','design:paramtypes','21742OqVUsx','API_HOST','onModuleInit','获取列表失败','21096CSYTSW','绘制失败','uploadService','defineProperty','__esModule','status','@nestjs/common','https://api.stability.ai','all','message','stability\x20api\x20key\x20is\x20invalid,\x20','log','7CpJoRb','drawTextToImage','env','response','13ynSemo','5HLuxlE','axios','data','getEngines','HttpException','DrawService','metadata','HttpStatus','apiKey','base64','/text-to-image','271539JIeNCD','72524JXkEJY','Authorization','uploadFile','application/json','getOwnPropertyDescriptor','GET','STABILITY_API_KEY','apiHost','1916370JTuWIG','uuid','BAD_REQUEST','function','decorate','69990CjLrCx','2758878fYrDHu','../upload/upload.service','object','slice','UploadService'];_0x3055=function(){return _0x23b949;};return _0x3055();}var __decorate=this&&this[_0x2147c3(0x194)]||function(_0x160082,_0x5cbce9,_0x35cdf6,_0x222fdf){const _0xf684ba=_0x2147c3;var _0x361c82=arguments['length'],_0x67bc3d=_0x361c82<0x3?_0x5cbce9:_0x222fdf===null?_0x222fdf=Object[_0xf684ba(0x184)](_0x5cbce9,_0x35cdf6):_0x222fdf,_0x16934b;if(typeof Reflect===_0xf684ba(0x190)&&typeof Reflect[_0xf684ba(0x18c)]===_0xf684ba(0x18b))_0x67bc3d=Reflect[_0xf684ba(0x18c)](_0x160082,_0x5cbce9,_0x35cdf6,_0x222fdf);else{for(var _0x131607=_0x160082['length']-0x1;_0x131607>=0x0;_0x131607--)if(_0x16934b=_0x160082[_0x131607])_0x67bc3d=(_0x361c82<0x3?_0x16934b(_0x67bc3d):_0x361c82>0x3?_0x16934b(_0x5cbce9,_0x35cdf6,_0x67bc3d):_0x16934b(_0x5cbce9,_0x35cdf6))||_0x67bc3d;}return _0x361c82>0x3&&_0x67bc3d&&Object['defineProperty'](_0x5cbce9,_0x35cdf6,_0x67bc3d),_0x67bc3d;},__metadata=this&&this['__metadata']||function(_0x4ead05,_0x51b9fe){const _0x3e35d4=_0x2147c3;if(typeof Reflect===_0x3e35d4(0x190)&&typeof Reflect['metadata']==='function')return Reflect[_0x3e35d4(0x17a)](_0x4ead05,_0x51b9fe);};Object[_0x2147c3(0x19e)](exports,_0x2147c3(0x19f),{'value':!![]}),exports[_0x2147c3(0x179)]=void 0x0;const common_1=require(_0x2147c3(0x1a1)),axios_1=require(_0x2147c3(0x175)),uuid=require(_0x2147c3(0x189)),upload_service_1=require(_0x2147c3(0x18f));let DrawService=class DrawService{constructor(_0x2e5096){const _0x1b146a=_0x2147c3;this[_0x1b146a(0x19d)]=_0x2e5096;}async[_0x2147c3(0x199)](){const _0x4a4e06=_0x2147c3;var _0x1d9278;this[_0x4a4e06(0x187)]=(_0x1d9278=process['env'][_0x4a4e06(0x198)])!==null&&_0x1d9278!==void 0x0?_0x1d9278:_0x4a4e06(0x1a2),this[_0x4a4e06(0x17c)]=process[_0x4a4e06(0x1a9)][_0x4a4e06(0x186)],!this[_0x4a4e06(0x17c)]&&(this[_0x4a4e06(0x17c)]='*********'),this[_0x4a4e06(0x181)]='Bearer\x20'+this[_0x4a4e06(0x17c)];}async[_0x2147c3(0x177)](){const _0x1de8bb=_0x2147c3;var _0x17334b,_0x1d2e1f;const _0x3d48ac=this[_0x1de8bb(0x187)]+'/v1/engines/list',_0x334340=await(0x0,axios_1[_0x1de8bb(0x193)])(_0x3d48ac,{'method':_0x1de8bb(0x185),'headers':{'Authorization':this[_0x1de8bb(0x181)]}});_0x334340[_0x1de8bb(0x1a0)]===0x191&&console[_0x1de8bb(0x1a6)](_0x1de8bb(0x1a5)+((_0x17334b=_0x334340===null||_0x334340===void 0x0?void 0x0:_0x334340['data'])===null||_0x17334b===void 0x0?void 0x0:_0x17334b[_0x1de8bb(0x1a4)]));if(_0x334340[_0x1de8bb(0x1a0)]!==0xc8){console['log'](_0x334340[_0x1de8bb(0x1a0)]+'\x20'+((_0x1d2e1f=_0x334340===null||_0x334340===void 0x0?void 0x0:_0x334340['data'])===null||_0x1d2e1f===void 0x0?void 0x0:_0x1d2e1f[_0x1de8bb(0x1a4)])+'}');throw new common_1['HttpException'](_0x1de8bb(0x19a),common_1['HttpStatus'][_0x1de8bb(0x18a)]);}return _0x334340[_0x1de8bb(0x176)];}async[_0x2147c3(0x1a8)](_0x4bae4f){const _0xf207ff=_0x2147c3,{engineId:engineId='stable-diffusion-768-v2-1'}=_0x4bae4f,_0x3e075c={'Content-Type':_0xf207ff(0x183),'Accept':_0xf207ff(0x183),'Authorization':this['Authorization']},_0x595126=this[_0xf207ff(0x187)]+'/v1/generation/'+engineId+_0xf207ff(0x17e);try{const _0x2c82a7=await axios_1[_0xf207ff(0x193)]['post'](_0x595126,_0x4bae4f,{'headers':_0x3e075c});if(_0x2c82a7[_0xf207ff(0x1a0)]!==0xc8)throw new common_1['HttpException'](_0xf207ff(0x19c),common_1[_0xf207ff(0x17b)][_0xf207ff(0x18a)]);const _0x52f8f3=[];for(const _0x2160a5 of _0x2c82a7[_0xf207ff(0x176)]['artifacts']){const _0x152e3d=uuid['v4']()[_0xf207ff(0x191)](0x0,0xa)+'.png',_0x3bffcf=Buffer['from'](_0x2160a5[_0xf207ff(0x17d)],_0xf207ff(0x17d));_0x52f8f3[_0xf207ff(0x195)](this['uploadService'][_0xf207ff(0x182)]({'filename':_0x152e3d,'buffer':_0x3bffcf}));}const _0x2ff8c4=await Promise[_0xf207ff(0x1a3)](_0x52f8f3);return _0x2ff8c4;}catch(_0x440c6e){if(!(_0x440c6e===null||_0x440c6e===void 0x0?void 0x0:_0x440c6e['response']))throw new common_1[(_0xf207ff(0x178))]('绘制失败',common_1[_0xf207ff(0x17b)][_0xf207ff(0x18a)]);const {status:_0x5369fe,data:_0x6acdb2}=_0x440c6e[_0xf207ff(0x1aa)];throw new common_1[(_0xf207ff(0x178))](_0x6acdb2['message'],_0x5369fe);}}};DrawService=__decorate([(0x0,common_1['Injectable'])(),__metadata(_0x2147c3(0x196),[upload_service_1[_0x2147c3(0x192)]])],DrawService),exports[_0x2147c3(0x179)]=DrawService;