@cloudbase/js-sdk 2.21.3 → 2.21.5
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.
- package/index.d.ts +406 -288
- package/miniprogram_dist/app.js +1 -1
- package/miniprogram_dist/cloudrun.js +1 -1
- package/miniprogram_dist/functions.js +1 -1
- package/miniprogram_dist/index.js +1 -1
- package/miniprogram_dist/storage.js +1 -1
- package/package.json +13 -13
|
@@ -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={352:(t,e,n)=>{n.r(e),n.d(e,{registerStorage:()=>V});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(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(r(),"][").concat(t,"]:").concat(e))}var u,l,p=(u=function(t,e){return u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},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 n(){this.constructor=t}u(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),f=function(){return f=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},f.apply(this,arguments)},d=function(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((o=o.apply(t,e||[])).next())}))},h=function(t,e){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=e.call(t,s)}catch(t){a=[6,t],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(t){function e(e){var n=t.call(this)||this,o=e.timeout,r=e.timeoutMsg,i=e.restrictedMethods;return n.timeout=o||0,n.timeoutMsg=r||"请求超时",n.restrictedMethods=i||["get","post","upload","download"],n}p(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,n=t.file,o=t.name,r=t.method,i=t.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(e).forEach((function(t){c.append(t,e[t])})),c.append("key",o),c.append("file",n),this.request(f(f({},t),{data:c,method:a}),this.restrictedMethods.includes("upload"))):this.request(f(f({},t),{method:"put",headers:s,body:n}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return d(this,void 0,void 0,(function(){var e,n,o,r;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,n=window.URL.createObjectURL(new Blob([e])),o=decodeURIComponent(new URL(t.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(e){e({statusCode:200,tempFilePath:t.url})}))]}}))}))},e.prototype.fetch=function(t){var e;return d(this,void 0,void 0,(function(){var n,o,r,i,s,a,c,u,l,p,y,m=this;return h(this,(function(g){switch(g.label){case 0:return n=new AbortController,o=t.url,r=t.enableAbort,i=void 0!==r&&r,s=t.stream,a=void 0!==s&&s,c=t.signal,u=t.timeout,l=null!=u?u:this.timeout,c&&(c.aborted&&n.abort(),c.addEventListener("abort",(function(){return n.abort()}))),p=null,i&&l&&(p=setTimeout((function(){console.warn(m.timeoutMsg),n.abort(new Error(m.timeoutMsg))}),l)),[4,fetch(o,f(f({},t),{signal:n.signal})).then((function(t){return d(m,void 0,void 0,(function(){var e,n,o;return h(this,(function(r){switch(r.label){case 0:return clearTimeout(p),t.ok?(e=t,[3,3]):[3,1];case 1:return o=(n=Promise).reject,[4,t.json()];case 2:e=o.apply(n,[r.sent()]),r.label=3;case 3:return[2,e]}}))}))})).catch((function(t){return clearTimeout(p),Promise.reject(t)}))];case 1:return y=g.sent(),[2,{data:a?y.body:(null===(e=y.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?y.json():y.text(),statusCode:y.status,header:y.headers}]}}))}))},e.prototype.request=function(t,e){var n=this;void 0===e&&(e=!1);var o=String(t.method).toLowerCase()||"get";return new Promise((function(r){var i,s,a,c=t.url,u=t.headers,l=void 0===u?{}:u,p=t.data,f=t.responseType,d=t.withCredentials,h=t.body,y=t.onUploadProgress,m=function(t,e,n){void 0===n&&(n={});var o=/\?/.test(e),r="";return Object.keys(n).forEach((function(t){""===r?!o&&(e+="?"):r+="&",r+="".concat(t,"=").concat(encodeURIComponent(n[t]))})),/^http(s)?:\/\//.test(e+=r)?e:"".concat(t).concat(e)}("https:",c,"get"===o?p:{}),g=new XMLHttpRequest;g.open(o,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]+/),n={};e.forEach((function(t){var e=t.split(": "),o=e.shift().toLowerCase(),r=e.join(": ");n[o]=r})),t.header=n,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),r(t)}},e&&n.timeout&&(i=setTimeout((function(){console.warn(n.timeoutMsg),g.abort()}),n.timeout)),a=p,s="[object FormData]"===Object.prototype.toString.call(a)?p:"application/x-www-form-urlencoded"===l["content-type"]?function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach((function(n){e.push("".concat(n,"=").concat(encodeURIComponent(t[n])))})),e.join("&")}(p):h||(p?JSON.stringify(p):void 0),d&&(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,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,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=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),m=function(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((o=o.apply(t,e||[])).next())}))},g=function(t,e){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=e.call(t,s)}catch(t){a=[6,t],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])}}},b=function(t){function e(e){var n=t.call(this)||this;return n.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),n}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,n=t.platformInfo,o=void 0===n?{}:n,r=t.keys,i=void 0===r?{}:r;this.platformInfo=o,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 b(e.root));case"none":return new b(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,n){if("async"!==this.mode){if(this.storage)try{var o={version:n||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(o))}catch(t){throw new Error(JSON.stringify({code:s.OPERATION_FAIL,msg:"[".concat(r(),"][").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,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:e},[4,this.storage.setItem(t,JSON.stringify(o))];case 2:return r.sent(),[3,4];case 3:return r.sent(),[2];case 4:return[2]}}))}))},t.prototype.getStore=function(t,e){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(t){return""}e=e||"localCachev1";var o=this.storage.getItem(t);return o&&o.indexOf(e)>=0?JSON.parse(o).content:""}c(s.INVALID_OPERATION,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){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(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(o=r.sent())&&o.indexOf(e)>=0?[2,JSON.parse(o).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 v=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,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=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),w=function(t,e){this.data=e||null,this.name=t},O=function(t){function e(e,n){var o=t.call(this,"error",{error:e,data:n})||this;return o.error=e,o}return v(e,t),e}(w),I=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,n){n[t]=n[t]||[],n[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,n){if(null==n?void 0:n[t]){var o=n[t].indexOf(e);-1!==o&&n[t].splice(o,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if(t instanceof O)return console.error(t.error),this;var n=a(t)?new w(t,e||{}):t,o=n.name;if(this.listens(o)){n.target=this;for(var r=0,i=this.listeners[o]?function(t,e,n){if(n||2===arguments.length)for(var o,r=0,i=e.length;r<i;r++)!o&&r in e||(o||(o=Array.prototype.slice.call(e,0,r)),o[r]=e[r]);return t.concat(o||Array.prototype.slice.call(e))}([],this.listeners[o],!0):[];r<i.length;r++)i[r].call(this,n)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();function _(t){this.message=t}function A(t){this.message=t}new I,new I,"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,P=function(){return P=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},P.apply(this,arguments)},R=function(t,e,n,o){var r,i=arguments.length,s=i<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,o);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(s=(i<3?r(s):i>3?r(e,n,s):r(e,n))||s);return i>3&&s&&Object.defineProperty(e,n,s),s},j=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},N=function(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((o=o.apply(t,e||[])).next())}))},L=function(t,e){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=e.call(t,s)}catch(t){a=[6,t],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(t){t.put="put",t.post="post"}(S||(S={}));var F=r,E=s,T="https://support.qq.com/products/148793",x=function(t){return"[object Array]"===Object.prototype.toString.call(t)},M=a,U=function(t,e,n){if(void 0===n&&(n=null),t&&"function"==typeof t)return t(e,n);if(e)throw e;return n},C=function(t){return t.mode,t.customInfo,t.title,t.messages,function(t,e,n){}},D="storage",k=new(function(){function t(){}return t.prototype.uploadFile=function(t,e){return N(this,void 0,void 0,(function(){var n,o,r,i,s,a,c,u,l,p,f,d,h,y,m,g,b,v,w,O,I,_,A,R,j;return L(this,(function(N){switch(N.label){case 0:if(n=t.cloudPath,o=t.filePath,r=t.onUploadProgress,i=t.method,s=void 0===i?"put":i,a=t.headers,c=void 0===a?{}:a,!M(n)||!o)throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(D,".uploadFile] invalid params")}));return u={put:S.put,post:S.post}[s.toLocaleLowerCase()]||S.put,l=this.request,p={path:n,method:u},u===S.put&&(p.headers=c),[4,l.send("storage.getUploadMetadata",p)];case 1:return f=N.sent(),d=f.data,h=d.url,y=d.authorization,m=d.token,g=d.fileId,b=d.cosFileId,v=d.download_url,w=f.requestId,I=P(P({},O={url:h,file:o,name:n,onUploadProgress:r}),{method:S.put,headers:P(P({},c),{authorization:y,"x-cos-meta-fileid":b,"x-cos-security-token":m})}),_=P(P({},O),{method:S.post,data:{key:n,signature:y,"x-cos-meta-fileid":b,success_action_status:"201","x-cos-security-token":m}}),(j={})[S.put]={params:I,isSuccess:function(t){return t>=200&&t<300}},j[S.post]={params:_,isSuccess:function(t){return 201===t}},A=j,[4,l.upload(A[u].params)];case 2:return R=N.sent(),A[u].isSuccess(R.statusCode)?[2,U(e,null,{fileID:g,download_url:v,requestId:w})]:[2,U(e,new Error("[".concat(F(),"][").concat(E.OPERATION_FAIL,"][").concat(D,"]:").concat(R.data)))]}}))}))},t.prototype.getUploadMetadata=function(t,e){return N(this,void 0,void 0,(function(){var n,o,r,i,s;return L(this,(function(a){switch(a.label){case 0:if(n=t.cloudPath,!M(n))throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(D,".getUploadMetadata] invalid cloudPath")}));o=this.request,r="storage.getUploadMetadata",a.label=1;case 1:return a.trys.push([1,3,,4]),[4,o.send(r,{path:n})];case 2:return i=a.sent(),[2,U(e,null,i)];case 3:return s=a.sent(),[2,U(e,s)];case 4:return[2]}}))}))},t.prototype.deleteFile=function(t,e){return N(this,void 0,void 0,(function(){var n,o,r,i,s,a;return L(this,(function(c){switch(c.label){case 0:if(!(n=t.fileList)||!x(n)||0===n.length)throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(D,".deleteFile] fileList must not be empty")}));for(o=0,r=n;o<r.length;o++)if(!(i=r[o])||!M(i))throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(D,".deleteFile] fileID must be string")}));return[4,this.request.send("storage.batchDeleteFile",{fileid_list:n})];case 1:return(s=c.sent()).code?[2,U(e,null,s)]:(a={fileList:s.data.delete_list,requestId:s.requestId},[2,U(e,null,a)])}}))}))},t.prototype.getTempFileURL=function(t,e){return N(this,void 0,void 0,(function(){var n,o,r,i,s,a;return L(this,(function(c){switch(c.label){case 0:if(!(n=t.fileList)||!x(n)||0===n.length)throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(D,".getTempFileURL] fileList must not be empty")}));for(o=[],r=0,i=n;r<i.length;r++)if(s=i[r],u=s,"[object Object]"===Object.prototype.toString.call(u)){if(!Object.prototype.hasOwnProperty.call(s,"fileID")||!Object.prototype.hasOwnProperty.call(s,"maxAge"))throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(D,".getTempFileURL] file info must include fileID and maxAge")}));o.push({fileid:s.fileID,max_age:s.maxAge})}else{if(!M(s))throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(D,".getTempFileURL] invalid fileList")}));o.push({fileid:s})}return[4,this.request.send("storage.batchGetDownloadUrl",{file_list:o})];case 1:return(a=c.sent()).code?[2,U(e,null,a)]:[2,U(e,null,{fileList:a.data.download_list,requestId:a.requestId})]}var u}))}))},t.prototype.downloadFile=function(t,e){return N(this,void 0,void 0,(function(){var n,o,r,i,s,a;return L(this,(function(c){switch(c.label){case 0:if(n=t.fileID,!M(n))throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(D,".getTempFileURL] fileID must be string")}));return[4,this.getTempFileURL.call(this,{fileList:[{fileID:n,maxAge:600}]})];case 1:return o=c.sent(),"SUCCESS"!==(r=o.fileList[0]).code?[2,U(e,r)]:(i=this.request,s=encodeURI(r.download_url),[4,i.download({url:s})]);case 2:return a=c.sent(),[2,U(e,null,a)]}}))}))},R([C({customInfo:{className:"Cloudbase",methodName:"uploadFile"},title:"上传文件失败",messages:["请确认以下各项:"," 1 - 调用 uploadFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(T)]}),j("design:type",Function),j("design:paramtypes",[Object,Function]),j("design:returntype",Promise)],t.prototype,"uploadFile",null),R([C({customInfo:{className:"Cloudbase",methodName:"getUploadMetadata"},title:"获取上传元信息失败",messages:["请确认以下各项:"," 1 - 调用 getUploadMetadata() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(T)]}),j("design:type",Function),j("design:paramtypes",[Object,Function]),j("design:returntype",Promise)],t.prototype,"getUploadMetadata",null),R([C({customInfo:{className:"Cloudbase",methodName:"deleteFile"},title:"删除文件失败",messages:["请确认以下各项:"," 1 - 调用 deleteFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(T)]}),j("design:type",Function),j("design:paramtypes",[Object,Function]),j("design:returntype",Promise)],t.prototype,"deleteFile",null),R([C({customInfo:{className:"Cloudbase",methodName:"getTempFileURL"},title:"获取文件下载链接",messages:["请确认以下各项:"," 1 - 调用 getTempFileURL() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(T)]}),j("design:type",Function),j("design:paramtypes",[Object,Function]),j("design:returntype",Promise)],t.prototype,"getTempFileURL",null),R([C({customInfo:{className:"Cloudbase",methodName:"downloadFile"},title:"下载文件失败",messages:["请确认以下各项:"," 1 - 调用 downloadFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(T)]}),j("design:type",Function),j("design:paramtypes",[Object,Function]),j("design:returntype",Promise)],t.prototype,"downloadFile",null),t}()),q={name:D,entity:{uploadFile:k.uploadFile,deleteFile:k.deleteFile,getTempFileURL:k.getTempFileURL,downloadFile:k.downloadFile,getUploadMetadata:k.getUploadMetadata}};try{cloudbase.registerComponent(q)}catch(_){}function V(t){try{t.registerComponent(q)}catch(t){console.warn(t)}}}},e={};function n(o){var r=e[o];if(void 0!==r)return r.exports;var i=e[o]={exports:{}};return t[o](i,i.exports,n),i.exports}n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};return(()=>{var t=o;Object.defineProperty(t,"__esModule",{value:!0}),t.registerStorage=void 0;var e=n(352);t.registerStorage=e.registerStorage})(),o})()));
|
|
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={352:(t,e,n)=>{n.r(e),n.d(e,{registerStorage:()=>J});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(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(r(),"][").concat(t,"]:").concat(e))}var u,l,p=(u=function(t,e){return u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},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 n(){this.constructor=t}u(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),f=function(){return f=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},f.apply(this,arguments)},d=function(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((o=o.apply(t,e||[])).next())}))},h=function(t,e){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=e.call(t,s)}catch(t){a=[6,t],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(t){function e(e){var n=t.call(this)||this,o=e.timeout,r=e.timeoutMsg,i=e.restrictedMethods;return n.timeout=o||0,n.timeoutMsg=r||"请求超时",n.restrictedMethods=i||["get","post","upload","download"],n}p(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,n=t.file,o=t.name,r=t.method,i=t.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(e).forEach((function(t){c.append(t,e[t])})),c.append("key",o),c.append("file",n),this.request(f(f({},t),{data:c,method:a}),this.restrictedMethods.includes("upload"))):this.request(f(f({},t),{method:"put",headers:s,body:n}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return d(this,void 0,void 0,(function(){var e,n,o,r;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,n=window.URL.createObjectURL(new Blob([e])),o=decodeURIComponent(new URL(t.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(e){e({statusCode:200,tempFilePath:t.url})}))]}}))}))},e.prototype.fetch=function(t){var e;return d(this,void 0,void 0,(function(){var n,o,r,i,s,a,c,u,l,p,y,m=this;return h(this,(function(g){switch(g.label){case 0:return n=new AbortController,o=t.url,r=t.enableAbort,i=void 0!==r&&r,s=t.stream,a=void 0!==s&&s,c=t.signal,u=t.timeout,l=null!=u?u:this.timeout,c&&(c.aborted&&n.abort(),c.addEventListener("abort",(function(){return n.abort()}))),p=null,i&&l&&(p=setTimeout((function(){console.warn(m.timeoutMsg),n.abort(new Error(m.timeoutMsg))}),l)),[4,fetch(o,f(f({},t),{signal:n.signal})).then((function(t){return d(m,void 0,void 0,(function(){var e,n,o;return h(this,(function(r){switch(r.label){case 0:return clearTimeout(p),t.ok?(e=t,[3,3]):[3,1];case 1:return o=(n=Promise).reject,[4,t.json()];case 2:e=o.apply(n,[r.sent()]),r.label=3;case 3:return[2,e]}}))}))})).catch((function(t){return clearTimeout(p),Promise.reject(t)}))];case 1:return y=g.sent(),[2,{data:a?y.body:(null===(e=y.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?y.json():y.text(),statusCode:y.status,header:y.headers}]}}))}))},e.prototype.request=function(t,e){var n=this;void 0===e&&(e=!1);var o=String(t.method).toLowerCase()||"get";return new Promise((function(r){var i,s,a,c=t.url,u=t.headers,l=void 0===u?{}:u,p=t.data,f=t.responseType,d=t.withCredentials,h=t.body,y=t.onUploadProgress,m=function(t,e,n){void 0===n&&(n={});var o=/\?/.test(e),r="";return Object.keys(n).forEach((function(t){""===r?!o&&(e+="?"):r+="&",r+="".concat(t,"=").concat(encodeURIComponent(n[t]))})),/^http(s)?:\/\//.test(e+=r)?e:"".concat(t).concat(e)}("https:",c,"get"===o?p:{}),g=new XMLHttpRequest;g.open(o,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]+/),n={};e.forEach((function(t){var e=t.split(": "),o=e.shift().toLowerCase(),r=e.join(": ");n[o]=r})),t.header=n,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),r(t)}},e&&n.timeout&&(i=setTimeout((function(){console.warn(n.timeoutMsg),g.abort()}),n.timeout)),a=p,s="[object FormData]"===Object.prototype.toString.call(a)?p:"application/x-www-form-urlencoded"===l["content-type"]?function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach((function(n){e.push("".concat(n,"=").concat(encodeURIComponent(t[n])))})),e.join("&")}(p):h||(p?JSON.stringify(p):void 0),d&&(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,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,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=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),m=function(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((o=o.apply(t,e||[])).next())}))},g=function(t,e){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=e.call(t,s)}catch(t){a=[6,t],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])}}},b=function(t){function e(e){var n=t.call(this)||this;return n.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),n}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,n=t.platformInfo,o=void 0===n?{}:n,r=t.keys,i=void 0===r?{}:r;this.platformInfo=o,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 b(e.root));case"none":return new b(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,n){if("async"!==this.mode){if(this.storage)try{var o={version:n||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(o))}catch(t){throw new Error(JSON.stringify({code:s.OPERATION_FAIL,msg:"[".concat(r(),"][").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,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:e},[4,this.storage.setItem(t,JSON.stringify(o))];case 2:return r.sent(),[3,4];case 3:return r.sent(),[2];case 4:return[2]}}))}))},t.prototype.getStore=function(t,e){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(t){return""}e=e||"localCachev1";var o=this.storage.getItem(t);return o&&o.indexOf(e)>=0?JSON.parse(o).content:""}c(s.INVALID_OPERATION,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){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(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(o=r.sent())&&o.indexOf(e)>=0?[2,JSON.parse(o).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 v=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,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=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),w=function(t,e){this.data=e||null,this.name=t},I=function(t){function e(e,n){var o=t.call(this,"error",{error:e,data:n})||this;return o.error=e,o}return v(e,t),e}(w),O=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,n){n[t]=n[t]||[],n[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,n){if(null==n?void 0:n[t]){var o=n[t].indexOf(e);-1!==o&&n[t].splice(o,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if(t instanceof I)return console.error(t.error),this;var n=a(t)?new w(t,e||{}):t,o=n.name;if(this.listens(o)){n.target=this;for(var r=0,i=this.listeners[o]?function(t,e,n){if(n||2===arguments.length)for(var o,r=0,i=e.length;r<i;r++)!o&&r in e||(o||(o=Array.prototype.slice.call(e,0,r)),o[r]=e[r]);return t.concat(o||Array.prototype.slice.call(e))}([],this.listeners[o],!0):[];r<i.length;r++)i[r].call(this,n)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();function _(t){this.message=t}function A(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),A.prototype=new Error,A.prototype.name="InvalidTokenError";var R,S=function(){return S=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},S.apply(this,arguments)},F=function(t,e,n,o){var r,i=arguments.length,s=i<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,o);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(s=(i<3?r(s):i>3?r(e,n,s):r(e,n))||s);return i>3&&s&&Object.defineProperty(e,n,s),s},L=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},P=function(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((o=o.apply(t,e||[])).next())}))},N=function(t,e){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=e.call(t,s)}catch(t){a=[6,t],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(t){t.put="put",t.post="post"}(R||(R={}));var j=r,E=s,T="https://support.qq.com/products/148793",U=function(t){return"[object Array]"===Object.prototype.toString.call(t)},D=a,x=function(t,e,n){if(void 0===n&&(n=null),t&&"function"==typeof t)return t(e,n);if(e)throw e;return n},C=function(t){return t.mode,t.customInfo,t.title,t.messages,function(t,e,n){}},M="storage";function q(t){var e=t.lastIndexOf("/");return-1===e?t:t.slice(e+1)}var k=new(function(){function t(){}return t.prototype.uploadFile=function(t,e){return P(this,void 0,void 0,(function(){var n,o,r,i,s,a,c,u,l,p,f,d,h,y,m,g,b,v,w,I,O,_,A,F,L,P;return N(this,(function(N){switch(N.label){case 0:if(n=t.cloudPath,o=t.filePath,r=t.onUploadProgress,i=t.method,s=void 0===i?"put":i,a=t.headers,c=void 0===a?{}:a,u=t.fileContent,!D(n)||!o&&!u)throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(M,".uploadFile] invalid params")}));return l={put:R.put,post:R.post}[s.toLocaleLowerCase()]||R.put,p=this.request,f={path:n,method:l},l===R.put&&(f.headers=c),[4,p.send("storage.getUploadMetadata",f,t.customReqOpts)];case 1:return d=N.sent(),h=d.data,y=h.url,m=h.authorization,g=h.token,b=h.fileId,v=h.cosFileId,w=h.download_url,I=d.requestId,_=S(S({},O={url:y,file:o,name:n,onUploadProgress:r,fileContent:u,fileId:b,requestId:I}),{method:R.put,headers:S(S({},c),{authorization:m,"x-cos-meta-fileid":v,"x-cos-security-token":g})}),A=S(S({},O),{method:R.post,data:{key:n,signature:m,"x-cos-meta-fileid":v,success_action_status:"201","x-cos-security-token":g}}),(P={})[R.put]={params:_,isSuccess:function(t){return t>=200&&t<300}},P[R.post]={params:A,isSuccess:function(t){return 201===t}},F=P,[4,p.upload(F[l].params)];case 2:return L=N.sent(),F[l].isSuccess(L.statusCode)?[2,x(e,null,{fileID:b,download_url:w,requestId:I})]:[2,x(e,new Error("[".concat(j(),"][").concat(E.OPERATION_FAIL,"][").concat(M,"]:").concat(L.data)))]}}))}))},t.prototype.getUploadMetadata=function(t,e){return P(this,void 0,void 0,(function(){var n,o,r,i,s;return N(this,(function(a){switch(a.label){case 0:if(n=t.cloudPath,!D(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,3,,4]),[4,o.send(r,{path:n},t.customReqOpts)];case 2:return i=a.sent(),[2,x(e,null,i)];case 3:return s=a.sent(),[2,x(e,s)];case 4:return[2]}}))}))},t.prototype.deleteFile=function(t,e){return P(this,void 0,void 0,(function(){var n,o,r,i,s,a;return N(this,(function(c){switch(c.label){case 0:if(!(n=t.fileList)||!U(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])||!D(i))throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(M,".deleteFile] fileID must be string")}));return[4,this.request.send("storage.batchDeleteFile",{fileid_list:n},t.customReqOpts)];case 1:return(s=c.sent()).code?[2,x(e,null,s)]:(a={fileList:s.data.delete_list,requestId:s.requestId},[2,x(e,null,a)])}}))}))},t.prototype.getTempFileURL=function(t,e){return P(this,void 0,void 0,(function(){var n,o,r,i,s,a;return N(this,(function(c){switch(c.label){case 0:if(!(n=t.fileList)||!U(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],u=s,"[object Object]"===Object.prototype.toString.call(u)){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(!D(s))throw new Error(JSON.stringify({code:E.INVALID_PARAMS,msg:"[".concat(M,".getTempFileURL] invalid fileList")}));o.push({fileid:s})}return[4,this.request.send("storage.batchGetDownloadUrl",{file_list:o},t.customReqOpts)];case 1:return(a=c.sent()).code?[2,x(e,null,a)]:[2,x(e,null,{fileList:a.data.download_list,requestId:a.requestId})]}var u}))}))},t.prototype.downloadFile=function(t,e){return P(this,void 0,void 0,(function(){var n,o,r,i,s,a;return N(this,(function(c){switch(c.label){case 0:if(n=t.fileID,!D(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:t.customReqOpts})];case 1:return o=c.sent(),"SUCCESS"!==(r=o.fileList[0]).code?[2,x(e,r)]:(i=this.request,s=encodeURI(r.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 P(this,void 0,void 0,(function(){var n,o,r,i,s,a,c,u;return N(this,(function(l){switch(l.label){case 0:if(!(n=t.fileList)||!U(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[4,this.request.send("storage.batchCopyFile",{file_list:o},t.customReqOpts)];case 1:return(u=l.sent()).code?[2,x(e,null,u)]:[2,x(e,null,{fileList:u.data.copy_list,requestId:u.requestId})]}}))}))},t.prototype.getFileInfo=function(t){var e;return P(this,void 0,void 0,(function(){var n,o=this;return N(this,(function(r){switch(r.label){case 0:return[4,this.getTempFileURL(t)];case 1:return(null==(n=r.sent())?void 0:n.fileList)&&(null===(e=null==n?void 0:n.fileList)||void 0===e?void 0:e.length)>0?[4,Promise.all(n.fileList.map((function(t){return P(o,void 0,void 0,(function(){var e,n,o;return N(this,(function(r){switch(r.label){case 0:if("SUCCESS"!==t.code)return[2,{code:t.code,fileID:t.fileID,tempFileURL:t.tempFileURL}];r.label=1;case 1:return r.trys.push([1,3,,4]),[4,this.request.fetch({url:t.tempFileURL,method:"HEAD"})];case 2:return e=r.sent(),n=parseInt(e.headers["content-length"])||0,o=e.headers["content-type"]||"",[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}];case 3:return r.sent(),[2,{code:"FETCH_FILE_INFO_ERROR",fileID:t.fileID,tempFileURL:t.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}]}}))}))},F([C({customInfo:{className:"Cloudbase",methodName:"uploadFile"},title:"上传文件失败",messages:["请确认以下各项:"," 1 - 调用 uploadFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(T)]}),L("design:type",Function),L("design:paramtypes",[Object,Function]),L("design:returntype",Promise)],t.prototype,"uploadFile",null),F([C({customInfo:{className:"Cloudbase",methodName:"getUploadMetadata"},title:"获取上传元信息失败",messages:["请确认以下各项:"," 1 - 调用 getUploadMetadata() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(T)]}),L("design:type",Function),L("design:paramtypes",[Object,Function]),L("design:returntype",Promise)],t.prototype,"getUploadMetadata",null),F([C({customInfo:{className:"Cloudbase",methodName:"deleteFile"},title:"删除文件失败",messages:["请确认以下各项:"," 1 - 调用 deleteFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(T)]}),L("design:type",Function),L("design:paramtypes",[Object,Function]),L("design:returntype",Promise)],t.prototype,"deleteFile",null),F([C({customInfo:{className:"Cloudbase",methodName:"getTempFileURL"},title:"获取文件下载链接",messages:["请确认以下各项:"," 1 - 调用 getTempFileURL() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(T)]}),L("design:type",Function),L("design:paramtypes",[Object,Function]),L("design:returntype",Promise)],t.prototype,"getTempFileURL",null),F([C({customInfo:{className:"Cloudbase",methodName:"downloadFile"},title:"下载文件失败",messages:["请确认以下各项:"," 1 - 调用 downloadFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(T)]}),L("design:type",Function),L("design:paramtypes",[Object,Function]),L("design:returntype",Promise)],t.prototype,"downloadFile",null),F([C({customInfo:{className:"Cloudbase",methodName:"copyFile"},title:"批量复制文件",messages:["请确认以下各项:"," 1 - 调用 copyFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(T)]}),L("design:type",Function),L("design:paramtypes",[Object,Function]),L("design:returntype",Promise)],t.prototype,"copyFile",null),t}()),V={name:M,entity:{uploadFile:k.uploadFile,deleteFile:k.deleteFile,getTempFileURL:k.getTempFileURL,downloadFile:k.downloadFile,getUploadMetadata:k.getUploadMetadata,copyFile:k.copyFile,getFileInfo:k.getFileInfo}};try{cloudbase.registerComponent(V)}catch(_){}function J(t){try{t.registerComponent(V)}catch(t){console.warn(t)}}}},e={};function n(o){var r=e[o];if(void 0!==r)return r.exports;var i=e[o]={exports:{}};return t[o](i,i.exports,n),i.exports}n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};return(()=>{var t=o;Object.defineProperty(t,"__esModule",{value:!0}),t.registerStorage=void 0;var e=n(352);t.registerStorage=e.registerStorage})(),o})()));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/js-sdk",
|
|
3
|
-
"version": "2.21.
|
|
3
|
+
"version": "2.21.5",
|
|
4
4
|
"description": "cloudbase javascript sdk",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -46,23 +46,23 @@
|
|
|
46
46
|
"license": "Apache-2.0",
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@cloudbase/adapter-interface": "^0.7.1",
|
|
49
|
-
"@cloudbase/ai": "2.21.
|
|
50
|
-
"@cloudbase/analytics": "2.21.
|
|
51
|
-
"@cloudbase/app": "2.21.
|
|
52
|
-
"@cloudbase/auth": "2.21.
|
|
53
|
-
"@cloudbase/cloudrun": "2.21.
|
|
49
|
+
"@cloudbase/ai": "2.21.5",
|
|
50
|
+
"@cloudbase/analytics": "2.21.5",
|
|
51
|
+
"@cloudbase/app": "2.21.5",
|
|
52
|
+
"@cloudbase/auth": "2.21.5",
|
|
53
|
+
"@cloudbase/cloudrun": "2.21.5",
|
|
54
54
|
"@cloudbase/database": "0.9.22",
|
|
55
|
-
"@cloudbase/functions": "2.21.
|
|
56
|
-
"@cloudbase/model": "2.21.
|
|
57
|
-
"@cloudbase/realtime": "2.21.
|
|
58
|
-
"@cloudbase/storage": "2.21.
|
|
59
|
-
"@cloudbase/types": "2.21.
|
|
60
|
-
"@cloudbase/utilities": "2.21.
|
|
55
|
+
"@cloudbase/functions": "2.21.5",
|
|
56
|
+
"@cloudbase/model": "2.21.5",
|
|
57
|
+
"@cloudbase/realtime": "2.21.5",
|
|
58
|
+
"@cloudbase/storage": "2.21.5",
|
|
59
|
+
"@cloudbase/types": "2.21.5",
|
|
60
|
+
"@cloudbase/utilities": "2.21.5"
|
|
61
61
|
},
|
|
62
62
|
"browserslist": [
|
|
63
63
|
"last 2 version",
|
|
64
64
|
"> 1%",
|
|
65
65
|
"chrome 53"
|
|
66
66
|
],
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "afe094897dacbd42d3deca5c3ad73205b8d5d153"
|
|
68
68
|
}
|