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