@idm-plugin/aliclient2 0.1.1 → 0.1.2
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/alioss/src/oss.d.ts +2 -1
- package/dist/index.js +62 -55
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/alioss/src/oss.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
var j = Object.defineProperty;
|
|
2
|
-
var w = (
|
|
3
|
-
var d = (
|
|
2
|
+
var w = (i, n, o) => n in i ? j(i, n, { enumerable: !0, configurable: !0, writable: !0, value: o }) : i[n] = o;
|
|
3
|
+
var d = (i, n, o) => (w(i, typeof n != "symbol" ? n + "" : n, o), o);
|
|
4
4
|
import k from "@log4js-node/log4js-api";
|
|
5
|
-
import
|
|
6
|
-
import { ReadStream as
|
|
5
|
+
import x from "ali-oss";
|
|
6
|
+
import { ReadStream as y } from "fs";
|
|
7
7
|
let s;
|
|
8
8
|
try {
|
|
9
9
|
s = k.getLogger("ali-client");
|
|
10
10
|
} catch {
|
|
11
11
|
} finally {
|
|
12
12
|
}
|
|
13
|
-
var $ = /* @__PURE__ */ ((
|
|
13
|
+
var $ = /* @__PURE__ */ ((i) => (i.tk = "tk", i.hz = "hz", i.sh = "sh", i.pvc = "pvc", i))($ || {});
|
|
14
14
|
const f = {
|
|
15
15
|
tk: {
|
|
16
16
|
region: "oss-ap-northeast-1",
|
|
@@ -31,12 +31,19 @@ const f = {
|
|
|
31
31
|
domain: "https://osssh.ormwx.com",
|
|
32
32
|
endpoint: "https://osssh.ormwx.com",
|
|
33
33
|
forceCname: !0
|
|
34
|
+
},
|
|
35
|
+
pvc: {
|
|
36
|
+
region: "oss-cn-hangzhou",
|
|
37
|
+
bucket: "orm-privacy",
|
|
38
|
+
domain: "https://osspvc.ormwx.com",
|
|
39
|
+
endpoint: "https://osspvc.ormwx.com",
|
|
40
|
+
forceCname: !0
|
|
34
41
|
}
|
|
35
42
|
};
|
|
36
|
-
function
|
|
37
|
-
return
|
|
43
|
+
function v(i, n) {
|
|
44
|
+
return i.domain ? i.domain : `https://${i.bucket}.${i.region}${n ? "-internal" : ""}.aliyuncs.com`;
|
|
38
45
|
}
|
|
39
|
-
class
|
|
46
|
+
class C {
|
|
40
47
|
/**
|
|
41
48
|
* 创建阿里云OSS客户端
|
|
42
49
|
* @param region enum [tk, hz, sh]
|
|
@@ -45,47 +52,47 @@ class O {
|
|
|
45
52
|
* @param internal boolean true 内网访问
|
|
46
53
|
* @param cname boolean 是否使用自定义域名访问
|
|
47
54
|
*/
|
|
48
|
-
constructor(n,
|
|
55
|
+
constructor(n, o, e, r, t = !0) {
|
|
49
56
|
d(this, "client");
|
|
50
57
|
d(this, "region");
|
|
51
58
|
d(this, "domain");
|
|
52
59
|
this.region = n;
|
|
53
|
-
const
|
|
54
|
-
this.domain =
|
|
60
|
+
const c = f[this.region] || f.hz, l = !!c.endpoint && (c.forceCname ?? t);
|
|
61
|
+
this.domain = v(c, r), this.client = new x({
|
|
55
62
|
secure: !0,
|
|
56
|
-
region:
|
|
57
|
-
accessKeyId:
|
|
58
|
-
accessKeySecret:
|
|
59
|
-
bucket:
|
|
63
|
+
region: c.region,
|
|
64
|
+
accessKeyId: o,
|
|
65
|
+
accessKeySecret: e,
|
|
66
|
+
bucket: c.bucket,
|
|
60
67
|
internal: r,
|
|
61
|
-
cname:
|
|
62
|
-
endpoint:
|
|
68
|
+
cname: l,
|
|
69
|
+
endpoint: l ? c.endpoint : void 0
|
|
63
70
|
});
|
|
64
71
|
}
|
|
65
|
-
async putObjects(n,
|
|
66
|
-
const r =
|
|
67
|
-
var
|
|
68
|
-
let
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
return
|
|
72
|
+
async putObjects(n, o, e = {}) {
|
|
73
|
+
const r = o.map(async (t) => {
|
|
74
|
+
var a, u;
|
|
75
|
+
let c = `${n}/${t.name}`.replaceAll(/\/\//g, "/");
|
|
76
|
+
c = c.startsWith("/") ? c.substring(1) : c;
|
|
77
|
+
const l = `${this.domain}/${c}`, h = `${this.domain}/${c}`, m = e.headers || {};
|
|
78
|
+
return t.stream instanceof y ? await ((a = this.client) == null ? void 0 : a.putStream(c, t.stream)) : await ((u = this.client) == null ? void 0 : u.put(c, t.stream, { headers: m })), { url: l, name: t.name, aliSign: !0, external: h };
|
|
72
79
|
});
|
|
73
|
-
return await Promise.all(r).then((
|
|
80
|
+
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), []));
|
|
74
81
|
}
|
|
75
82
|
/**
|
|
76
83
|
* 删除对象
|
|
77
84
|
* @param filePath
|
|
78
85
|
* @param options
|
|
79
86
|
*/
|
|
80
|
-
async deleteObject(n,
|
|
87
|
+
async deleteObject(n, o = {}) {
|
|
81
88
|
var r;
|
|
82
|
-
let
|
|
83
|
-
|
|
89
|
+
let e = `${n}`.replaceAll(/\/\//g, "/");
|
|
90
|
+
e = e.startsWith("/") ? e.substring(1) : e;
|
|
84
91
|
try {
|
|
85
|
-
const
|
|
86
|
-
return s == null || s.info("[%s] delete oss object success: %s",
|
|
87
|
-
} catch (
|
|
88
|
-
return s == null || s.error("[%s] delete oss object failed: %s - %j",
|
|
92
|
+
const t = await ((r = this.client) == null ? void 0 : r.delete(e));
|
|
93
|
+
return s == null || s.info("[%s] delete oss object success: %s", o.requestId, e), t;
|
|
94
|
+
} catch (t) {
|
|
95
|
+
return s == null || s.error("[%s] delete oss object failed: %s - %j", o.requestId, e, t), null;
|
|
89
96
|
}
|
|
90
97
|
}
|
|
91
98
|
/**
|
|
@@ -94,35 +101,35 @@ class O {
|
|
|
94
101
|
* @param names
|
|
95
102
|
* @param options
|
|
96
103
|
*/
|
|
97
|
-
async deleteObjects(n,
|
|
104
|
+
async deleteObjects(n, o, e = {}) {
|
|
98
105
|
var h, m;
|
|
99
106
|
let r = `${n}`.replaceAll(/\/\//g, "/");
|
|
100
107
|
r = r.startsWith("/") ? r.substring(1) : r, r && !r.endsWith("/") && (r += "/");
|
|
101
|
-
let
|
|
102
|
-
if (Array.isArray(
|
|
103
|
-
|
|
108
|
+
let t = [];
|
|
109
|
+
if (Array.isArray(o) && o.length > 0)
|
|
110
|
+
t = o.map((a) => `${r}${a}`.replaceAll(/\/\//g, "/").replace(/^\//, ""));
|
|
104
111
|
else {
|
|
105
|
-
let
|
|
112
|
+
let a;
|
|
106
113
|
try {
|
|
107
114
|
do {
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
} while (
|
|
111
|
-
} catch (
|
|
112
|
-
return s == null || s.error("[%s] list oss objects failed: %s - %j",
|
|
115
|
+
const u = await ((h = this.client) == null ? void 0 : h.list({ prefix: r, marker: a, "max-keys": 1e3 })), p = (u == null ? void 0 : u.objects) || [];
|
|
116
|
+
t.push(...p.map((b) => b.name)), a = u == null ? void 0 : u.nextMarker;
|
|
117
|
+
} while (a);
|
|
118
|
+
} catch (u) {
|
|
119
|
+
return s == null || s.error("[%s] list oss objects failed: %s - %j", e.requestId, r, u), [];
|
|
113
120
|
}
|
|
114
121
|
}
|
|
115
|
-
if (
|
|
116
|
-
return s == null || s.info("[%s] no objects to delete for prefix: %s",
|
|
117
|
-
const
|
|
122
|
+
if (t.length === 0)
|
|
123
|
+
return s == null || s.info("[%s] no objects to delete for prefix: %s", e.requestId, r), [];
|
|
124
|
+
const c = 1e3, l = [];
|
|
118
125
|
try {
|
|
119
|
-
for (let
|
|
120
|
-
const
|
|
121
|
-
|
|
126
|
+
for (let a = 0; a < t.length; a += c) {
|
|
127
|
+
const u = t.slice(a, a + c), p = await ((m = this.client) == null ? void 0 : m.deleteMulti(u, { quiet: !0 }));
|
|
128
|
+
l.push(p);
|
|
122
129
|
}
|
|
123
|
-
return s == null || s.info("[%s] delete oss objects success, count: %d",
|
|
124
|
-
} catch (
|
|
125
|
-
return s == null || s.error("[%s] delete oss objects failed: %s - %j",
|
|
130
|
+
return s == null || s.info("[%s] delete oss objects success, count: %d", e.requestId, t.length), l;
|
|
131
|
+
} catch (a) {
|
|
132
|
+
return s == null || s.error("[%s] delete oss objects failed: %s - %j", e.requestId, r, a), [];
|
|
126
133
|
}
|
|
127
134
|
}
|
|
128
135
|
/**
|
|
@@ -130,12 +137,12 @@ class O {
|
|
|
130
137
|
* @param url 待签名的url
|
|
131
138
|
* @param expires 过期时间,单位秒
|
|
132
139
|
*/
|
|
133
|
-
async signature(n,
|
|
134
|
-
var
|
|
135
|
-
return (
|
|
140
|
+
async signature(n, o = 60) {
|
|
141
|
+
var e;
|
|
142
|
+
return (e = this.client) == null ? void 0 : e.signatureUrl(n, { expires: o });
|
|
136
143
|
}
|
|
137
144
|
}
|
|
138
145
|
export {
|
|
139
|
-
|
|
146
|
+
C as AliOssClient,
|
|
140
147
|
$ as OSSRegion
|
|
141
148
|
};
|
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,h,k){"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,h,k){"use strict";var q=Object.defineProperty;var v=(r,c,h)=>c in r?q(r,c,{enumerable:!0,configurable:!0,writable:!0,value:h}):r[c]=h;var j=(r,c,h)=>(v(r,typeof c!="symbol"?c+"":c,h),h);let t;try{t=c.getLogger("ali-client")}catch{}finally{}var y=(u=>(u.tk="tk",u.hz="hz",u.sh="sh",u.pvc="pvc",u))(y||{});const w={tk:{region:"oss-ap-northeast-1",bucket:"idm-wx",domain:"https://osstk.ormwx.com",endpoint:"https://osstk.ormwx.com"},hz:{region:"oss-cn-hangzhou",bucket:"idm-hz",domain:"https://ossimg.ormwx.com",endpoint:"https://ossimg.ormwx.com",forceCname:!0},sh:{region:"oss-cn-shanghai",bucket:"orm-sh",domain:"https://osssh.ormwx.com",endpoint:"https://osssh.ormwx.com",forceCname:!0},pvc:{region:"oss-cn-hangzhou",bucket:"orm-privacy",domain:"https://osspvc.ormwx.com",endpoint:"https://osspvc.ormwx.com",forceCname:!0}};function x(u,d){return u.domain?u.domain:`https://${u.bucket}.${u.region}${d?"-internal":""}.aliyuncs.com`}class ${constructor(d,l,s,n,e=!0){j(this,"client");j(this,"region");j(this,"domain");this.region=d;const i=w[this.region]||w.hz,m=!!i.endpoint&&(i.forceCname??e);this.domain=x(i,n),this.client=new h({secure:!0,region:i.region,accessKeyId:l,accessKeySecret:s,bucket:i.bucket,internal:n,cname:m,endpoint:m?i.endpoint:void 0})}async putObjects(d,l,s={}){const n=l.map(async e=>{var o,a;let i=`${d}/${e.name}`.replaceAll(/\/\//g,"/");i=i.startsWith("/")?i.substring(1):i;const m=`${this.domain}/${i}`,p=`${this.domain}/${i}`,f=s.headers||{};return e.stream instanceof k.ReadStream?await((o=this.client)==null?void 0:o.putStream(i,e.stream)):await((a=this.client)==null?void 0:a.put(i,e.stream,{headers:f})),{url:m,name:e.name,aliSign:!0,external:p}});return await Promise.all(n).then(e=>(t.info("[%s] upload to oss success, url: %j",s.requestId,e),e)).catch(e=>(t.error("[%s] upload to oss failed: %j-%s",s.requestId,e),[]))}async deleteObject(d,l={}){var n;let s=`${d}`.replaceAll(/\/\//g,"/");s=s.startsWith("/")?s.substring(1):s;try{const e=await((n=this.client)==null?void 0:n.delete(s));return t==null||t.info("[%s] delete oss object success: %s",l.requestId,s),e}catch(e){return t==null||t.error("[%s] delete oss object failed: %s - %j",l.requestId,s,e),null}}async deleteObjects(d,l,s={}){var p,f;let n=`${d}`.replaceAll(/\/\//g,"/");n=n.startsWith("/")?n.substring(1):n,n&&!n.endsWith("/")&&(n+="/");let e=[];if(Array.isArray(l)&&l.length>0)e=l.map(o=>`${n}${o}`.replaceAll(/\/\//g,"/").replace(/^\//,""));else{let o;try{do{const a=await((p=this.client)==null?void 0:p.list({prefix:n,marker:o,"max-keys":1e3})),b=(a==null?void 0:a.objects)||[];e.push(...b.map(g=>g.name)),o=a==null?void 0:a.nextMarker}while(o)}catch(a){return t==null||t.error("[%s] list oss objects failed: %s - %j",s.requestId,n,a),[]}}if(e.length===0)return t==null||t.info("[%s] no objects to delete for prefix: %s",s.requestId,n),[];const i=1e3,m=[];try{for(let o=0;o<e.length;o+=i){const a=e.slice(o,o+i),b=await((f=this.client)==null?void 0:f.deleteMulti(a,{quiet:!0}));m.push(b)}return t==null||t.info("[%s] delete oss objects success, count: %d",s.requestId,e.length),m}catch(o){return t==null||t.error("[%s] delete oss objects failed: %s - %j",s.requestId,n,o),[]}}async signature(d,l=60){var s;return(s=this.client)==null?void 0:s.signatureUrl(d,{expires:l})}}r.AliOssClient=$,r.OSSRegion=y,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|