@idm-plugin/aliclient2 0.0.4 → 0.0.6
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/dist/index.js +9 -9
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -44,11 +44,11 @@ class I {
|
|
|
44
44
|
}
|
|
45
45
|
async putObjects(c, i, e = {}) {
|
|
46
46
|
const r = i.map(async (t) => {
|
|
47
|
-
var
|
|
47
|
+
var n, l;
|
|
48
48
|
let a = `${c}/${t.name}`.replaceAll(/\/\//g, "/");
|
|
49
49
|
a = a.startsWith("/") ? a.substring(1) : a;
|
|
50
|
-
const
|
|
51
|
-
return t.stream instanceof y ? await ((
|
|
50
|
+
const u = this.region === "tk" ? `https://oss.idmwx.com/${a}` : `https://osshz.idmwx.com/${a}`, h = this.region === "tk" ? `https://img.idmwx.com/${a}` : `https://osshz.idmwx.com/${a}`, d = e.headers || {};
|
|
51
|
+
return t.stream instanceof y ? await ((n = this.client) == null ? void 0 : n.putStream(a, t.stream)) : await ((l = this.client) == null ? void 0 : l.put(a, t.stream, { headers: d })), { url: u, name: t.name, aliSign: !0, external: h };
|
|
52
52
|
});
|
|
53
53
|
return await Promise.all(r).then((t) => (s.info("[%s] upload to oss success, url: %j", e.requestId, t), t)).catch((t) => (s.error("[%s] upload to oss failed: %j-%s", e.requestId, t), []));
|
|
54
54
|
}
|
|
@@ -75,7 +75,7 @@ class I {
|
|
|
75
75
|
* @param options
|
|
76
76
|
*/
|
|
77
77
|
async deleteObjects(c, i, e = {}) {
|
|
78
|
-
var
|
|
78
|
+
var h, d;
|
|
79
79
|
let r = `${c}`.replaceAll(/\/\//g, "/");
|
|
80
80
|
r = r.startsWith("/") ? r.substring(1) : r, r && !r.endsWith("/") && (r += "/");
|
|
81
81
|
let t = [];
|
|
@@ -85,7 +85,7 @@ class I {
|
|
|
85
85
|
let n;
|
|
86
86
|
try {
|
|
87
87
|
do {
|
|
88
|
-
const l = await ((
|
|
88
|
+
const l = await ((h = this.client) == null ? void 0 : h.list({ prefix: r, marker: n, "max-keys": 1e3 })), m = (l == null ? void 0 : l.objects) || [];
|
|
89
89
|
t.push(...m.map((b) => b.name)), n = l == null ? void 0 : l.nextMarker;
|
|
90
90
|
} while (n);
|
|
91
91
|
} catch (l) {
|
|
@@ -94,13 +94,13 @@ class I {
|
|
|
94
94
|
}
|
|
95
95
|
if (t.length === 0)
|
|
96
96
|
return s == null || s.info("[%s] no objects to delete for prefix: %s", e.requestId, r), [];
|
|
97
|
-
const a = 1e3,
|
|
97
|
+
const a = 1e3, u = [];
|
|
98
98
|
try {
|
|
99
99
|
for (let n = 0; n < t.length; n += a) {
|
|
100
|
-
const l = t.slice(n, n + a), m = await ((
|
|
101
|
-
|
|
100
|
+
const l = t.slice(n, n + a), m = await ((d = this.client) == null ? void 0 : d.deleteMulti(l, { quiet: !0 }));
|
|
101
|
+
u.push(m);
|
|
102
102
|
}
|
|
103
|
-
return s == null || s.info("[%s] delete oss objects success, count: %d", e.requestId, t.length),
|
|
103
|
+
return s == null || s.info("[%s] delete oss objects success, count: %d", e.requestId, t.length), u;
|
|
104
104
|
} catch (n) {
|
|
105
105
|
return s == null || s.error("[%s] delete oss objects failed: %s - %j", e.requestId, r, n), [];
|
|
106
106
|
}
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(r,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@log4js-node/log4js-api"),require("ali-oss"),require("fs")):typeof define=="function"&&define.amd?define(["exports","@log4js-node/log4js-api","ali-oss","fs"],c):(r=typeof globalThis<"u"?globalThis:r||self,c(r["idm-plugin-aliclient"]={},r["@log4js-node/log4js-api"],r.OSS,r.fs))})(this,function(r,c,d,b){"use strict";var q=Object.defineProperty;var $=(r,c,d)=>c in r?q(r,c,{enumerable:!0,configurable:!0,writable:!0,value:d}):r[c]=d;var j=(r,c,d)=>($(r,typeof c!="symbol"?c+"":c,d),d);let
|
|
1
|
+
(function(r,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@log4js-node/log4js-api"),require("ali-oss"),require("fs")):typeof define=="function"&&define.amd?define(["exports","@log4js-node/log4js-api","ali-oss","fs"],c):(r=typeof globalThis<"u"?globalThis:r||self,c(r["idm-plugin-aliclient"]={},r["@log4js-node/log4js-api"],r.OSS,r.fs))})(this,function(r,c,d,b){"use strict";var q=Object.defineProperty;var $=(r,c,d)=>c in r?q(r,c,{enumerable:!0,configurable:!0,writable:!0,value:d}):r[c]=d;var j=(r,c,d)=>($(r,typeof c!="symbol"?c+"":c,d),d);let s;try{s=c.getLogger("ali-client")}catch{}finally{}class w{constructor(u,l,t,i,e=!0){j(this,"client");j(this,"region");this.region=u,u==="tk"?this.client=new d({secure:!0,region:"oss-ap-northeast-1",accessKeyId:l,accessKeySecret:t,bucket:"idm-wx",internal:i,cname:e,endpoint:e?"https://img.idmwx.com":void 0}):this.client=new d({secure:!0,region:"oss-cn-hangzhou",accessKeyId:l,accessKeySecret:t,bucket:"idm-hz",internal:i,cname:!0,endpoint:"https://osshz.idmwx.com"})}async putObjects(u,l,t={}){const i=l.map(async e=>{var n,o;let a=`${u}/${e.name}`.replaceAll(/\/\//g,"/");a=a.startsWith("/")?a.substring(1):a;const h=this.region==="tk"?`https://oss.idmwx.com/${a}`:`https://osshz.idmwx.com/${a}`,f=this.region==="tk"?`https://img.idmwx.com/${a}`:`https://osshz.idmwx.com/${a}`,m=t.headers||{};return e.stream instanceof b.ReadStream?await((n=this.client)==null?void 0:n.putStream(a,e.stream)):await((o=this.client)==null?void 0:o.put(a,e.stream,{headers:m})),{url:h,name:e.name,aliSign:!0,external:f}});return await Promise.all(i).then(e=>(s.info("[%s] upload to oss success, url: %j",t.requestId,e),e)).catch(e=>(s.error("[%s] upload to oss failed: %j-%s",t.requestId,e),[]))}async deleteObject(u,l={}){var i;let t=`${u}`.replaceAll(/\/\//g,"/");t=t.startsWith("/")?t.substring(1):t;try{const e=await((i=this.client)==null?void 0:i.delete(t));return s==null||s.info("[%s] delete oss object success: %s",l.requestId,t),e}catch(e){return s==null||s.error("[%s] delete oss object failed: %s - %j",l.requestId,t,e),null}}async deleteObjects(u,l,t={}){var f,m;let i=`${u}`.replaceAll(/\/\//g,"/");i=i.startsWith("/")?i.substring(1):i,i&&!i.endsWith("/")&&(i+="/");let e=[];if(Array.isArray(l)&&l.length>0)e=l.map(n=>`${i}${n}`.replaceAll(/\/\//g,"/").replace(/^\//,""));else{let n;try{do{const o=await((f=this.client)==null?void 0:f.list({prefix:i,marker:n,"max-keys":1e3})),p=(o==null?void 0:o.objects)||[];e.push(...p.map(x=>x.name)),n=o==null?void 0:o.nextMarker}while(n)}catch(o){return s==null||s.error("[%s] list oss objects failed: %s - %j",t.requestId,i,o),[]}}if(e.length===0)return s==null||s.info("[%s] no objects to delete for prefix: %s",t.requestId,i),[];const a=1e3,h=[];try{for(let n=0;n<e.length;n+=a){const o=e.slice(n,n+a),p=await((m=this.client)==null?void 0:m.deleteMulti(o,{quiet:!0}));h.push(p)}return s==null||s.info("[%s] delete oss objects success, count: %d",t.requestId,e.length),h}catch(n){return s==null||s.error("[%s] delete oss objects failed: %s - %j",t.requestId,i,n),[]}}async signature(u,l=60){var t;return(t=this.client)==null?void 0:t.signatureUrl(u,{expires:l})}}r.AliOssClient=w,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|