@cloudbase/js-sdk 3.0.3 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("cloudbase_storage",[],e):"object"==typeof exports?exports.cloudbase_storage=e():t.cloudbase_storage=e()}("undefined"!=typeof window?window:this,(()=>(()=>{"use strict";var t={160:(t,e,r)=>{r.r(e),r.d(e,{registerStorage:()=>nt});var n="@cloudbase/js-sdk";function o(){return n}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(t){t.local="local",t.none="none",t.session="session"}(i||(i={}));function a(t){return"string"==typeof t}function c(t,e){console.warn("[".concat(o(),"][").concat(t,"]:").concat(e))}var u,l,d=(u=function(t,e){return u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},u(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}u(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),f=function(){return f=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},f.apply(this,arguments)},p=function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{c(n.next(t))}catch(t){i(t)}}function a(t){try{c(n.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))},h=function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[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(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};!function(t){function e(e){var r=t.call(this)||this,n=e.timeout,o=e.timeoutMsg,i=e.restrictedMethods;return r.timeout=n||0,r.timeoutMsg=o||"请求超时",r.restrictedMethods=i||["get","post","upload","download"],r}d(e,t),e.prototype.get=function(t){return this.request(f(f({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(f(f({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(f(f({},t),{method:"put"}))},e.prototype.upload=function(t){var e=t.data,r=t.file,n=t.name,o=t.method,i=t.headers,s=void 0===i?{}:i,a={post:"post",put:"put"}[null==o?void 0:o.toLowerCase()]||"put",c=new FormData;return"post"===a?(Object.keys(e).forEach((function(t){c.append(t,e[t])})),c.append("key",n),c.append("file",r),this.request(f(f({},t),{data:c,method:a}),this.restrictedMethods.includes("upload"))):this.request(f(f({},t),{method:"put",headers:s,body:r}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return p(this,void 0,void 0,(function(){var e,r,n,o;return h(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(f(f({},t),{headers:{},responseType:"blob"}))];case 1:return e=i.sent().data,r=window.URL.createObjectURL(new Blob([e])),n=decodeURIComponent(new URL(t.url).pathname.split("/").pop()||""),(o=document.createElement("a")).href=r,o.setAttribute("download",n),o.style.display="none",document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(r),document.body.removeChild(o),[3,3];case 2:return i.sent(),[3,3];case 3:return[2,new Promise((function(e){e({statusCode:200,tempFilePath:t.url})}))]}}))}))},e.prototype.fetch=function(t){var e;return p(this,void 0,void 0,(function(){var r,n,o,i,s,a,c,u,l,d,y,m,g,v=this;return h(this,(function(w){switch(w.label){case 0:return r=new AbortController,n=t.url,o=t.enableAbort,i=void 0!==o&&o,s=t.stream,a=void 0!==s&&s,c=t.signal,u=t.timeout,l=t.shouldThrowOnError,d=void 0===l||l,y=null!=u?u:this.timeout,c&&(c.aborted&&r.abort(),c.addEventListener("abort",(function(){return r.abort()}))),m=null,i&&y&&(m=setTimeout((function(){console.warn(v.timeoutMsg),r.abort(new Error(v.timeoutMsg))}),y)),[4,fetch(n,f(f({},t),{signal:r.signal})).then((function(t){return p(v,void 0,void 0,(function(){var e,r,n;return h(this,(function(o){switch(o.label){case 0:return clearTimeout(m),d?t.ok?(e=t,[3,3]):[3,1]:[3,4];case 1:return n=(r=Promise).reject,[4,t.json()];case 2:e=n.apply(r,[o.sent()]),o.label=3;case 3:return[2,e];case 4:return[2,t]}}))}))})).catch((function(t){if(clearTimeout(m),d)return Promise.reject(t)}))];case 1:return g=w.sent(),[2,{data:a?g.body:(null===(e=g.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?g.json():g.text(),statusCode:g.status,header:g.headers}]}}))}))},e.prototype.request=function(t,e){var r=this;void 0===e&&(e=!1);var n=String(t.method).toLowerCase()||"get";return new Promise((function(o){var i,s,a,c=t.url,u=t.headers,l=void 0===u?{}:u,d=t.data,f=t.responseType,p=t.withCredentials,h=t.body,y=t.onUploadProgress,m=function(t,e,r){void 0===r&&(r={});var n=/\?/.test(e),o="";return Object.keys(r).forEach((function(t){""===o?!n&&(e+="?"):o+="&",o+="".concat(t,"=").concat(encodeURIComponent(r[t]))})),/^http(s)?:\/\//.test(e+=o)?e:"".concat(t).concat(e)}("https:",c,"get"===n?d:{}),g=new XMLHttpRequest;g.open(n,m),f&&(g.responseType=f),Object.keys(l).forEach((function(t){g.setRequestHeader(t,l[t])})),y&&g.upload.addEventListener("progress",y),g.onreadystatechange=function(){var t={};if(4===g.readyState){var e=g.getAllResponseHeaders().trim().split(/[\r\n]+/),r={};e.forEach((function(t){var e=t.split(": "),n=e.shift().toLowerCase(),o=e.join(": ");r[n]=o})),t.header=r,t.statusCode=g.status;try{t.data="blob"===f?g.response:JSON.parse(g.responseText)}catch(e){t.data="blob"===f?g.response:g.responseText}clearTimeout(i),o(t)}},e&&r.timeout&&(i=setTimeout((function(){console.warn(r.timeoutMsg),g.abort()}),r.timeout)),a=d,s="[object FormData]"===Object.prototype.toString.call(a)?d:"application/x-www-form-urlencoded"===l["content-type"]?function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach((function(r){e.push("".concat(r,"=").concat(encodeURIComponent(t[r])))})),e.join("&")}(d):h||(d?JSON.stringify(d):void 0),p&&(g.withCredentials=!0),g.send(s)}))}}((function(){})),function(t){t.WEB="web",t.WX_MP="wx_mp"}(l||(l={}));var y=function(){var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)};return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),m=function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{c(n.next(t))}catch(t){i(t)}}function a(t){try{c(n.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))},g=function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[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(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},v=function(t){function e(e){var r=t.call(this)||this;return r.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),r}return y(e,t),e.prototype.setItem=function(t,e){this.root.tcbCacheObject[t]=e},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}((function(){}));!function(){function t(t){this.keys={};var e=t.persistence,r=t.platformInfo,n=void 0===r?{}:r,o=t.keys,i=void 0===o?{}:o;this.platformInfo=n,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||e,this.storage=function(t,e){switch(t){case"local":default:return e.localStorage?e.localStorage:(c(s.INVALID_PARAMS,"localStorage is not supported on current platform"),new v(e.root));case"none":return new v(e.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=i)}Object.defineProperty(t.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),t.prototype.setStore=function(t,e,r){if("async"!==this.mode){if(this.storage)try{var n={version:r||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(n))}catch(t){throw new Error(JSON.stringify({code:s.OPERATION_FAIL,msg:"[".concat(o(),"][").concat(s.OPERATION_FAIL,"]setStore failed"),info:t}))}}else c(s.INVALID_OPERATION,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,r){return m(this,void 0,void 0,(function(){var n;return g(this,(function(o){switch(o.label){case 0:if(!this.storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),n={version:r||"localCachev1",content:e},[4,this.storage.setItem(t,JSON.stringify(n))];case 2:return o.sent(),[3,4];case 3:return o.sent(),[2];case 4:return[2]}}))}))},t.prototype.getStore=function(t,e){var r;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(r={IS_MP_BUILD:!0})||void 0===r?void 0:r.tcb_token))return{IS_MP_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(t){return""}e=e||"localCachev1";var n=this.storage.getItem(t);return n&&n.indexOf(e)>=0?JSON.parse(n).content:""}c(s.INVALID_OPERATION,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var r;return m(this,void 0,void 0,(function(){var n;return g(this,(function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(r={IS_MP_BUILD:!0})||void 0===r?void 0:r.tcb_token))return[2,{IS_MP_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(n=o.sent())&&n.indexOf(e)>=0?[2,JSON.parse(n).content]:[2,""]}}))}))},t.prototype.removeStore=function(t){"async"!==this.mode?this.storage.removeItem(t):c(s.INVALID_OPERATION,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return m(this,void 0,void 0,(function(){return g(this,(function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}}))}))}}();var w=function(){var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)};return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),b=function(t,e){this.data=e||null,this.name=t},I=function(t){function e(e,r){var n=t.call(this,"error",{error:e,data:r})||this;return n.error=e,n}return w(e,t),e}(b),O=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,r){r[t]=r[t]||[],r[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,r){if(null==r?void 0:r[t]){var n=r[t].indexOf(e);-1!==n&&r[t].splice(n,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if(t instanceof I)return console.error(t.error),this;var r=a(t)?new b(t,e||{}):t,n=r.name;if(this.listens(n)){r.target=this;for(var o=0,i=this.listeners[n]?function(t,e,r){if(r||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}([],this.listeners[n],!0):[];o<i.length;o++)i[o].call(this,r)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();function _(t){this.message=t}function S(t){this.message=t}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),S.prototype=new Error,S.prototype.name="InvalidTokenError";var L,F=function(){return F=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},F.apply(this,arguments)},P=function(t,e,r,n){var o,i=arguments.length,s=i<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,r,s):o(e,r))||s);return i>3&&s&&Object.defineProperty(e,r,s),s},A=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},R=function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{c(n.next(t))}catch(t){i(t)}}function a(t){try{c(n.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))},C=function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[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(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};!function(t){t.put="put",t.post="post"}(L||(L={}));var E,U=o,j=s,N="https://support.qq.com/products/148793",T=function(t){return"[object Array]"===Object.prototype.toString.call(t)},D=a,x=function(t,e,r){if(void 0===r&&(r=null),t&&"function"==typeof t)return t(e,r);if(e)throw e;return r},k=function(t){return t.mode,t.customInfo,t.title,t.messages,function(t,e,r){}},M="storage",q=function(t,e,r){return R(void 0,void 0,void 0,(function(){var n,o,i;return C(this,(function(s){switch(s.label){case 0:return[4,t.gateWay({path:"storages",name:"get-objects-upload-info",data:[F({objectId:e.path},e.headers?{signedHeader:e.headers}:{})]},r)];case 1:return n=s.sent(),o=(null===(i=n.data)||void 0===i?void 0:i[0])||{},[2,n=F(F({},n),{data:F(F({},o.code?F({},o):{}),{authorization:o.authorization,token:o.token,url:o.uploadUrl,fileId:o.cloudObjectId,cosFileId:o.cloudObjectMeta,download_url:o.downloadUrl})})]}}))}))},J=function(t,e,r){return R(void 0,void 0,void 0,(function(){var n,o;return C(this,(function(i){switch(i.label){case 0:return[4,t.gateWay({path:"storages",name:"get-objects-download-info",data:e.convertedFileList.map((function(t){return{cloudObjectId:t.fileid}}))},r)];case 1:return n=i.sent(),[2,n=F(F({},n),{data:{download_list:null===(o=n.data)||void 0===o?void 0:o.map((function(t){return{code:t.code||"SUCCESS",message:t.message,fileid:t.cloudObjectId,download_url:t.downloadUrl,fileID:t.cloudObjectId,tempFileURL:t.downloadUrl}}))}})]}}))}))},V=function(t,e,r){return R(void 0,void 0,void 0,(function(){var n,o;return C(this,(function(i){switch(i.label){case 0:return[4,t.gateWay({path:"storages",name:"delete-objects",data:e.fileList.map((function(t){return{cloudObjectId:t}}))},r)];case 1:return n=i.sent(),[2,n=F(F({},n),{data:{delete_list:null===(o=n.data)||void 0===o?void 0:o.map((function(t){return{code:t.code||"SUCCESS",fileID:t.cloudObjectId,message:t.message}}))}})]}}))}))},W=function(t,e,r){return R(void 0,void 0,void 0,(function(){var n,o;return C(this,(function(i){switch(i.label){case 0:return[4,t.gateWay({path:"storages",name:"copy-objects",data:e.convertedFileList.map((function(t){return{srcPath:t.src_path,dstPath:t.dst_path,overwrite:t.overwrite,removeOriginal:t.remove_original}}))},r)];case 1:return n=i.sent(),[2,n=F(F({},n),{data:{copy_list:null===(o=n.data)||void 0===o?void 0:o.map((function(t){return{code:t.code||"SUCCESS",fileID:t.cloudObjectId,message:t.message}}))}})]}}))}))},z=function(){function t(){}return t.prototype.isGateWay=function(){return"GATEWAY"===(this.config.endPointMode||"CLOUD_API")},t.prototype.uploadFile=function(t,e){return R(this,void 0,void 0,(function(){var r,n,o,i,s,a,c,u,l,d,f,p,h,y,m,g,v,w,b,I,O,_,S,P;return C(this,(function(A){switch(A.label){case 0:if(r=t.cloudPath,n=t.filePath,o=t.onUploadProgress,_=t.method,i=void 0===_?"put":_,S=t.headers,s=void 0===S?{}:S,a=t.fileContent,!D(r)||!n&&!a)throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".uploadFile] invalid params")}));return c={put:L.put,post:L.post}[i.toLocaleLowerCase()]||L.put,[4,this.getUploadMetadata({cloudPath:r,method:c,headers:c===L.put?s:void 0,customReqOpts:t.customReqOpts})];case 1:return u=A.sent(),l=u.data,d=u.requestId,f=l.url,p=l.authorization,h=l.token,y=l.fileId,m=l.cosFileId,g=l.download_url,w=F(F({},v={url:f,file:n,name:r,onUploadProgress:o,fileContent:a,fileId:y,requestId:d}),{method:L.put,headers:F(F({},s),{authorization:p,"x-cos-meta-fileid":m,"x-cos-security-token":h})}),b=F(F({},v),{method:L.post,data:{key:r,signature:p,"x-cos-meta-fileid":m,success_action_status:"201","x-cos-security-token":h}}),(P={})[L.put]={params:w,isSuccess:function(t){return t>=200&&t<300}},P[L.post]={params:b,isSuccess:function(t){return 201===t}},I=P,[4,this.request.upload(I[c].params)];case 2:return O=A.sent(),I[c].isSuccess(O.statusCode)?[2,x(e,null,{fileID:y,download_url:g,requestId:d})]:[2,x(e,new Error("[".concat(U(),"][").concat(j.OPERATION_FAIL,"][").concat(M,"]:").concat(O.data)))]}}))}))},t.prototype.getUploadMetadata=function(t,e){return R(this,void 0,void 0,(function(){var r,n,o,i,s,a,c,u;return C(this,(function(l){switch(l.label){case 0:if(r=t.cloudPath,n=t.method,o=t.headers,!D(r))throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".getUploadMetadata] invalid cloudPath")}));i=this.request,s="storage.getUploadMetadata",l.label=1;case 1:return l.trys.push([1,6,,7]),a=void 0,c={path:r},n&&(c.method=n),n===L.put&&o&&(c.headers=o),this.isGateWay()?[4,q(i,c,t.customReqOpts)]:[3,3];case 2:return a=l.sent(),[3,5];case 3:return[4,i.send(s,c,t.customReqOpts)];case 4:a=l.sent(),l.label=5;case 5:return[2,x(e,null,a)];case 6:return u=l.sent(),[2,x(e,u)];case 7:return[2]}}))}))},t.prototype.deleteFile=function(t,e){return R(this,void 0,void 0,(function(){var r,n,o,i,s,a,c,u;return C(this,(function(l){switch(l.label){case 0:if(!(r=t.fileList)||!T(r)||0===r.length)throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".deleteFile] fileList must not be empty")}));for(n=0,o=r;n<o.length;n++)if(!(i=o[n])||!D(i))throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".deleteFile] fileID must be string")}));return s="storage.batchDeleteFile",a=this.request,c={},this.isGateWay()?[4,V(a,{fileList:r},t.customReqOpts)]:[3,2];case 1:return c=l.sent(),[3,4];case 2:return[4,a.send(s,{fileid_list:r},t.customReqOpts)];case 3:c=l.sent(),l.label=4;case 4:return c.code?[2,x(e,null,c)]:(u={fileList:c.data.delete_list,requestId:c.requestId},[2,x(e,null,u)])}}))}))},t.prototype.getTempFileURL=function(t,e){return R(this,void 0,void 0,(function(){var r,n,o,i,s,a,c,u;return C(this,(function(l){switch(l.label){case 0:if(!(r=t.fileList)||!T(r)||0===r.length)throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".getTempFileURL] fileList must not be empty")}));for(n=[],o=0,i=r;o<i.length;o++)if(s=i[o],d=s,"[object Object]"===Object.prototype.toString.call(d)){if(!Object.prototype.hasOwnProperty.call(s,"fileID"))throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".getTempFileURL] file info must include fileID")}));n.push({fileid:s.fileID,max_age:s.maxAge||7200})}else{if(!D(s))throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".getTempFileURL] invalid fileList")}));n.push({fileid:s})}return a="storage.batchGetDownloadUrl",c=this.request,u={},this.isGateWay()?[4,J(c,{convertedFileList:n},t.customReqOpts)]:[3,2];case 1:return u=l.sent(),[3,4];case 2:return[4,c.send(a,{file_list:n},t.customReqOpts)];case 3:u=l.sent(),l.label=4;case 4:return u.code?[2,x(e,null,u)]:[2,x(e,null,{fileList:u.data.download_list,requestId:u.requestId})]}var d}))}))},t.prototype.downloadFile=function(t,e){return R(this,void 0,void 0,(function(){var r,n,o,i,s,a;return C(this,(function(c){switch(c.label){case 0:if(r=t.fileID,!D(r))throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".getTempFileURL] fileID must be string")}));return[4,this.getTempFileURL.call(this,{fileList:[{fileID:r,maxAge:600}],customReqOpts:t.customReqOpts})];case 1:return n=c.sent(),"SUCCESS"!==(o=n.fileList[0]).code?[2,x(e,o)]:(i=this.request,s=encodeURI(o.download_url),[4,i.download({url:s,tempFilePath:t.tempFilePath})]);case 2:return a=c.sent(),[2,x(e,null,a)]}}))}))},t.prototype.copyFile=function(t,e){return R(this,void 0,void 0,(function(){var r,n,o,i,s,a,c,u,l;return C(this,(function(d){switch(d.label){case 0:if(!(r=t.fileList)||!T(r)||0===r.length)throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".copyFile] fileList must not be empty")}));for(n=[],o=0,i=r;o<i.length;o++){if(s=i[o],a=s.srcPath,c=s.dstPath,!a||!c||"string"!=typeof a||"string"!=typeof c)throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".copyFile] srcPath and dstPath may not be empty")}));if(a===c)throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".copyFile] srcPath and dstPath can not be the same")}));n.push({src_path:a,dst_path:c,overwrite:s.overwrite,remove_original:s.removeOriginal})}return u=this.request,l={},this.isGateWay()?[4,W(u,{convertedFileList:n},t.customReqOpts)]:[3,2];case 1:return l=d.sent(),[3,4];case 2:return[4,u.send("storage.batchCopyFile",{file_list:n},t.customReqOpts)];case 3:l=d.sent(),d.label=4;case 4:return l.code?[2,x(e,null,l)]:[2,x(e,null,{fileList:l.data.copy_list,requestId:l.requestId})]}}))}))},t.prototype.getFileInfo=function(t){var e;return R(this,void 0,void 0,(function(){var r,n=this;return C(this,(function(o){switch(o.label){case 0:return[4,this.getTempFileURL(t)];case 1:return(null==(r=o.sent())?void 0:r.fileList)&&(null===(e=null==r?void 0:r.fileList)||void 0===e?void 0:e.length)>0?[4,Promise.all(r.fileList.map((function(t){return R(n,void 0,void 0,(function(){var e,r,n,o,i;return C(this,(function(s){switch(s.label){case 0:if("SUCCESS"!==t.code)return[2,{code:t.code,fileID:t.fileID,tempFileURL:t.tempFileURL,message:t.message}];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.request.fetch({url:t.tempFileURL,method:"HEAD"})];case 2:return e=s.sent(),r=e.header,Headers&&r instanceof Headers&&(r=Object.fromEntries(e.header.entries())),n=parseInt(r["content-length"])||0,o=r["content-type"]||"",[400,404].includes(Number(e.statusCode))?[2,{code:"FILE_NOT_FOUND",fileID:t.fileID,tempFileURL:t.tempFileURL,message:"file not found"}]:[2,{code:t.code,fileID:t.fileID,tempFileURL:t.tempFileURL,cloudId:t.fileID,fileName:t.fileID.split("/").pop(),contentType:o,mime:o.split(";")[0].trim(),size:n,etag:r.etag||"",lastModified:r["last-modified"]||"",cacheControl:r["cache-control"]||""}];case 3:return i=s.sent(),[2,{code:"FETCH_FILE_INFO_ERROR",fileID:t.fileID,tempFileURL:t.tempFileURL,message:i.message}];case 4:return[2]}}))}))})))]:[3,3];case 2:return[2,{fileList:o.sent(),requestId:r.requestId}];case 3:return[2,{fileList:[],requestId:r.requestId}]}}))}))},P([k({customInfo:{className:"Cloudbase",methodName:"uploadFile"},title:"上传文件失败",messages:["请确认以下各项:"," 1 - 调用 uploadFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(N)]}),A("design:type",Function),A("design:paramtypes",[Object,Function]),A("design:returntype",Promise)],t.prototype,"uploadFile",null),P([k({customInfo:{className:"Cloudbase",methodName:"getUploadMetadata"},title:"获取上传元信息失败",messages:["请确认以下各项:"," 1 - 调用 getUploadMetadata() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(N)]}),A("design:type",Function),A("design:paramtypes",[Object,Function]),A("design:returntype",Promise)],t.prototype,"getUploadMetadata",null),P([k({customInfo:{className:"Cloudbase",methodName:"deleteFile"},title:"删除文件失败",messages:["请确认以下各项:"," 1 - 调用 deleteFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(N)]}),A("design:type",Function),A("design:paramtypes",[Object,Function]),A("design:returntype",Promise)],t.prototype,"deleteFile",null),P([k({customInfo:{className:"Cloudbase",methodName:"getTempFileURL"},title:"获取文件下载链接",messages:["请确认以下各项:"," 1 - 调用 getTempFileURL() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(N)]}),A("design:type",Function),A("design:paramtypes",[Object,Function]),A("design:returntype",Promise)],t.prototype,"getTempFileURL",null),P([k({customInfo:{className:"Cloudbase",methodName:"downloadFile"},title:"下载文件失败",messages:["请确认以下各项:"," 1 - 调用 downloadFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(N)]}),A("design:type",Function),A("design:paramtypes",[Object,Function]),A("design:returntype",Promise)],t.prototype,"downloadFile",null),P([k({customInfo:{className:"Cloudbase",methodName:"copyFile"},title:"批量复制文件",messages:["请确认以下各项:"," 1 - 调用 copyFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(N)]}),A("design:type",Function),A("design:paramtypes",[Object,Function]),A("design:returntype",Promise)],t.prototype,"copyFile",null),t}(),B=function(){var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)};return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),G=function(t){function e(e){var r=t.call(this,e)||this;return r.__isStorageError=!0,r.name="StorageError",r}return B(e,t),e}(Error);function H(t){return"object"==typeof t&&null!==t&&"__isStorageError"in t}(function(t){function e(e,r,n){var o=t.call(this,e)||this;return o.name="StorageApiError",o.status=r,o.statusCode=n,o}B(e,t),e.prototype.toJSON=function(){return{name:this.name,message:this.message,status:this.status,statusCode:this.statusCode}}})(G),B((function(t,e){var r=E.call(this,t)||this;return r.name="StorageUnknownError",r.originalError=e,r}),E=G);var K=function(){var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)};return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),X=function(){return X=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},X.apply(this,arguments)},Y=function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{c(n.next(t))}catch(t){i(t)}}function a(t){try{c(n.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))},Q=function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[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(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},$=s,Z=function(t){function e(e){var r=t.call(this)||this;return r.shouldThrowOnError=!1,r.bucketId="",r.context=e,r}return K(e,t),Object.defineProperty(e.prototype,"config",{get:function(){var t;return null===(t=this.context)||void 0===t?void 0:t.config},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"request",{get:function(){var t;return null===(t=this.context)||void 0===t?void 0:t.request},enumerable:!1,configurable:!0}),e.prototype.throwOnError=function(){return this.shouldThrowOnError=!0,this},e.prototype.from=function(t){return this.bucketId=t||"",this},e.prototype.upload=function(t,e,r){return Y(this,void 0,void 0,(function(){var n,o,i,s,a,c,u,l,d;return Q(this,(function(f){switch(f.label){case 0:n=X({upsert:!0},r),o=n.cacheControl,i=n.contentType,s=n.metadata,f.label=1;case 1:return f.trys.push([1,3,,4]),a=this._getCloudPath(t),c={cloudPath:a,filePath:e},(o||i||s)&&(u={},o&&(u["cache-control"]=o),i&&(u["content-type"]=i),s&&(u["x-cos-metadata-metadata"]=this.toBase64(JSON.stringify(s))),c.headers=u),[4,this.uploadFile(c)];case 2:if(!(l=f.sent()).fileID)throw new Error(JSON.stringify({code:$.OPERATION_FAIL,msg:"[".concat(M,".update] no fileID returned")}));return[2,{data:{id:l.fileID,path:t,fullPath:t},error:null}];case 3:if(d=f.sent(),this.shouldThrowOnError)throw d;if(H(d))return[2,{data:null,error:d}];throw d;case 4:return[2]}}))}))},e.prototype.uploadToSignedUrl=function(t,e,r,n){return Y(this,void 0,void 0,(function(){return Q(this,(function(e){return[2,this.upload(t,r,n)]}))}))},e.prototype.createSignedUploadUrl=function(t){return Y(this,void 0,void 0,(function(){var e,r,n;return Q(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),e=this._getCloudPath(t),[4,this.getUploadMetadata({cloudPath:e})];case 1:return[2,{data:{signedUrl:(r=o.sent().data).url,token:r.token,path:t,authorization:r.authorization,id:r.fileId,cosFileId:r.cosFileId,downloadUrl:r.download_url},error:null}];case 2:if(n=o.sent(),this.shouldThrowOnError)throw n;return[2,{data:null,error:n instanceof G?n:new G(n.message)}];case 3:return[2]}}))}))},e.prototype.update=function(t,e,r){return Y(this,void 0,void 0,(function(){return Q(this,(function(n){return[2,this.upload(t,e,X(X({},r),{upsert:!0}))]}))}))},e.prototype.move=function(t,e){return Y(this,void 0,void 0,(function(){var r,n;return Q(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.copyFile({fileList:[{srcPath:this._getCloudPath(t),dstPath:this._getCloudPath(e),overwrite:!0,removeOriginal:!0}]})];case 1:if((r=o.sent()).fileList[0].code&&"SUCCESS"!==r.fileList[0].code)throw new G(r.fileList[0].message||"Move failed");return[2,{data:{message:"File moved from ".concat(t," to ").concat(e)},error:null}];case 2:if(n=o.sent(),this.shouldThrowOnError)throw n;if(H(n))return[2,{data:null,error:n}];throw n;case 3:return[2]}}))}))},e.prototype.copy=function(t,e){return Y(this,void 0,void 0,(function(){var r,n;return Q(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.copyFile({fileList:[{srcPath:this._getCloudPath(t),dstPath:this._getCloudPath(e),overwrite:!0,removeOriginal:!1}]})];case 1:if((r=o.sent()).fileList[0].code&&"SUCCESS"!==r.fileList[0].code)throw new G(r.fileList[0].message||"Copy failed");return[2,{data:{path:this._getCloudPath(e)},error:null}];case 2:if(n=o.sent(),this.shouldThrowOnError)throw n;if(H(n))return[2,{data:null,error:n}];throw n;case 3:return[2]}}))}))},e.prototype.createSignedUrl=function(t,e,r){return Y(this,void 0,void 0,(function(){var n,o,i,s,a,c,u;return Q(this,(function(l){switch(l.label){case 0:return l.trys.push([0,2,,3]),n=this._normalizeCloudId(t),[4,this.getTempFileURL({fileList:[{fileID:n,maxAge:e}]})];case 1:if("SUCCESS"!==(o=l.sent()).fileList[0].code)throw new G("Failed to create signed URL: [".concat(o.fileList[0].code,"] ").concat(o.fileList[0].fileID));return i=o.fileList[0].download_url,s=[],void 0!==(null==r?void 0:r.download)&&("string"==typeof r.download?s.push("download=".concat(encodeURIComponent(r.download))):!0===r.download&&s.push("download=true")),(null==r?void 0:r.transform)&&(a=this._transformOptsToQueryString(r.transform))&&s.push(a),s.length>0&&(c=i.includes("?")?"&":"?",i="".concat(i).concat(c).concat(s.join("&"))),[2,{data:{signedUrl:i},error:null}];case 2:if(u=l.sent(),this.shouldThrowOnError)throw u;if(H(u))return[2,{data:null,error:u}];throw u;case 3:return[2]}}))}))},e.prototype.createSignedUrls=function(t,e){return Y(this,void 0,void 0,(function(){var r,n,o=this;return Q(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),r=t.map((function(t){return{fileID:o._normalizeCloudId(t),maxAge:e}})),[4,this.getTempFileURL({fileList:r})];case 1:return[2,{data:i.sent().fileList.map((function(e,r){return{path:t[r],signedUrl:e.tempFileURL||"",error:"SUCCESS"===e.code?null:e.message}})),error:null}];case 2:if(n=i.sent(),this.shouldThrowOnError)throw n;if(H(n))return[2,{data:null,error:n}];throw n;case 3:return[2]}}))}))},e.prototype.download=function(t,e){return Y(this,void 0,void 0,(function(){var r,n,o=this;return Q(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),n={},[4,Y(o,void 0,void 0,(function(){var r,n,o,i;return Q(this,(function(s){switch(s.label){case 0:return[4,this.createSignedUrl(t,600,{transform:e})];case 1:if((r=s.sent()).error)throw r.error;return n=encodeURI(null===(i=r.data)||void 0===i?void 0:i.signedUrl),[4,this.request.reqClass.get({url:n,headers:{},responseType:"blob"})];case 2:if(!(o=s.sent().data))throw new G("Download failed: no file content");return[2,new Blob([o])]}}))}))];case 1:return[2,(n.data=i.sent(),n.error=null,n)];case 2:if(r=i.sent(),this.shouldThrowOnError)throw r;if(H(r))return[2,{data:null,error:r}];throw r;case 3:return[2]}}))}))},e.prototype.info=function(t){return Y(this,void 0,void 0,(function(){var e,r,n,o,i,s,a,c;return Q(this,(function(u){switch(u.label){case 0:return u.trys.push([0,2,,3]),e=t.startsWith("cloud://"),r=e?this._extractPathFromFileId(t):t,n=e?this._extractBucketFromFileId(t):this.bucketId,[4,this.getFileInfo({fileList:[this._normalizeCloudId(t)]})];case 1:if(o=u.sent(),"SUCCESS"!==(i=o.fileList[0]).code)throw new G(i.message);return s=(new Date).toISOString(),a=(i.lastModified?new Date(i.lastModified):new Date).toISOString(),[2,{data:{id:i.fileID,version:"1",name:r,bucketId:n,updatedAt:a,createdAt:a,lastAccessedAt:s,size:i.size,cacheControl:i.cacheControl,contentType:i.contentType,etag:i.etag,lastModified:a,metadata:{}},error:null}];case 2:if(c=u.sent(),this.shouldThrowOnError)throw c;return[2,{data:null,error:c instanceof G?c:new G(c.message)}];case 3:return[2]}}))}))},e.prototype.exists=function(t){return Y(this,void 0,void 0,(function(){var e,r,n;return Q(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.getFileInfo({fileList:[this._normalizeCloudId(t)]})];case 1:if(e=o.sent(),"FILE_NOT_FOUND"===(r=e.fileList[0]).code)return[2,{data:!1,error:null}];if("SUCCESS"!==r.code)throw new G(r.message);return[2,{data:!0,error:null}];case 2:if(n=o.sent(),this.shouldThrowOnError)throw n;throw n;case 3:return[2]}}))}))},e.prototype.getPublicUrl=function(t,e){return Y(this,void 0,void 0,(function(){var r;return Q(this,(function(n){switch(n.label){case 0:return[4,this.createSignedUrl(t,600,e)];case 1:return(r=n.sent()).data?[2,{data:{publicUrl:r.data.signedUrl}}]:[2,{data:null,error:r.error}]}}))}))},e.prototype.remove=function(t){return Y(this,void 0,void 0,(function(){var e,r,n,o,i,s,a,c,u,l,d=this;return Q(this,(function(f){switch(f.label){case 0:for(f.trys.push([0,3,,4]),e=10,r=[],n=0;n<t.length;n+=e)r.push(t.slice(n,n+e));return[4,Promise.all(r.map((function(t){return Promise.all(t.map((function(t){return d.info(t)})))})))];case 1:return o=f.sent(),i=new Map,o.flat().forEach((function(r,n){r.data&&i.set(t[Math.floor(n/e)*e+n%e],r.data)})),s=t.map((function(t){return d._normalizeCloudId(t)})),[4,this.deleteFile({fileList:s})];case 2:if(a=f.sent(),(c=a.fileList.filter((function(t){return"SUCCESS"!==t.code}))).length>0)throw new G("Delete failed for ".concat(c.length," file(s)"));return u=(new Date).toISOString(),[2,{data:t.map((function(t){var e=i.get(t);return{name:null==e?void 0:e.name,id:null==e?void 0:e.id,bucket_id:null==e?void 0:e.bucketId,owner:void 0,updated_at:(null==e?void 0:e.updatedAt)||u,created_at:null==e?void 0:e.createdAt,last_accessed_at:(null==e?void 0:e.lastAccessedAt)||u,metadata:(null==e?void 0:e.metadata)||{},buckets:{id:null==e?void 0:e.bucketId,name:null==e?void 0:e.bucketId,owner:void 0,public:!1,created_at:"",updated_at:u}}})),error:null}];case 3:if(l=f.sent(),this.shouldThrowOnError)throw l;if(H(l))return[2,{data:null,error:l}];throw l;case 4:return[2]}}))}))},e.prototype.list=function(){return Y(this,void 0,void 0,(function(){return Q(this,(function(t){throw new G("Not implemented")}))}))},e.prototype._getCloudPath=function(t){return t.replace(/^\/|\/$/g,"").replace(/\/+/g,"/")},e.prototype._normalizeCloudId=function(t){var e;if(/^cloud:\/\//.test(t))return t;var r=this._getCloudPath(t);if(!this.bucketId)throw new G("bucketId is not set");var n=(null===(e=this.config)||void 0===e?void 0:e.env)||"";return n?"cloud://".concat(n,".").concat(this.bucketId,"/").concat(r):void 0},e.prototype.toBase64=function(t){return"undefined"!=typeof Buffer?Buffer.from(t).toString("base64"):btoa(t)},e.prototype._transformOptsToQueryString=function(t){var e=["imageMogr2"];if(t.width||t.height){var r=t.width||"",n=t.height||"";"fill"===t.resize?e.push("thumbnail/".concat(r,"x").concat(n,"!")):"contain"===t.resize?e.push("thumbnail/".concat(r,"x").concat(n)):e.push("thumbnail/".concat(r,"x").concat(n,"^"))}if(t.format&&"origin"!==t.format&&e.push("format/".concat(t.format)),void 0!==t.quality){var o=Math.max(1,Math.min(100,t.quality));e.push("quality/".concat(o))}return e.join("/")},e.prototype._extractPathFromFileId=function(t){var e=t.replace(/^cloud:\/\//,"").split("/");return e.length<2?t:e.slice(1).join("/")},e.prototype._extractBucketFromFileId=function(t){var e=t.replace(/^cloud:\/\//,"").split("/");if(e.length<1)return"";var r=e[0],n=r.indexOf(".");return-1===n?r:r.substring(n+1)},e}(z),tt=new z,et={name:M,entity:{uploadFile:tt.uploadFile,deleteFile:tt.deleteFile,getTempFileURL:tt.getTempFileURL,downloadFile:tt.downloadFile,getUploadMetadata:tt.getUploadMetadata,copyFile:tt.copyFile,getFileInfo:tt.getFileInfo,isGateWay:tt.isGateWay}},rt={name:"".concat(M,"/supabase"),IIFE:!0,entity:function(){var t=new WeakMap;Object.defineProperty(this.prototype,"storage",{get:function(){if(t.has(this))return t.get(this);var e=this,r=new Proxy({},{get:function(t,r){return"config"===r?e.config:"request"===r?e.request:void 0}}),n=new Z(r);return t.set(this,n),n},configurable:!0,enumerable:!0})}};try{cloudbase.registerComponent(et),cloudbase.registerComponent(rt)}catch(_){}function nt(t){try{t.registerComponent(et),t.registerComponent(rt)}catch(t){console.warn(t)}}try{window.registerStorage=nt}catch(_){}}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n](i,i.exports,r),i.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{var t=n;Object.defineProperty(t,"__esModule",{value:!0}),t.registerStorage=void 0;var e=r(160);t.registerStorage=e.registerStorage})(),n})()));
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("cloudbase_storage",[],e):"object"==typeof exports?exports.cloudbase_storage=e():t.cloudbase_storage=e()}("undefined"!=typeof window?window:this,(()=>(()=>{"use strict";var t={160:(t,e,r)=>{r.r(e),r.d(e,{registerStorage:()=>nt});var n="@cloudbase/js-sdk";function o(){return n}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(t){t.local="local",t.none="none",t.session="session"}(i||(i={}));function a(t){return"string"==typeof t}function c(t,e){console.warn("[".concat(o(),"][").concat(t,"]:").concat(e))}var u,l,d=(u=function(t,e){return u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},u(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}u(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),f=function(){return f=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},f.apply(this,arguments)},p=function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{c(n.next(t))}catch(t){i(t)}}function a(t){try{c(n.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))},h=function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[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(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};!function(t){function e(e){var r=t.call(this)||this,n=e.timeout,o=e.timeoutMsg,i=e.restrictedMethods;return r.timeout=n||0,r.timeoutMsg=o||"请求超时",r.restrictedMethods=i||["get","post","upload","download"],r}d(e,t),e.prototype.get=function(t){return this.request(f(f({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(f(f({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(f(f({},t),{method:"put"}))},e.prototype.upload=function(t){var e=t.data,r=t.file,n=t.name,o=t.method,i=t.headers,s=void 0===i?{}:i,a={post:"post",put:"put"}[null==o?void 0:o.toLowerCase()]||"put",c=new FormData;return"post"===a?(Object.keys(e).forEach((function(t){c.append(t,e[t])})),c.append("key",n),c.append("file",r),this.request(f(f({},t),{data:c,method:a}),this.restrictedMethods.includes("upload"))):this.request(f(f({},t),{method:"put",headers:s,body:r}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return p(this,void 0,void 0,(function(){var e,r,n,o;return h(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(f(f({},t),{headers:{},responseType:"blob"}))];case 1:return e=i.sent().data,r=window.URL.createObjectURL(new Blob([e])),n=decodeURIComponent(new URL(t.url).pathname.split("/").pop()||""),(o=document.createElement("a")).href=r,o.setAttribute("download",n),o.style.display="none",document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(r),document.body.removeChild(o),[3,3];case 2:return i.sent(),[3,3];case 3:return[2,new Promise((function(e){e({statusCode:200,tempFilePath:t.url})}))]}}))}))},e.prototype.fetch=function(t){var e;return p(this,void 0,void 0,(function(){var r,n,o,i,s,a,c,u,l,d,y,m,g,v=this;return h(this,(function(w){switch(w.label){case 0:return r=new AbortController,n=t.url,o=t.enableAbort,i=void 0!==o&&o,s=t.stream,a=void 0!==s&&s,c=t.signal,u=t.timeout,l=t.shouldThrowOnError,d=void 0===l||l,y=null!=u?u:this.timeout,c&&(c.aborted&&r.abort(),c.addEventListener("abort",(function(){return r.abort()}))),m=null,i&&y&&(m=setTimeout((function(){console.warn(v.timeoutMsg),r.abort(new Error(v.timeoutMsg))}),y)),[4,fetch(n,f(f({},t),{signal:r.signal})).then((function(t){return p(v,void 0,void 0,(function(){var e,r,n;return h(this,(function(o){switch(o.label){case 0:return clearTimeout(m),d?t.ok?(e=t,[3,3]):[3,1]:[3,4];case 1:return n=(r=Promise).reject,[4,t.json()];case 2:e=n.apply(r,[o.sent()]),o.label=3;case 3:return[2,e];case 4:return[2,t]}}))}))})).catch((function(t){if(clearTimeout(m),d)return Promise.reject(t)}))];case 1:return g=w.sent(),[2,{data:a?g.body:(null===(e=g.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?g.json():g.text(),statusCode:g.status,header:g.headers}]}}))}))},e.prototype.request=function(t,e){var r=this;void 0===e&&(e=!1);var n=String(t.method).toLowerCase()||"get";return new Promise((function(o){var i,s,a,c=t.url,u=t.headers,l=void 0===u?{}:u,d=t.data,f=t.responseType,p=t.withCredentials,h=t.body,y=t.onUploadProgress,m=function(t,e,r){void 0===r&&(r={});var n=/\?/.test(e),o="";return Object.keys(r).forEach((function(t){""===o?!n&&(e+="?"):o+="&",o+="".concat(t,"=").concat(encodeURIComponent(r[t]))})),/^http(s)?:\/\//.test(e+=o)?e:"".concat(t).concat(e)}("https:",c,"get"===n?d:{}),g=new XMLHttpRequest;g.open(n,m),f&&(g.responseType=f),Object.keys(l).forEach((function(t){g.setRequestHeader(t,l[t])})),y&&g.upload.addEventListener("progress",y),g.onreadystatechange=function(){var t={};if(4===g.readyState){var e=g.getAllResponseHeaders().trim().split(/[\r\n]+/),r={};e.forEach((function(t){var e=t.split(": "),n=e.shift().toLowerCase(),o=e.join(": ");r[n]=o})),t.header=r,t.statusCode=g.status;try{t.data="blob"===f?g.response:JSON.parse(g.responseText)}catch(e){t.data="blob"===f?g.response:g.responseText}clearTimeout(i),o(t)}},e&&r.timeout&&(i=setTimeout((function(){console.warn(r.timeoutMsg),g.abort()}),r.timeout)),a=d,s="[object FormData]"===Object.prototype.toString.call(a)?d:"application/x-www-form-urlencoded"===l["content-type"]?function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach((function(r){e.push("".concat(r,"=").concat(encodeURIComponent(t[r])))})),e.join("&")}(d):h||(d?JSON.stringify(d):void 0),p&&(g.withCredentials=!0),g.send(s)}))}}((function(){})),function(t){t.WEB="web",t.WX_MP="wx_mp"}(l||(l={}));var y=function(){var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)};return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),m=function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{c(n.next(t))}catch(t){i(t)}}function a(t){try{c(n.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))},g=function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[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(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},v=function(t){function e(e){var r=t.call(this)||this;return r.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),r}return y(e,t),e.prototype.setItem=function(t,e){this.root.tcbCacheObject[t]=e},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}((function(){}));!function(){function t(t){this.keys={};var e=t.persistence,r=t.platformInfo,n=void 0===r?{}:r,o=t.keys,i=void 0===o?{}:o;this.platformInfo=n,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||e,this.storage=function(t,e){switch(t){case"local":default:return e.localStorage?e.localStorage:(c(s.INVALID_PARAMS,"localStorage is not supported on current platform"),new v(e.root));case"none":return new v(e.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=i)}Object.defineProperty(t.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),t.prototype.setStore=function(t,e,r){if("async"!==this.mode){if(this.storage)try{var n={version:r||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(n))}catch(t){throw new Error(JSON.stringify({code:s.OPERATION_FAIL,msg:"[".concat(o(),"][").concat(s.OPERATION_FAIL,"]setStore failed"),info:t}))}}else c(s.INVALID_OPERATION,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,r){return m(this,void 0,void 0,(function(){var n;return g(this,(function(o){switch(o.label){case 0:if(!this.storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),n={version:r||"localCachev1",content:e},[4,this.storage.setItem(t,JSON.stringify(n))];case 2:return o.sent(),[3,4];case 3:return o.sent(),[2];case 4:return[2]}}))}))},t.prototype.getStore=function(t,e){var r;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(r={IS_MP_BUILD:!0})||void 0===r?void 0:r.tcb_token))return{IS_MP_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(t){return""}e=e||"localCachev1";var n=this.storage.getItem(t);return n&&n.indexOf(e)>=0?JSON.parse(n).content:""}c(s.INVALID_OPERATION,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var r;return m(this,void 0,void 0,(function(){var n;return g(this,(function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(r={IS_MP_BUILD:!0})||void 0===r?void 0:r.tcb_token))return[2,{IS_MP_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(n=o.sent())&&n.indexOf(e)>=0?[2,JSON.parse(n).content]:[2,""]}}))}))},t.prototype.removeStore=function(t){"async"!==this.mode?this.storage.removeItem(t):c(s.INVALID_OPERATION,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return m(this,void 0,void 0,(function(){return g(this,(function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}}))}))}}();var w=function(){var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)};return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),b=function(t,e){this.data=e||null,this.name=t},I=function(t){function e(e,r){var n=t.call(this,"error",{error:e,data:r})||this;return n.error=e,n}return w(e,t),e}(b),O=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,r){r[t]=r[t]||[],r[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,r){if(null==r?void 0:r[t]){var n=r[t].indexOf(e);-1!==n&&r[t].splice(n,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if(t instanceof I)return console.error(t.error),this;var r=a(t)?new b(t,e||{}):t,n=r.name;if(this.listens(n)){r.target=this;for(var o=0,i=this.listeners[n]?function(t,e,r){if(r||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}([],this.listeners[n],!0):[];o<i.length;o++)i[o].call(this,r)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();function _(t){this.message=t}function S(t){this.message=t}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),S.prototype=new Error,S.prototype.name="InvalidTokenError";var L,F=function(){return F=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},F.apply(this,arguments)},P=function(t,e,r,n){var o,i=arguments.length,s=i<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,r,s):o(e,r))||s);return i>3&&s&&Object.defineProperty(e,r,s),s},A=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},R=function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{c(n.next(t))}catch(t){i(t)}}function a(t){try{c(n.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))},C=function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[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(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};!function(t){t.put="put",t.post="post"}(L||(L={}));var E,U=o,j=s,N="https://support.qq.com/products/148793",T=function(t){return"[object Array]"===Object.prototype.toString.call(t)},D=a,x=function(t,e,r){if(void 0===r&&(r=null),t&&"function"==typeof t)return t(e,r);if(e)throw e;return r},k=function(t){return t.mode,t.customInfo,t.title,t.messages,function(t,e,r){}},M="storage",q=function(t,e,r){return R(void 0,void 0,void 0,(function(){var n,o,i;return C(this,(function(s){switch(s.label){case 0:return[4,t.gateWay({path:"storages",name:"get-objects-upload-info",data:[F({objectId:e.path},e.headers?{signedHeader:e.headers}:{})]},r)];case 1:return n=s.sent(),o=(null===(i=n.data)||void 0===i?void 0:i[0])||{},[2,n=F(F({},n),{data:F(F({},o.code?F({},o):{}),{authorization:o.authorization,token:o.token,url:o.uploadUrl,fileId:o.cloudObjectId,cosFileId:o.cloudObjectMeta,download_url:o.downloadUrl})})]}}))}))},J=function(t,e,r){return R(void 0,void 0,void 0,(function(){var n;return C(this,(function(o){switch(o.label){case 0:return[4,t.gateWay({path:"storages",name:"get-objects-download-info",data:e.convertedFileList.map((function(t){return{cloudObjectId:t.fileid}}))},r)];case 1:return n=o.sent(),[2,n=F(F({},n),{data:{download_list:Array.isArray(n.data)?n.data.map((function(t){return{code:t.code||"SUCCESS",message:t.message,fileid:t.cloudObjectId,download_url:t.downloadUrl,fileID:t.cloudObjectId,tempFileURL:t.downloadUrl}})):[]}})]}}))}))},V=function(t,e,r){return R(void 0,void 0,void 0,(function(){var n;return C(this,(function(o){switch(o.label){case 0:return[4,t.gateWay({path:"storages",name:"delete-objects",data:e.fileList.map((function(t){return{cloudObjectId:t}}))},r)];case 1:return n=o.sent(),[2,n=F(F({},n),{data:{delete_list:Array.isArray(n.data)?n.data.map((function(t){return{code:t.code||"SUCCESS",fileID:t.cloudObjectId,message:t.message}})):[]}})]}}))}))},W=function(t,e,r){return R(void 0,void 0,void 0,(function(){var n;return C(this,(function(o){switch(o.label){case 0:return[4,t.gateWay({path:"storages",name:"copy-objects",data:e.convertedFileList.map((function(t){return{srcPath:t.src_path,dstPath:t.dst_path,overwrite:t.overwrite,removeOriginal:t.remove_original}}))},r)];case 1:return n=o.sent(),[2,n=F(F({},n),{data:{copy_list:Array.isArray(n.data)?n.data.map((function(t){return{code:t.code||"SUCCESS",fileID:t.cloudObjectId,message:t.message}})):[]}})]}}))}))},z=function(){function t(){}return t.prototype.isGateWay=function(){return"GATEWAY"===(this.config.endPointMode||"CLOUD_API")},t.prototype.uploadFile=function(t,e){return R(this,void 0,void 0,(function(){var r,n,o,i,s,a,c,u,l,d,f,p,h,y,m,g,v,w,b,I,O,_,S,P;return C(this,(function(A){switch(A.label){case 0:if(r=t.cloudPath,n=t.filePath,o=t.onUploadProgress,_=t.method,i=void 0===_?"put":_,S=t.headers,s=void 0===S?{}:S,a=t.fileContent,!D(r)||!n&&!a)throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".uploadFile] invalid params")}));return c={put:L.put,post:L.post}[i.toLocaleLowerCase()]||L.put,[4,this.getUploadMetadata({cloudPath:r,method:c,headers:c===L.put?s:void 0,customReqOpts:t.customReqOpts})];case 1:return u=A.sent(),l=u.data,d=u.requestId,f=l.url,p=l.authorization,h=l.token,y=l.fileId,m=l.cosFileId,g=l.download_url,w=F(F({},v={url:f,file:n,name:r,onUploadProgress:o,fileContent:a,fileId:y,requestId:d}),{method:L.put,headers:F(F({},s),{authorization:p,"x-cos-meta-fileid":m,"x-cos-security-token":h})}),b=F(F({},v),{method:L.post,data:{key:r,signature:p,"x-cos-meta-fileid":m,success_action_status:"201","x-cos-security-token":h}}),(P={})[L.put]={params:w,isSuccess:function(t){return t>=200&&t<300}},P[L.post]={params:b,isSuccess:function(t){return 201===t}},I=P,[4,this.request.upload(I[c].params)];case 2:return O=A.sent(),I[c].isSuccess(O.statusCode)?[2,x(e,null,{fileID:y,download_url:g,requestId:d})]:[2,x(e,new Error("[".concat(U(),"][").concat(j.OPERATION_FAIL,"][").concat(M,"]:").concat(O.data)))]}}))}))},t.prototype.getUploadMetadata=function(t,e){return R(this,void 0,void 0,(function(){var r,n,o,i,s,a,c,u;return C(this,(function(l){switch(l.label){case 0:if(r=t.cloudPath,n=t.method,o=t.headers,!D(r))throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".getUploadMetadata] invalid cloudPath")}));i=this.request,s="storage.getUploadMetadata",l.label=1;case 1:return l.trys.push([1,6,,7]),a=void 0,c={path:r},n&&(c.method=n),n===L.put&&o&&(c.headers=o),this.isGateWay()?[4,q(i,c,t.customReqOpts)]:[3,3];case 2:return a=l.sent(),[3,5];case 3:return[4,i.send(s,c,t.customReqOpts)];case 4:a=l.sent(),l.label=5;case 5:return[2,x(e,null,a)];case 6:return u=l.sent(),[2,x(e,u)];case 7:return[2]}}))}))},t.prototype.deleteFile=function(t,e){return R(this,void 0,void 0,(function(){var r,n,o,i,s,a,c,u;return C(this,(function(l){switch(l.label){case 0:if(!(r=t.fileList)||!T(r)||0===r.length)throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".deleteFile] fileList must not be empty")}));for(n=0,o=r;n<o.length;n++)if(!(i=o[n])||!D(i))throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".deleteFile] fileID must be string")}));return s="storage.batchDeleteFile",a=this.request,c={},this.isGateWay()?[4,V(a,{fileList:r},t.customReqOpts)]:[3,2];case 1:return c=l.sent(),[3,4];case 2:return[4,a.send(s,{fileid_list:r},t.customReqOpts)];case 3:c=l.sent(),l.label=4;case 4:return c.code?[2,x(e,null,c)]:(u={fileList:c.data.delete_list,requestId:c.requestId},[2,x(e,null,u)])}}))}))},t.prototype.getTempFileURL=function(t,e){return R(this,void 0,void 0,(function(){var r,n,o,i,s,a,c,u;return C(this,(function(l){switch(l.label){case 0:if(!(r=t.fileList)||!T(r)||0===r.length)throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".getTempFileURL] fileList must not be empty")}));for(n=[],o=0,i=r;o<i.length;o++)if(s=i[o],d=s,"[object Object]"===Object.prototype.toString.call(d)){if(!Object.prototype.hasOwnProperty.call(s,"fileID"))throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".getTempFileURL] file info must include fileID")}));n.push({fileid:s.fileID,max_age:s.maxAge||7200})}else{if(!D(s))throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".getTempFileURL] invalid fileList")}));n.push({fileid:s})}return a="storage.batchGetDownloadUrl",c=this.request,u={},this.isGateWay()?[4,J(c,{convertedFileList:n},t.customReqOpts)]:[3,2];case 1:return u=l.sent(),[3,4];case 2:return[4,c.send(a,{file_list:n},t.customReqOpts)];case 3:u=l.sent(),l.label=4;case 4:return u.code?[2,x(e,null,u)]:[2,x(e,null,{fileList:u.data.download_list,requestId:u.requestId})]}var d}))}))},t.prototype.downloadFile=function(t,e){return R(this,void 0,void 0,(function(){var r,n,o,i,s,a;return C(this,(function(c){switch(c.label){case 0:if(r=t.fileID,!D(r))throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".getTempFileURL] fileID must be string")}));return[4,this.getTempFileURL.call(this,{fileList:[{fileID:r,maxAge:600}],customReqOpts:t.customReqOpts})];case 1:return n=c.sent(),"SUCCESS"!==(o=n.fileList[0]).code?[2,x(e,o)]:(i=this.request,s=encodeURI(o.download_url),[4,i.download({url:s,tempFilePath:t.tempFilePath})]);case 2:return a=c.sent(),[2,x(e,null,a)]}}))}))},t.prototype.copyFile=function(t,e){return R(this,void 0,void 0,(function(){var r,n,o,i,s,a,c,u,l;return C(this,(function(d){switch(d.label){case 0:if(!(r=t.fileList)||!T(r)||0===r.length)throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".copyFile] fileList must not be empty")}));for(n=[],o=0,i=r;o<i.length;o++){if(s=i[o],a=s.srcPath,c=s.dstPath,!a||!c||"string"!=typeof a||"string"!=typeof c)throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".copyFile] srcPath and dstPath may not be empty")}));if(a===c)throw new Error(JSON.stringify({code:j.INVALID_PARAMS,msg:"[".concat(M,".copyFile] srcPath and dstPath can not be the same")}));n.push({src_path:a,dst_path:c,overwrite:s.overwrite,remove_original:s.removeOriginal})}return u=this.request,l={},this.isGateWay()?[4,W(u,{convertedFileList:n},t.customReqOpts)]:[3,2];case 1:return l=d.sent(),[3,4];case 2:return[4,u.send("storage.batchCopyFile",{file_list:n},t.customReqOpts)];case 3:l=d.sent(),d.label=4;case 4:return l.code?[2,x(e,null,l)]:[2,x(e,null,{fileList:l.data.copy_list,requestId:l.requestId})]}}))}))},t.prototype.getFileInfo=function(t){var e;return R(this,void 0,void 0,(function(){var r,n=this;return C(this,(function(o){switch(o.label){case 0:return[4,this.getTempFileURL(t)];case 1:return(null==(r=o.sent())?void 0:r.fileList)&&(null===(e=null==r?void 0:r.fileList)||void 0===e?void 0:e.length)>0?[4,Promise.all(r.fileList.map((function(t){return R(n,void 0,void 0,(function(){var e,r,n,o,i;return C(this,(function(s){switch(s.label){case 0:if("SUCCESS"!==t.code)return[2,{code:t.code,fileID:t.fileID,tempFileURL:t.tempFileURL,message:t.message}];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.request.fetch({url:t.tempFileURL,method:"HEAD"})];case 2:return e=s.sent(),r=e.header,Headers&&r instanceof Headers&&(r=Object.fromEntries(e.header.entries())),n=parseInt(r["content-length"])||0,o=r["content-type"]||"",[400,404].includes(Number(e.statusCode))?[2,{code:"FILE_NOT_FOUND",fileID:t.fileID,tempFileURL:t.tempFileURL,message:"file not found"}]:[2,{code:t.code,fileID:t.fileID,tempFileURL:t.tempFileURL,cloudId:t.fileID,fileName:t.fileID.split("/").pop(),contentType:o,mime:o.split(";")[0].trim(),size:n,etag:r.etag||"",lastModified:r["last-modified"]||"",cacheControl:r["cache-control"]||""}];case 3:return i=s.sent(),[2,{code:"FETCH_FILE_INFO_ERROR",fileID:t.fileID,tempFileURL:t.tempFileURL,message:i.message}];case 4:return[2]}}))}))})))]:[3,3];case 2:return[2,{fileList:o.sent(),requestId:r.requestId}];case 3:return[2,{fileList:[],requestId:r.requestId}]}}))}))},P([k({customInfo:{className:"Cloudbase",methodName:"uploadFile"},title:"上传文件失败",messages:["请确认以下各项:"," 1 - 调用 uploadFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(N)]}),A("design:type",Function),A("design:paramtypes",[Object,Function]),A("design:returntype",Promise)],t.prototype,"uploadFile",null),P([k({customInfo:{className:"Cloudbase",methodName:"getUploadMetadata"},title:"获取上传元信息失败",messages:["请确认以下各项:"," 1 - 调用 getUploadMetadata() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(N)]}),A("design:type",Function),A("design:paramtypes",[Object,Function]),A("design:returntype",Promise)],t.prototype,"getUploadMetadata",null),P([k({customInfo:{className:"Cloudbase",methodName:"deleteFile"},title:"删除文件失败",messages:["请确认以下各项:"," 1 - 调用 deleteFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(N)]}),A("design:type",Function),A("design:paramtypes",[Object,Function]),A("design:returntype",Promise)],t.prototype,"deleteFile",null),P([k({customInfo:{className:"Cloudbase",methodName:"getTempFileURL"},title:"获取文件下载链接",messages:["请确认以下各项:"," 1 - 调用 getTempFileURL() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(N)]}),A("design:type",Function),A("design:paramtypes",[Object,Function]),A("design:returntype",Promise)],t.prototype,"getTempFileURL",null),P([k({customInfo:{className:"Cloudbase",methodName:"downloadFile"},title:"下载文件失败",messages:["请确认以下各项:"," 1 - 调用 downloadFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(N)]}),A("design:type",Function),A("design:paramtypes",[Object,Function]),A("design:returntype",Promise)],t.prototype,"downloadFile",null),P([k({customInfo:{className:"Cloudbase",methodName:"copyFile"},title:"批量复制文件",messages:["请确认以下各项:"," 1 - 调用 copyFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(N)]}),A("design:type",Function),A("design:paramtypes",[Object,Function]),A("design:returntype",Promise)],t.prototype,"copyFile",null),t}(),B=function(){var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)};return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),G=function(t){function e(e){var r=t.call(this,e)||this;return r.__isStorageError=!0,r.name="StorageError",r}return B(e,t),e}(Error);function H(t){return"object"==typeof t&&null!==t&&"__isStorageError"in t}(function(t){function e(e,r,n){var o=t.call(this,e)||this;return o.name="StorageApiError",o.status=r,o.statusCode=n,o}B(e,t),e.prototype.toJSON=function(){return{name:this.name,message:this.message,status:this.status,statusCode:this.statusCode}}})(G),B((function(t,e){var r=E.call(this,t)||this;return r.name="StorageUnknownError",r.originalError=e,r}),E=G);var K=function(){var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)};return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),X=function(){return X=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},X.apply(this,arguments)},Y=function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{c(n.next(t))}catch(t){i(t)}}function a(t){try{c(n.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))},Q=function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[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(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},$=s,Z=function(t){function e(e){var r=t.call(this)||this;return r.shouldThrowOnError=!1,r.bucketId="",r.context=e,r}return K(e,t),Object.defineProperty(e.prototype,"config",{get:function(){var t;return null===(t=this.context)||void 0===t?void 0:t.config},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"request",{get:function(){var t;return null===(t=this.context)||void 0===t?void 0:t.request},enumerable:!1,configurable:!0}),e.prototype.throwOnError=function(){return this.shouldThrowOnError=!0,this},e.prototype.from=function(t){return this.bucketId=t||"",this},e.prototype.upload=function(t,e,r){return Y(this,void 0,void 0,(function(){var n,o,i,s,a,c,u,l,d;return Q(this,(function(f){switch(f.label){case 0:n=X({upsert:!0},r),o=n.cacheControl,i=n.contentType,s=n.metadata,f.label=1;case 1:return f.trys.push([1,3,,4]),a=this._getCloudPath(t),c={cloudPath:a,filePath:e},(o||i||s)&&(u={},o&&(u["cache-control"]=o),i&&(u["content-type"]=i),s&&(u["x-cos-metadata-metadata"]=this.toBase64(JSON.stringify(s))),c.headers=u),[4,this.uploadFile(c)];case 2:if(!(l=f.sent()).fileID)throw new Error(JSON.stringify({code:$.OPERATION_FAIL,msg:"[".concat(M,".update] no fileID returned")}));return[2,{data:{id:l.fileID,path:t,fullPath:t},error:null}];case 3:if(d=f.sent(),this.shouldThrowOnError)throw d;if(H(d))return[2,{data:null,error:d}];throw d;case 4:return[2]}}))}))},e.prototype.uploadToSignedUrl=function(t,e,r,n){return Y(this,void 0,void 0,(function(){return Q(this,(function(e){return[2,this.upload(t,r,n)]}))}))},e.prototype.createSignedUploadUrl=function(t){return Y(this,void 0,void 0,(function(){var e,r,n;return Q(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),e=this._getCloudPath(t),[4,this.getUploadMetadata({cloudPath:e})];case 1:return[2,{data:{signedUrl:(r=o.sent().data).url,token:r.token,path:t,authorization:r.authorization,id:r.fileId,cosFileId:r.cosFileId,downloadUrl:r.download_url},error:null}];case 2:if(n=o.sent(),this.shouldThrowOnError)throw n;return[2,{data:null,error:n instanceof G?n:new G(n.message)}];case 3:return[2]}}))}))},e.prototype.update=function(t,e,r){return Y(this,void 0,void 0,(function(){return Q(this,(function(n){return[2,this.upload(t,e,X(X({},r),{upsert:!0}))]}))}))},e.prototype.move=function(t,e){return Y(this,void 0,void 0,(function(){var r,n;return Q(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.copyFile({fileList:[{srcPath:this._getCloudPath(t),dstPath:this._getCloudPath(e),overwrite:!0,removeOriginal:!0}]})];case 1:if((r=o.sent()).fileList[0].code&&"SUCCESS"!==r.fileList[0].code)throw new G(r.fileList[0].message||"Move failed");return[2,{data:{message:"File moved from ".concat(t," to ").concat(e)},error:null}];case 2:if(n=o.sent(),this.shouldThrowOnError)throw n;if(H(n))return[2,{data:null,error:n}];throw n;case 3:return[2]}}))}))},e.prototype.copy=function(t,e){return Y(this,void 0,void 0,(function(){var r,n;return Q(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.copyFile({fileList:[{srcPath:this._getCloudPath(t),dstPath:this._getCloudPath(e),overwrite:!0,removeOriginal:!1}]})];case 1:if((r=o.sent()).fileList[0].code&&"SUCCESS"!==r.fileList[0].code)throw new G(r.fileList[0].message||"Copy failed");return[2,{data:{path:this._getCloudPath(e)},error:null}];case 2:if(n=o.sent(),this.shouldThrowOnError)throw n;if(H(n))return[2,{data:null,error:n}];throw n;case 3:return[2]}}))}))},e.prototype.createSignedUrl=function(t,e,r){return Y(this,void 0,void 0,(function(){var n,o,i,s,a,c,u;return Q(this,(function(l){switch(l.label){case 0:return l.trys.push([0,2,,3]),n=this._normalizeCloudId(t),[4,this.getTempFileURL({fileList:[{fileID:n,maxAge:e}]})];case 1:if("SUCCESS"!==(o=l.sent()).fileList[0].code)throw new G("Failed to create signed URL: [".concat(o.fileList[0].code,"] ").concat(o.fileList[0].fileID));return i=o.fileList[0].download_url,s=[],void 0!==(null==r?void 0:r.download)&&("string"==typeof r.download?s.push("download=".concat(encodeURIComponent(r.download))):!0===r.download&&s.push("download=true")),(null==r?void 0:r.transform)&&(a=this._transformOptsToQueryString(r.transform))&&s.push(a),s.length>0&&(c=i.includes("?")?"&":"?",i="".concat(i).concat(c).concat(s.join("&"))),[2,{data:{signedUrl:i},error:null}];case 2:if(u=l.sent(),this.shouldThrowOnError)throw u;if(H(u))return[2,{data:null,error:u}];throw u;case 3:return[2]}}))}))},e.prototype.createSignedUrls=function(t,e){return Y(this,void 0,void 0,(function(){var r,n,o=this;return Q(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),r=t.map((function(t){return{fileID:o._normalizeCloudId(t),maxAge:e}})),[4,this.getTempFileURL({fileList:r})];case 1:return[2,{data:i.sent().fileList.map((function(e,r){return{path:t[r],signedUrl:e.tempFileURL||"",error:"SUCCESS"===e.code?null:e.message}})),error:null}];case 2:if(n=i.sent(),this.shouldThrowOnError)throw n;if(H(n))return[2,{data:null,error:n}];throw n;case 3:return[2]}}))}))},e.prototype.download=function(t,e){return Y(this,void 0,void 0,(function(){var r,n,o=this;return Q(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),n={},[4,Y(o,void 0,void 0,(function(){var r,n,o,i;return Q(this,(function(s){switch(s.label){case 0:return[4,this.createSignedUrl(t,600,{transform:e})];case 1:if((r=s.sent()).error)throw r.error;return n=encodeURI(null===(i=r.data)||void 0===i?void 0:i.signedUrl),[4,this.request.reqClass.get({url:n,headers:{},responseType:"blob"})];case 2:if(!(o=s.sent().data))throw new G("Download failed: no file content");return[2,new Blob([o])]}}))}))];case 1:return[2,(n.data=i.sent(),n.error=null,n)];case 2:if(r=i.sent(),this.shouldThrowOnError)throw r;if(H(r))return[2,{data:null,error:r}];throw r;case 3:return[2]}}))}))},e.prototype.info=function(t){return Y(this,void 0,void 0,(function(){var e,r,n,o,i,s,a,c;return Q(this,(function(u){switch(u.label){case 0:return u.trys.push([0,2,,3]),e=t.startsWith("cloud://"),r=e?this._extractPathFromFileId(t):t,n=e?this._extractBucketFromFileId(t):this.bucketId,[4,this.getFileInfo({fileList:[this._normalizeCloudId(t)]})];case 1:if(o=u.sent(),"SUCCESS"!==(i=o.fileList[0]).code)throw new G(i.message);return s=(new Date).toISOString(),a=(i.lastModified?new Date(i.lastModified):new Date).toISOString(),[2,{data:{id:i.fileID,version:"1",name:r,bucketId:n,updatedAt:a,createdAt:a,lastAccessedAt:s,size:i.size,cacheControl:i.cacheControl,contentType:i.contentType,etag:i.etag,lastModified:a,metadata:{}},error:null}];case 2:if(c=u.sent(),this.shouldThrowOnError)throw c;return[2,{data:null,error:c instanceof G?c:new G(c.message)}];case 3:return[2]}}))}))},e.prototype.exists=function(t){return Y(this,void 0,void 0,(function(){var e,r,n;return Q(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.getFileInfo({fileList:[this._normalizeCloudId(t)]})];case 1:if(e=o.sent(),"FILE_NOT_FOUND"===(r=e.fileList[0]).code)return[2,{data:!1,error:null}];if("SUCCESS"!==r.code)throw new G(r.message);return[2,{data:!0,error:null}];case 2:if(n=o.sent(),this.shouldThrowOnError)throw n;throw n;case 3:return[2]}}))}))},e.prototype.getPublicUrl=function(t,e){return Y(this,void 0,void 0,(function(){var r;return Q(this,(function(n){switch(n.label){case 0:return[4,this.createSignedUrl(t,600,e)];case 1:return(r=n.sent()).data?[2,{data:{publicUrl:r.data.signedUrl}}]:[2,{data:null,error:r.error}]}}))}))},e.prototype.remove=function(t){return Y(this,void 0,void 0,(function(){var e,r,n,o,i,s,a,c,u,l,d=this;return Q(this,(function(f){switch(f.label){case 0:for(f.trys.push([0,3,,4]),e=10,r=[],n=0;n<t.length;n+=e)r.push(t.slice(n,n+e));return[4,Promise.all(r.map((function(t){return Promise.all(t.map((function(t){return d.info(t)})))})))];case 1:return o=f.sent(),i=new Map,o.flat().forEach((function(r,n){r.data&&i.set(t[Math.floor(n/e)*e+n%e],r.data)})),s=t.map((function(t){return d._normalizeCloudId(t)})),[4,this.deleteFile({fileList:s})];case 2:if(a=f.sent(),(c=a.fileList.filter((function(t){return"SUCCESS"!==t.code}))).length>0)throw new G("Delete failed for ".concat(c.length," file(s)"));return u=(new Date).toISOString(),[2,{data:t.map((function(t){var e=i.get(t);return{name:null==e?void 0:e.name,id:null==e?void 0:e.id,bucket_id:null==e?void 0:e.bucketId,owner:void 0,updated_at:(null==e?void 0:e.updatedAt)||u,created_at:null==e?void 0:e.createdAt,last_accessed_at:(null==e?void 0:e.lastAccessedAt)||u,metadata:(null==e?void 0:e.metadata)||{},buckets:{id:null==e?void 0:e.bucketId,name:null==e?void 0:e.bucketId,owner:void 0,public:!1,created_at:"",updated_at:u}}})),error:null}];case 3:if(l=f.sent(),this.shouldThrowOnError)throw l;if(H(l))return[2,{data:null,error:l}];throw l;case 4:return[2]}}))}))},e.prototype.list=function(){return Y(this,void 0,void 0,(function(){return Q(this,(function(t){throw new G("Not implemented")}))}))},e.prototype._getCloudPath=function(t){return t.replace(/^\/|\/$/g,"").replace(/\/+/g,"/")},e.prototype._normalizeCloudId=function(t){var e;if(/^cloud:\/\//.test(t))return t;var r=this._getCloudPath(t);if(!this.bucketId)throw new G("bucketId is not set");var n=(null===(e=this.config)||void 0===e?void 0:e.env)||"";return n?"cloud://".concat(n,".").concat(this.bucketId,"/").concat(r):void 0},e.prototype.toBase64=function(t){return"undefined"!=typeof Buffer?Buffer.from(t).toString("base64"):btoa(t)},e.prototype._transformOptsToQueryString=function(t){var e=["imageMogr2"];if(t.width||t.height){var r=t.width||"",n=t.height||"";"fill"===t.resize?e.push("thumbnail/".concat(r,"x").concat(n,"!")):"contain"===t.resize?e.push("thumbnail/".concat(r,"x").concat(n)):e.push("thumbnail/".concat(r,"x").concat(n,"^"))}if(t.format&&"origin"!==t.format&&e.push("format/".concat(t.format)),void 0!==t.quality){var o=Math.max(1,Math.min(100,t.quality));e.push("quality/".concat(o))}return e.join("/")},e.prototype._extractPathFromFileId=function(t){var e=t.replace(/^cloud:\/\//,"").split("/");return e.length<2?t:e.slice(1).join("/")},e.prototype._extractBucketFromFileId=function(t){var e=t.replace(/^cloud:\/\//,"").split("/");if(e.length<1)return"";var r=e[0],n=r.indexOf(".");return-1===n?r:r.substring(n+1)},e}(z),tt=new z,et={name:M,entity:{uploadFile:tt.uploadFile,deleteFile:tt.deleteFile,getTempFileURL:tt.getTempFileURL,downloadFile:tt.downloadFile,getUploadMetadata:tt.getUploadMetadata,copyFile:tt.copyFile,getFileInfo:tt.getFileInfo,isGateWay:tt.isGateWay}},rt={name:"".concat(M,"/supabase"),IIFE:!0,entity:function(){var t=new WeakMap;Object.defineProperty(this.prototype,"storage",{get:function(){if(t.has(this))return t.get(this);var e=this,r=new Proxy({},{get:function(t,r){return"config"===r?e.config:"request"===r?e.request:void 0}}),n=new Z(r);return t.set(this,n),n},configurable:!0,enumerable:!0})}};try{cloudbase.registerComponent(et),cloudbase.registerComponent(rt)}catch(_){}function nt(t){try{t.registerComponent(et),t.registerComponent(rt)}catch(t){console.warn(t)}}try{window.registerStorage=nt}catch(_){}}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n](i,i.exports,r),i.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{var t=n;Object.defineProperty(t,"__esModule",{value:!0}),t.registerStorage=void 0;var e=r(160);t.registerStorage=e.registerStorage})(),n})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/js-sdk",
3
- "version": "3.0.3",
3
+ "version": "3.0.4",
4
4
  "description": "cloudbase javascript sdk",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -46,25 +46,25 @@
46
46
  "license": "Apache-2.0",
47
47
  "dependencies": {
48
48
  "@cloudbase/adapter-interface": "^0.7.1",
49
- "@cloudbase/ai": "3.0.3",
50
- "@cloudbase/analytics": "3.0.3",
51
- "@cloudbase/apis": "3.0.3",
52
- "@cloudbase/app": "3.0.3",
53
- "@cloudbase/auth": "3.0.3",
54
- "@cloudbase/cloudrun": "3.0.3",
49
+ "@cloudbase/ai": "3.0.4",
50
+ "@cloudbase/analytics": "3.0.4",
51
+ "@cloudbase/apis": "3.0.4",
52
+ "@cloudbase/app": "3.0.4",
53
+ "@cloudbase/auth": "3.0.4",
54
+ "@cloudbase/cloudrun": "3.0.4",
55
55
  "@cloudbase/database": "0.11.0",
56
- "@cloudbase/functions": "3.0.3",
57
- "@cloudbase/model": "3.0.3",
58
- "@cloudbase/mysql": "3.0.3",
59
- "@cloudbase/realtime": "3.0.3",
60
- "@cloudbase/storage": "3.0.3",
61
- "@cloudbase/types": "3.0.3",
62
- "@cloudbase/utilities": "3.0.3"
56
+ "@cloudbase/functions": "3.0.4",
57
+ "@cloudbase/model": "3.0.4",
58
+ "@cloudbase/mysql": "3.0.4",
59
+ "@cloudbase/realtime": "3.0.4",
60
+ "@cloudbase/storage": "3.0.4",
61
+ "@cloudbase/types": "3.0.4",
62
+ "@cloudbase/utilities": "3.0.4"
63
63
  },
64
64
  "browserslist": [
65
65
  "last 2 version",
66
66
  "> 1%",
67
67
  "chrome 53"
68
68
  ],
69
- "gitHead": "f636691d8dd8edef8c44e788512fa5a1bbbb11af"
69
+ "gitHead": "b5f5f8541b7e0d944bf345f8aa23c4e0ccb42b4f"
70
70
  }