"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.uploadGamePkg=uploadGamePkg;const tslib_1=require("tslib"),url_config_1=require("../../config/url.config"),taskstatus_1=require("../../utils/taskstatus"),querystring_1=tslib_1.__importDefault(require("querystring")),cos_upload_1=require("../cos-upload"),fs_1=tslib_1.__importDefault(require("fs")),log=tslib_1.__importStar(require("../../utils/log")),progressupdate_1=require("../utils/progressupdate"),locales_1=tslib_1.__importDefault(require("../../utils/locales/locales")),businesstype_1=require("../../config/businesstype");async function uploadGamePkg(e){if(!fs_1.default.existsSync(e.pkgPath||"")||fs_1.default.statSync(e.pkgPath).isDirectory())throw new Error("[upload game pkg]failed! cant find file: "+e.pkgPath);const s=(0,progressupdate_1.transProgressUpdate)(e.onProgressUpdate||(()=>{})),t={appid:e.project.appid,version:e.version,desc:e.desc,robot:e.robot},o=`${url_config_1.GAME_PKG_UPLOAD_URL}?${querystring_1.default.stringify(t)}`,r=new taskstatus_1.TaskStatus(locales_1.default.config.UPLOAD.toString());s(r);const{fallback:a,uploadCOSCostTime:i}=await(0,cos_upload_1.uploadByCosSafelyWithMultiUpload)(e.pkgPath,o,e.project,e.robot,{getUploadInfo:url_config_1.GET_GAME_PKG_UPLOAD_INFO,getUploadSign:url_config_1.GET_GAME_PKG_UPLOAD_SIGN,getAsyncResult:url_config_1.GET_GAME_PKG_ASYNC_RESULT,businessType:businesstype_1.BUSINESS_TYPE.BusiType_UploadApkPlugin},e.onProgressUpdate);return null!=i||log.log("[upload game pkg] total cost time : "+i),a&&log.error("[upload game pkg] failed!"),r.done(),s(r),{success:!a}}