@idm-plugin/aliclient2 0.0.5 → 0.0.7
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 +12 -12
- package/dist/index.umd.cjs +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ try {
|
|
|
10
10
|
} catch {
|
|
11
11
|
} finally {
|
|
12
12
|
}
|
|
13
|
-
class
|
|
13
|
+
class A {
|
|
14
14
|
/**
|
|
15
15
|
* 创建阿里云OSS客户端
|
|
16
16
|
* @param region enum [tk, hz]
|
|
@@ -39,16 +39,16 @@ class I {
|
|
|
39
39
|
bucket: "idm-hz",
|
|
40
40
|
internal: r,
|
|
41
41
|
cname: !0,
|
|
42
|
-
endpoint: "https://
|
|
42
|
+
endpoint: "https://ossimg.ormwx.com"
|
|
43
43
|
});
|
|
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://ossimg.ormwx.com/${a}`, h = this.region === "tk" ? `https://img.idmwx.com/${a}` : `https://ossimg.ormwx.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
|
}
|
|
@@ -116,5 +116,5 @@ class I {
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
export {
|
|
119
|
-
|
|
119
|
+
A as AliOssClient
|
|
120
120
|
};
|
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
|
|
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 g=Object.defineProperty;var q=(r,c,d)=>c in r?g(r,c,{enumerable:!0,configurable:!0,writable:!0,value:d}):r[c]=d;var j=(r,c,d)=>(q(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://ossimg.ormwx.com"})}async putObjects(u,l,t={}){const i=l.map(async e=>{var n,a;let o=`${u}/${e.name}`.replaceAll(/\/\//g,"/");o=o.startsWith("/")?o.substring(1):o;const h=this.region==="tk"?`https://oss.idmwx.com/${o}`:`https://ossimg.ormwx.com/${o}`,f=this.region==="tk"?`https://img.idmwx.com/${o}`:`https://ossimg.ormwx.com/${o}`,m=t.headers||{};return e.stream instanceof b.ReadStream?await((n=this.client)==null?void 0:n.putStream(o,e.stream)):await((a=this.client)==null?void 0:a.put(o,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 a=await((f=this.client)==null?void 0:f.list({prefix:i,marker:n,"max-keys":1e3})),p=(a==null?void 0:a.objects)||[];e.push(...p.map(x=>x.name)),n=a==null?void 0:a.nextMarker}while(n)}catch(a){return s==null||s.error("[%s] list oss objects failed: %s - %j",t.requestId,i,a),[]}}if(e.length===0)return s==null||s.info("[%s] no objects to delete for prefix: %s",t.requestId,i),[];const o=1e3,h=[];try{for(let n=0;n<e.length;n+=o){const a=e.slice(n,n+o),p=await((m=this.client)==null?void 0:m.deleteMulti(a,{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"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idm-plugin/aliclient2",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.7",
|
|
5
5
|
"description": "idm plugin for ali used in backend",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"keywords": [
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
],
|
|
19
19
|
"main": "./dist/index.umd.cjs",
|
|
20
20
|
"module": "./dist/index.js",
|
|
21
|
-
"types": "index.d.ts",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
22
|
"scripts": {
|
|
23
23
|
"dev": "vite --config ./build/base.config.ts",
|
|
24
24
|
"build": "vite build --config ./build/lib.config.ts",
|