@cloudbase/js-sdk
Version:
cloudbase javascript sdk
1 lines • 30.8 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("cloudbase_storage",[],t):"object"==typeof exports?exports.cloudbase_storage=t():e.cloudbase_storage=t()}("undefined"!=typeof window?window:this,(()=>(()=>{"use strict";var e={352:(e,t,n)=>{n.r(t),n.d(t,{registerStorage:()=>H});var o="@cloudbase/js-sdk";function r(){return o}var i,s={INVALID_PARAMS:"INVALID_PARAMS",INVALID_SYNTAX:"INVALID_SYNTAX",INVALID_OPERATION:"INVALID_OPERATION",OPERATION_FAIL:"OPERATION_FAIL",NETWORK_ERROR:"NETWORK_ERROR",UNKOWN_ERROR:"UNKOWN_ERROR"};!function(e){e.local="local",e.none="none",e.session="session"}(i||(i={}));function a(e){return"string"==typeof e}function c(e,t){console.warn("[".concat(r(),"][").concat(e,"]:").concat(t))}var u,l,d=(u=function(e,t){return u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},u(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}u(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),p=function(){return p=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},p.apply(this,arguments)},f=function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{c(o.next(e))}catch(e){i(e)}}function a(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((o=o.apply(e,t||[])).next())}))},h=function(e,t){var n,o,r,i,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,o&&(r=2&a[0]?o.return:a[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,a[1])).done)return r;switch(o=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,o=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((r=(r=s.trys).length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){s.label=a[1];break}if(6===a[0]&&s.label<r[1]){s.label=r[1],r=a;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(a);break}r[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],o=0}finally{n=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};!function(e){function t(t){var n=e.call(this)||this,o=t.timeout,r=t.timeoutMsg,i=t.restrictedMethods;return n.timeout=o||0,n.timeoutMsg=r||"请求超时",n.restrictedMethods=i||["get","post","upload","download"],n}d(t,e),t.prototype.get=function(e){return this.request(p(p({},e),{method:"get"}),this.restrictedMethods.includes("get"))},t.prototype.post=function(e){return this.request(p(p({},e),{method:"post"}),this.restrictedMethods.includes("post"))},t.prototype.put=function(e){return this.request(p(p({},e),{method:"put"}))},t.prototype.upload=function(e){var t=e.data,n=e.file,o=e.name,r=e.method,i=e.headers,s=void 0===i?{}:i,a={post:"post",put:"put"}[null==r?void 0:r.toLowerCase()]||"put",c=new FormData;return"post"===a?(Object.keys(t).forEach((function(e){c.append(e,t[e])})),c.append("key",o),c.append("file",n),this.request(p(p({},e),{data:c,method:a}),this.restrictedMethods.includes("upload"))):this.request(p(p({},e),{method:"put",headers:s,body:n}),this.restrictedMethods.includes("upload"))},t.prototype.download=function(e){return f(this,void 0,void 0,(function(){var t,n,o,r;return h(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(p(p({},e),{headers:{},responseType:"blob"}))];case 1:return t=i.sent().data,n=window.URL.createObjectURL(new Blob([t])),o=decodeURIComponent(new URL(e.url).pathname.split("/").pop()||""),(r=document.createElement("a")).href=n,r.setAttribute("download",o),r.style.display="none",document.body.appendChild(r),r.click(),window.URL.revokeObjectURL(n),document.body.removeChild(r),[3,3];case 2:return i.sent(),[3,3];case 3:return[2,new Promise((function(t){t({statusCode:200,tempFilePath:e.url})}))]}}))}))},t.prototype.fetch=function(e){var t;return f(this,void 0,void 0,(function(){var n,o,r,i,s,a,c,u,l,d,y,m,g,v=this;return h(this,(function(b){switch(b.label){case 0:return n=new AbortController,o=e.url,r=e.enableAbort,i=void 0!==r&&r,s=e.stream,a=void 0!==s&&s,c=e.signal,u=e.timeout,l=e.shouldThrowOnError,d=void 0===l||l,y=null!=u?u:this.timeout,c&&(c.aborted&&n.abort(),c.addEventListener("abort",(function(){return n.abort()}))),m=null,i&&y&&(m=setTimeout((function(){console.warn(v.timeoutMsg),n.abort(new Error(v.timeoutMsg))}),y)),[4,fetch(o,p(p({},e),{signal:n.signal})).then((function(e){return f(v,void 0,void 0,(function(){var t,n,o;return h(this,(function(r){switch(r.label){case 0:return clearTimeout(m),d?e.ok?(t=e,[3,3]):[3,1]:[3,4];case 1:return o=(n=Promise).reject,[4,e.json()];case 2:t=o.apply(n,[r.sent()]),r.label=3;case 3:return[2,t];case 4:return[2,e]}}))}))})).catch((function(e){if(clearTimeout(m),d)return Promise.reject(e)}))];case 1:return g=b.sent(),[2,{data:a?g.body:(null===(t=g.headers.get("content-type"))||void 0===t?void 0:t.includes("application/json"))?g.json():g.text(),statusCode:g.status,header:g.headers}]}}))}))},t.prototype.request=function(e,t){var n=this;void 0===t&&(t=!1);var o=String(e.method).toLowerCase()||"get";return new Promise((function(r){var i,s,a,c=e.url,u=e.headers,l=void 0===u?{}:u,d=e.data,p=e.responseType,f=e.withCredentials,h=e.body,y=e.onUploadProgress,m=function(e,t,n){void 0===n&&(n={});var o=/\?/.test(t),r="";return Object.keys(n).forEach((function(e){""===r?!o&&(t+="?"):r+="&",r+="".concat(e,"=").concat(encodeURIComponent(n[e]))})),/^http(s)?:\/\//.test(t+=r)?t:"".concat(e).concat(t)}("https:",c,"get"===o?d:{}),g=new XMLHttpRequest;g.open(o,m),p&&(g.responseType=p),Object.keys(l).forEach((function(e){g.setRequestHeader(e,l[e])})),y&&g.upload.addEventListener("progress",y),g.onreadystatechange=function(){var e={};if(4===g.readyState){var t=g.getAllResponseHeaders().trim().split(/[\r\n]+/),n={};t.forEach((function(e){var t=e.split(": "),o=t.shift().toLowerCase(),r=t.join(": ");n[o]=r})),e.header=n,e.statusCode=g.status;try{e.data="blob"===p?g.response:JSON.parse(g.responseText)}catch(t){e.data="blob"===p?g.response:g.responseText}clearTimeout(i),r(e)}},t&&n.timeout&&(i=setTimeout((function(){console.warn(n.timeoutMsg),g.abort()}),n.timeout)),a=d,s="[object FormData]"===Object.prototype.toString.call(a)?d:"application/x-www-form-urlencoded"===l["content-type"]?function(e){void 0===e&&(e={});var t=[];return Object.keys(e).forEach((function(n){t.push("".concat(n,"=").concat(encodeURIComponent(e[n])))})),t.join("&")}(d):h||(d?JSON.stringify(d):void 0),f&&(g.withCredentials=!0),g.send(s)}))}}((function(){})),function(e){e.WEB="web",e.WX_MP="wx_mp"}(l||(l={}));var y=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function o(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),m=function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{c(o.next(e))}catch(e){i(e)}}function a(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((o=o.apply(e,t||[])).next())}))},g=function(e,t){var n,o,r,i,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,o&&(r=2&a[0]?o.return:a[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,a[1])).done)return r;switch(o=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,o=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((r=(r=s.trys).length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){s.label=a[1];break}if(6===a[0]&&s.label<r[1]){s.label=r[1],r=a;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(a);break}r[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],o=0}finally{n=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},v=function(e){function t(t){var n=e.call(this)||this;return n.root=t,t.tcbCacheObject||(t.tcbCacheObject={}),n}return y(t,e),t.prototype.setItem=function(e,t){this.root.tcbCacheObject[e]=t},t.prototype.getItem=function(e){return this.root.tcbCacheObject[e]},t.prototype.removeItem=function(e){delete this.root.tcbCacheObject[e]},t.prototype.clear=function(){delete this.root.tcbCacheObject},t}((function(){}));!function(){function e(e){this.keys={};var t=e.persistence,n=e.platformInfo,o=void 0===n?{}:n,r=e.keys,i=void 0===r?{}:r;this.platformInfo=o,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||t,this.storage=function(e,t){switch(e){case"local":default:return t.localStorage?t.localStorage:(c(s.INVALID_PARAMS,"localStorage is not supported on current platform"),new v(t.root));case"none":return new v(t.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=i)}Object.defineProperty(e.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),e.prototype.setStore=function(e,t,n){if("async"!==this.mode){if(this.storage)try{var o={version:n||"localCachev1",content:t};this.storage.setItem(e,JSON.stringify(o))}catch(e){throw new Error(JSON.stringify({code:s.OPERATION_FAIL,msg:"[".concat(r(),"][").concat(s.OPERATION_FAIL,"]setStore failed"),info:e}))}}else c(s.INVALID_OPERATION,"current platform's storage is asynchronous, please use setStoreAsync insteed")},e.prototype.setStoreAsync=function(e,t,n){return m(this,void 0,void 0,(function(){var o;return g(this,(function(r){switch(r.label){case 0:if(!this.storage)return[2];r.label=1;case 1:return r.trys.push([1,3,,4]),o={version:n||"localCachev1",content:t},[4,this.storage.setItem(e,JSON.stringify(o))];case 2:return r.sent(),[3,4];case 3:return r.sent(),[2];case 4:return[2]}}))}))},e.prototype.getStore=function(e,t){var n;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!0})||void 0===n?void 0:n.tcb_token))return{IS_MP_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(e){return""}t=t||"localCachev1";var o=this.storage.getItem(e);return o&&o.indexOf(t)>=0?JSON.parse(o).content:""}c(s.INVALID_OPERATION,"current platform's storage is asynchronous, please use getStoreAsync insteed")},e.prototype.getStoreAsync=function(e,t){var n;return m(this,void 0,void 0,(function(){var o;return g(this,(function(r){switch(r.label){case 0:try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!0})||void 0===n?void 0:n.tcb_token))return[2,{IS_MP_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(e){return[2,""]}return t=t||"localCachev1",[4,this.storage.getItem(e)];case 1:return(o=r.sent())&&o.indexOf(t)>=0?[2,JSON.parse(o).content]:[2,""]}}))}))},e.prototype.removeStore=function(e){"async"!==this.mode?this.storage.removeItem(e):c(s.INVALID_OPERATION,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},e.prototype.removeStoreAsync=function(e){return m(this,void 0,void 0,(function(){return g(this,(function(t){switch(t.label){case 0:return[4,this.storage.removeItem(e)];case 1:return t.sent(),[2]}}))}))}}();var b=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function o(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),w=function(e,t){this.data=t||null,this.name=e},I=function(e){function t(t,n){var o=e.call(this,"error",{error:t,data:n})||this;return o.error=t,o}return b(t,e),t}(w),O=function(){function e(){this.listeners={}}return e.prototype.on=function(e,t){return function(e,t,n){n[e]=n[e]||[],n[e].push(t)}(e,t,this.listeners),this},e.prototype.off=function(e,t){return function(e,t,n){if(null==n?void 0:n[e]){var o=n[e].indexOf(t);-1!==o&&n[e].splice(o,1)}}(e,t,this.listeners),this},e.prototype.fire=function(e,t){if(e instanceof I)return console.error(e.error),this;var n=a(e)?new w(e,t||{}):e,o=n.name;if(this.listens(o)){n.target=this;for(var r=0,i=this.listeners[o]?function(e,t,n){if(n||2===arguments.length)for(var o,r=0,i=t.length;r<i;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}([],this.listeners[o],!0):[];r<i.length;r++)i[r].call(this,n)}return this},e.prototype.listens=function(e){return this.listeners[e]&&this.listeners[e].length>0},e}();function _(e){this.message=e}function A(e){this.message=e}new O,new O,"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox"),_.prototype=new Error,_.prototype.name="InvalidCharacterError","undefined"!=typeof window&&window.atob&&window.atob.bind(window),A.prototype=new Error,A.prototype.name="InvalidTokenError";var S,R=function(){return R=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},R.apply(this,arguments)},L=function(e,t,n,o){var r,i=arguments.length,s=i<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,o);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(s=(i<3?r(s):i>3?r(t,n,s):r(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},F=function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},P=function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{c(o.next(e))}catch(e){i(e)}}function a(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((o=o.apply(e,t||[])).next())}))},j=function(e,t){var n,o,r,i,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,o&&(r=2&a[0]?o.return:a[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,a[1])).done)return r;switch(o=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,o=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((r=(r=s.trys).length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){s.label=a[1];break}if(6===a[0]&&s.label<r[1]){s.label=r[1],r=a;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(a);break}r[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],o=0}finally{n=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};!function(e){e.put="put",e.post="post"}(S||(S={}));var N=r,E=s,U="https://support.qq.com/products/148793",C=function(e){return"[object Array]"===Object.prototype.toString.call(e)},T=a,D=function(e,t,n){if(void 0===n&&(n=null),e&&"function"==typeof e)return e(t,n);if(t)throw t;return n},x=function(e){return e.mode,e.customInfo,e.title,e.messages,function(e,t,n){}},M="storage";function q(e){var t=e.lastIndexOf("/");return-1===t?e:e.slice(t+1)}var k=function(e,t,n){return P(void 0,void 0,void 0,(function(){var o,r,i;return j(this,(function(s){switch(s.label){case 0:return[4,e.gateWay({path:"storages",name:"get-objects-upload-info",data:[R({objectId:t.path},t.headers?{signedHeader:t.headers}:{})]},n)];case 1:return o=s.sent(),r=(null===(i=o.data)||void 0===i?void 0:i[0])||{},[2,o=R(R({},o),{data:R(R({},r.code?R({},r):{}),{authorization:r.authorization,token:r.token,url:r.uploadUrl,fileId:r.cloudObjectId,cosFileId:r.cloudObjectMeta,download_url:r.downloadUrl})})]}}))}))},V=function(e,t,n){return P(void 0,void 0,void 0,(function(){var o,r;return j(this,(function(i){switch(i.label){case 0:return[4,e.gateWay({path:"storages",name:"get-objects-download-info",data:t.convertedFileList.map((function(e){return{cloudObjectId:e.fileid}}))},n)];case 1:return o=i.sent(),[2,o=R(R({},o),{data:{download_list:null===(r=o.data)||void 0===r?void 0:r.map((function(e){return{code:e.code||"SUCCESS",message:e.message,fileid:e.cloudObjectId,download_url:e.downloadUrl,fileID:e.cloudObjectId,tempFileURL:e.downloadUrl}}))}})]}}))}))},J=function(e,t,n){return P(void 0,void 0,void 0,(function(){var o,r;return j(this,(function(i){switch(i.label){case 0:return[4,e.gateWay({path:"storages",name:"delete-objects",data:t.fileList.map((function(e){return{cloudObjectId:e}}))},n)];case 1:return o=i.sent(),[2,o=R(R({},o),{data:{delete_list:null===(r=o.data)||void 0===r?void 0:r.map((function(e){return{code:e.code||"SUCCESS",fileID:e.cloudObjectId,message:e.message}}))}})]}}))}))},W=function(e,t,n){return P(void 0,void 0,void 0,(function(){var o,r;return j(this,(function(i){switch(i.label){case 0:return[4,e.gateWay({path:"storages",name:"copy-objects",data:t.convertedFileList.map((function(e){return{srcPath:e.src_path,dstPath:e.dst_path,overwrite:e.overwrite,removeOriginal:e.remove_original}}))},n)];case 1:return o=i.sent(),[2,o=R(R({},o),{data:{copy_list:null===(r=o.data)||void 0===r?void 0:r.map((function(e){return{code:e.code||"SUCCESS",fileID:e.cloudObjectId,message:e.message}}))}})]}}))}))},G=new(function(){function e(){}return e.prototype.isGateWay=function(){return"GATEWAY"===(this.config.endPointMode||"CLOUD_API")},e.prototype.uploadFile=function(e,t){var n;return P(this,void 0,void 0,(function(){var o,r,i,s,a,c,u,l,d,p,f,h,y,m,g,v,b,w,I,O,_,A,L,F,P,U,C;return j(this,(function(j){switch(j.label){case 0:if(o=e.cloudPath,r=e.filePath,i=e.onUploadProgress,s=e.method,a=void 0===s?"put":s,c=e.headers,u=void 0===c?{}:c,l=e.fileContent,!T(o)||!r&&!l)throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(M,".uploadFile] invalid params")}));return d={put:S.put,post:S.post}[a.toLocaleLowerCase()]||S.put,p="storage.getUploadMetadata",f=this.request,h={path:o,method:d},d===S.put&&(h.headers=u),y={},this.isGateWay()?[4,k(f,h,e.customReqOpts)]:[3,2];case 1:return y=j.sent(),[3,4];case 2:return[4,f.send(p,h,e.customReqOpts)];case 3:y=j.sent(),j.label=4;case 4:return m=y.data,g=m.url,v=m.authorization,b=m.token,w=m.fileId,I=m.cosFileId,O=m.download_url,_=y.requestId,(null===(n=y.data)||void 0===n?void 0:n.code)?[2,D(t,new Error("[".concat(N(),"][").concat(E.OPERATION_FAIL,"][").concat(M,"]:").concat(y.data)))]:(L=R(R({},A={url:g,file:r,name:o,onUploadProgress:i,fileContent:l,fileId:w,requestId:_}),{method:S.put,headers:R(R({},u),{authorization:v,"x-cos-meta-fileid":I,"x-cos-security-token":b})}),F=R(R({},A),{method:S.post,data:{key:o,signature:v,"x-cos-meta-fileid":I,success_action_status:"201","x-cos-security-token":b}}),(C={})[S.put]={params:L,isSuccess:function(e){return e>=200&&e<300}},C[S.post]={params:F,isSuccess:function(e){return 201===e}},P=C,[4,f.upload(P[d].params)]);case 5:return U=j.sent(),P[d].isSuccess(U.statusCode)?[2,D(t,null,{fileID:w,download_url:O,requestId:_})]:[2,D(t,new Error("[".concat(N(),"][").concat(E.OPERATION_FAIL,"][").concat(M,"]:").concat(U.data)))]}}))}))},e.prototype.getUploadMetadata=function(e,t){return P(this,void 0,void 0,(function(){var n,o,r,i,s;return j(this,(function(a){switch(a.label){case 0:if(n=e.cloudPath,!T(n))throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(M,".getUploadMetadata] invalid cloudPath")}));o=this.request,r="storage.getUploadMetadata",a.label=1;case 1:return a.trys.push([1,6,,7]),i={},this.isGateWay()?[4,k(o,{path:n},e.customReqOpts)]:[3,3];case 2:return i=a.sent(),[3,5];case 3:return[4,o.send(r,{path:n},e.customReqOpts)];case 4:i=a.sent(),a.label=5;case 5:return[2,D(t,null,i)];case 6:return s=a.sent(),[2,D(t,s)];case 7:return[2]}}))}))},e.prototype.deleteFile=function(e,t){return P(this,void 0,void 0,(function(){var n,o,r,i,s,a,c,u;return j(this,(function(l){switch(l.label){case 0:if(!(n=e.fileList)||!C(n)||0===n.length)throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(M,".deleteFile] fileList must not be empty")}));for(o=0,r=n;o<r.length;o++)if(!(i=r[o])||!T(i))throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(M,".deleteFile] fileID must be string")}));return s="storage.batchDeleteFile",a=this.request,c={},this.isGateWay()?[4,J(a,{fileList:n},e.customReqOpts)]:[3,2];case 1:return c=l.sent(),[3,4];case 2:return[4,a.send(s,{fileid_list:n},e.customReqOpts)];case 3:c=l.sent(),l.label=4;case 4:return c.code?[2,D(t,null,c)]:(u={fileList:c.data.delete_list,requestId:c.requestId},[2,D(t,null,u)])}}))}))},e.prototype.getTempFileURL=function(e,t){return P(this,void 0,void 0,(function(){var n,o,r,i,s,a,c,u;return j(this,(function(l){switch(l.label){case 0:if(!(n=e.fileList)||!C(n)||0===n.length)throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(M,".getTempFileURL] fileList must not be empty")}));for(o=[],r=0,i=n;r<i.length;r++)if(s=i[r],d=s,"[object Object]"===Object.prototype.toString.call(d)){if(!Object.prototype.hasOwnProperty.call(s,"fileID")||!Object.prototype.hasOwnProperty.call(s,"maxAge"))throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(M,".getTempFileURL] file info must include fileID and maxAge")}));o.push({fileid:s.fileID,max_age:s.maxAge})}else{if(!T(s))throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(M,".getTempFileURL] invalid fileList")}));o.push({fileid:s})}return a="storage.batchGetDownloadUrl",c=this.request,u={},this.isGateWay()?[4,V(c,{convertedFileList:o},e.customReqOpts)]:[3,2];case 1:return u=l.sent(),[3,4];case 2:return[4,c.send(a,{file_list:o},e.customReqOpts)];case 3:u=l.sent(),l.label=4;case 4:return u.code?[2,D(t,null,u)]:[2,D(t,null,{fileList:u.data.download_list,requestId:u.requestId})]}var d}))}))},e.prototype.downloadFile=function(e,t){return P(this,void 0,void 0,(function(){var n,o,r,i,s,a;return j(this,(function(c){switch(c.label){case 0:if(n=e.fileID,!T(n))throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(M,".getTempFileURL] fileID must be string")}));return[4,this.getTempFileURL.call(this,{fileList:[{fileID:n,maxAge:600}],customReqOpts:e.customReqOpts})];case 1:return o=c.sent(),"SUCCESS"!==(r=o.fileList[0]).code?[2,D(t,r)]:(i=this.request,s=encodeURI(r.download_url),[4,i.download({url:s,tempFilePath:e.tempFilePath})]);case 2:return a=c.sent(),[2,D(t,null,a)]}}))}))},e.prototype.copyFile=function(e,t){return P(this,void 0,void 0,(function(){var n,o,r,i,s,a,c,u,l,d;return j(this,(function(p){switch(p.label){case 0:if(!(n=e.fileList)||!C(n)||0===n.length)throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(M,".copyFile] fileList must not be empty")}));for(o=[],r=0,i=n;r<i.length;r++){if(s=i[r],a=s.srcPath,c=s.dstPath,!a||!c||"string"!=typeof a||"string"!=typeof c)throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(M,".copyFile] srcPath and dstPath may not be empty")}));if(a===c)throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(M,".copyFile] srcPath and dstPath can not be the same")}));if(q(a)!==q(c))throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(M,".copyFile] srcPath and dstPath file name must be the same")}));o.push({src_path:a,dst_path:c,overwrite:s.overwrite,remove_original:s.removeOriginal})}return u="storage.batchCopyFile",l=this.request,d={},this.isGateWay()?[4,W(l,{convertedFileList:o},e.customReqOpts)]:[3,2];case 1:return d=p.sent(),[3,4];case 2:return[4,l.send(u,{file_list:o},e.customReqOpts)];case 3:d=p.sent(),p.label=4;case 4:return d.code?[2,D(t,null,d)]:[2,D(t,null,{fileList:d.data.copy_list,requestId:d.requestId})]}}))}))},e.prototype.getFileInfo=function(e){var t;return P(this,void 0,void 0,(function(){var n,o=this;return j(this,(function(r){switch(r.label){case 0:return[4,this.getTempFileURL(e)];case 1:return(null==(n=r.sent())?void 0:n.fileList)&&(null===(t=null==n?void 0:n.fileList)||void 0===t?void 0:t.length)>0?[4,Promise.all(n.fileList.map((function(e){return P(o,void 0,void 0,(function(){var t,n,o;return j(this,(function(r){switch(r.label){case 0:if("SUCCESS"!==e.code)return[2,{code:e.code,fileID:e.fileID,tempFileURL:e.tempFileURL}];r.label=1;case 1:return r.trys.push([1,3,,4]),[4,this.request.fetch({url:e.tempFileURL,method:"HEAD"})];case 2:return t=r.sent(),n=parseInt(t.headers["content-length"])||0,o=t.headers["content-type"]||"",[2,{code:e.code,fileID:e.fileID,tempFileURL:e.tempFileURL,cloudId:e.fileID,fileName:e.fileID.split("/").pop(),contentType:o,mime:o.split(";")[0].trim(),size:n}];case 3:return r.sent(),[2,{code:"FETCH_FILE_INFO_ERROR",fileID:e.fileID,tempFileURL:e.tempFileURL}];case 4:return[2]}}))}))})))]:[3,3];case 2:return[2,{fileList:r.sent(),requestId:n.requestId}];case 3:return[2,{fileList:[],requestId:n.requestId}]}}))}))},L([x({customInfo:{className:"Cloudbase",methodName:"uploadFile"},title:"上传文件失败",messages:["请确认以下各项:"," 1 - 调用 uploadFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(U)]}),F("design:type",Function),F("design:paramtypes",[Object,Function]),F("design:returntype",Promise)],e.prototype,"uploadFile",null),L([x({customInfo:{className:"Cloudbase",methodName:"getUploadMetadata"},title:"获取上传元信息失败",messages:["请确认以下各项:"," 1 - 调用 getUploadMetadata() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(U)]}),F("design:type",Function),F("design:paramtypes",[Object,Function]),F("design:returntype",Promise)],e.prototype,"getUploadMetadata",null),L([x({customInfo:{className:"Cloudbase",methodName:"deleteFile"},title:"删除文件失败",messages:["请确认以下各项:"," 1 - 调用 deleteFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(U)]}),F("design:type",Function),F("design:paramtypes",[Object,Function]),F("design:returntype",Promise)],e.prototype,"deleteFile",null),L([x({customInfo:{className:"Cloudbase",methodName:"getTempFileURL"},title:"获取文件下载链接",messages:["请确认以下各项:"," 1 - 调用 getTempFileURL() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(U)]}),F("design:type",Function),F("design:paramtypes",[Object,Function]),F("design:returntype",Promise)],e.prototype,"getTempFileURL",null),L([x({customInfo:{className:"Cloudbase",methodName:"downloadFile"},title:"下载文件失败",messages:["请确认以下各项:"," 1 - 调用 downloadFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(U)]}),F("design:type",Function),F("design:paramtypes",[Object,Function]),F("design:returntype",Promise)],e.prototype,"downloadFile",null),L([x({customInfo:{className:"Cloudbase",methodName:"copyFile"},title:"批量复制文件",messages:["请确认以下各项:"," 1 - 调用 copyFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(U)]}),F("design:type",Function),F("design:paramtypes",[Object,Function]),F("design:returntype",Promise)],e.prototype,"copyFile",null),e}()),B={name:M,entity:{uploadFile:G.uploadFile,deleteFile:G.deleteFile,getTempFileURL:G.getTempFileURL,downloadFile:G.downloadFile,getUploadMetadata:G.getUploadMetadata,copyFile:G.copyFile,getFileInfo:G.getFileInfo,isGateWay:G.isGateWay}};try{cloudbase.registerComponent(B)}catch(_){}function H(e){try{e.registerComponent(B)}catch(e){console.warn(e)}}try{window.registerStorage=H}catch(_){}}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var i=t[o]={exports:{}};return e[o](i,i.exports,n),i.exports}n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{var e=o;Object.defineProperty(e,"__esModule",{value:!0}),e.registerStorage=void 0;var t=n(352);e.registerStorage=t.registerStorage})(),o})()));