"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.miniappCloudUpload=miniappCloudUpload;const tslib_1=require("tslib"),log=tslib_1.__importStar(require("../utils/log")),upload_1=require("./miniapp/upload"),archive_1=require("./miniapp/archive"),checkBuildArgument_1=require("./miniapp/checkBuildArgument"),moment_1=tslib_1.__importDefault(require("moment")),getcompiler_1=require("./getcompiler"),report_1=require("../utils/report"),crypto=require("crypto");function generateUint64(){const e=crypto.randomBytes(4).readUInt32BE(0),r=crypto.randomBytes(4).readUInt32BE(0);return((BigInt(e)<<BigInt(32))+BigInt(r)).toString()}async function miniappCloudUpload(e){var r,t,o;let i;const n=Date.now();try{if(!e.version)throw new Error("缺少参数 version");if(!e.project)throw new Error("缺少参数 project");const n=null===(r=e.iOSPlatform)||void 0===r||r,a=null===(t=e.androidPlatform)||void 0===t||t;if(!n&&!a)throw new Error("至少选择一个平台上传资源包");const{project:s}=e,p=await s.miniappAttr();if(!(null!==(o=null==p?void 0:p.cpa_info.use_cloud_sync)&&void 0!==o&&o))throw new Error("暂未开通使用此功能，请先在多端控制台开通使用");const c={version:e.version,desc:e.desc||`CI robot ${e.robot||1} 在 ${(0,moment_1.default)().format("LLL")} 提交上传`,targetPlatform:"mini-android",miniappOptions:{miniappPkgType:checkBuildArgument_1.IMiniappPkgType.Release,useCloudSync:!0,remoteDebugEnable:!1,archVersion:1},outputDir:""};n&&a&&(c.miniappOptions.uploadId=generateUint64()),a&&(c.targetPlatform="mini-android",await(0,upload_1.upload)(Object.assign(Object.assign(Object.assign({},e),c),(0,archive_1.getUploadOptions)())),log.success("上传 Android 资源包成功")),n&&(c.targetPlatform="mini-ios",await(0,upload_1.upload)(Object.assign(Object.assign(Object.assign({},e),c),(0,archive_1.getUploadOptions)())),log.success("上传 iOS 资源包成功"));(await(0,getcompiler_1.getCompiler)(e.project,e.setting||{useProjectConfig:!1})).destroy(),i={success:!0,errmsg:"上传资源包成功"}}catch(e){log.error("上传资源包失败：",e.message),i={success:!1,errmsg:"上传资源包失败："+e.message}}const a=Date.now()-n;return e.project&&(0,report_1.reportAction)("miniappCloudUpload",i.success?0:-1,i.errmsg,a,e.project),i}