"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const Module_1=__importDefault(require("../../common/Module")),feedback_1=require("../../protocol/feedback"),protocol_1=require("../../types/protocol"),common_1=require("../../config/common"),env_1=__importDefault(require("../../config/env")),fs_1=__importDefault(require("fs")),protocol_2=require("../../protocol"),api_1=require("../../config/api");class FeedbackModule extends Module_1.default{constructor(e){super(protocol_1.ModuleName.feedback),this.ctx={version:"",commitHash:""},this.ctx=e}[feedback_1.CmdEnum.Feedback](){const{feedbackUrl:e}=(0,common_1.getHelpConfig)();return e||""}[feedback_1.CmdEnum.DocUrl](){const{docList:e}=(0,common_1.getHelpConfig)();return Object.keys(e).map(o=>e[o])}[feedback_1.CmdEnum.FeedbackTip](){const{feedbackTip:e}=(0,common_1.getHelpConfig)();return e||(env_1.default.oversea?"The helpesk chat will be opened in your Lark App, please feedback there!":"The helpdesk chat will be opened in your Feishu App, please feedback there!")}async[feedback_1.CmdEnum.reportIssue](e){const o=this.log.bind(this,"info",feedback_1.CmdEnum.reportIssue);try{o("receiveParams","end",e);const t=this.execute(protocol_1.ModuleName.storage,protocol_2.StorageCmdEnum.Get,"uuid"),{types:r,time:c,desc:a,contact:s,pics:i,useLog:u}=e,n={uuid:t,types:JSON.stringify(r),time:c,desc:a,contact:s,version:this.ctx.version,commitHash:this.ctx.commitHash};let d=[];u&&(d=await this.logger.getLogs(new Date(c))),o("todayLogs","end",{logs:d}),i.forEach((e,o)=>{n["pics-"+o]=fs_1.default.createReadStream(e)});const l=[];return d.forEach((e,o)=>{const t=e+"copy";l.push(t),fs_1.default.copyFileSync(e,t),n["logs-"+o]=fs_1.default.createReadStream(t,{encoding:"utf8"})}),await this.execute(protocol_1.ModuleName.service,protocol_2.ServiceCmdEnum.Request,api_1.API.reportIssue,n,{headers:{"content-type":"multipart/form-data"}}),l.forEach(e=>{fs_1.default.unlinkSync(e)}),{flag:!0}}catch(e){return o("occurSomeError","end",{error:e}),{flag:!1,message:e.toString()}}}}exports.default=FeedbackModule;