@idm-plugin/aliclient2 0.1.2 → 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 +7 -0
- package/dist/index.js +59 -43
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/alioss/src/oss.d.ts
CHANGED
|
@@ -34,6 +34,13 @@ export declare class AliOssClient {
|
|
|
34
34
|
aliSign: boolean;
|
|
35
35
|
external: string;
|
|
36
36
|
}[] | never[]>;
|
|
37
|
+
/**
|
|
38
|
+
* 检查对象是否存在
|
|
39
|
+
* @param filePath 对象路径
|
|
40
|
+
* @param options
|
|
41
|
+
* @returns boolean 存在返回 true, 不存在返回 false; 鉴权/网络等异常会向上抛出
|
|
42
|
+
*/
|
|
43
|
+
existsObject(filePath: string, options?: any): Promise<boolean>;
|
|
37
44
|
/**
|
|
38
45
|
* 删除对象
|
|
39
46
|
* @param filePath
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
var j = Object.defineProperty;
|
|
2
|
-
var w = (i,
|
|
3
|
-
var
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { ReadStream as
|
|
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
|
+
import y from "ali-oss";
|
|
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
|
}
|
|
@@ -40,8 +40,8 @@ const f = {
|
|
|
40
40
|
forceCname: !0
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
function
|
|
44
|
-
return i.domain ? i.domain : `https://${i.bucket}.${i.region}${
|
|
43
|
+
function I(i, c) {
|
|
44
|
+
return i.domain ? i.domain : `https://${i.bucket}.${i.region}${c ? "-internal" : ""}.aliyuncs.com`;
|
|
45
45
|
}
|
|
46
46
|
class C {
|
|
47
47
|
/**
|
|
@@ -52,47 +52,63 @@ class C {
|
|
|
52
52
|
* @param internal boolean true 内网访问
|
|
53
53
|
* @param cname boolean 是否使用自定义域名访问
|
|
54
54
|
*/
|
|
55
|
-
constructor(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this.region =
|
|
60
|
-
const
|
|
61
|
-
this.domain =
|
|
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({
|
|
62
62
|
secure: !0,
|
|
63
|
-
region:
|
|
64
|
-
accessKeyId:
|
|
63
|
+
region: o.region,
|
|
64
|
+
accessKeyId: n,
|
|
65
65
|
accessKeySecret: e,
|
|
66
|
-
bucket:
|
|
66
|
+
bucket: o.bucket,
|
|
67
67
|
internal: r,
|
|
68
|
-
cname:
|
|
69
|
-
endpoint:
|
|
68
|
+
cname: h,
|
|
69
|
+
endpoint: h ? o.endpoint : void 0
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
|
-
async putObjects(
|
|
73
|
-
const r =
|
|
72
|
+
async putObjects(c, n, e = {}) {
|
|
73
|
+
const r = n.map(async (t) => {
|
|
74
74
|
var a, u;
|
|
75
|
-
let
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
return t.stream instanceof
|
|
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 };
|
|
79
79
|
});
|
|
80
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
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
|
+
}
|
|
97
|
+
}
|
|
82
98
|
/**
|
|
83
99
|
* 删除对象
|
|
84
100
|
* @param filePath
|
|
85
101
|
* @param options
|
|
86
102
|
*/
|
|
87
|
-
async deleteObject(
|
|
103
|
+
async deleteObject(c, n = {}) {
|
|
88
104
|
var r;
|
|
89
|
-
let e = `${
|
|
105
|
+
let e = `${c}`.replaceAll(/\/\//g, "/");
|
|
90
106
|
e = e.startsWith("/") ? e.substring(1) : e;
|
|
91
107
|
try {
|
|
92
108
|
const t = await ((r = this.client) == null ? void 0 : r.delete(e));
|
|
93
|
-
return s == null || s.info("[%s] delete oss object success: %s",
|
|
109
|
+
return s == null || s.info("[%s] delete oss object success: %s", n.requestId, e), t;
|
|
94
110
|
} catch (t) {
|
|
95
|
-
return s == null || s.error("[%s] delete oss object failed: %s - %j",
|
|
111
|
+
return s == null || s.error("[%s] delete oss object failed: %s - %j", n.requestId, e, t), null;
|
|
96
112
|
}
|
|
97
113
|
}
|
|
98
114
|
/**
|
|
@@ -101,18 +117,18 @@ class C {
|
|
|
101
117
|
* @param names
|
|
102
118
|
* @param options
|
|
103
119
|
*/
|
|
104
|
-
async deleteObjects(
|
|
105
|
-
var
|
|
106
|
-
let r = `${
|
|
120
|
+
async deleteObjects(c, n, e = {}) {
|
|
121
|
+
var l, d;
|
|
122
|
+
let r = `${c}`.replaceAll(/\/\//g, "/");
|
|
107
123
|
r = r.startsWith("/") ? r.substring(1) : r, r && !r.endsWith("/") && (r += "/");
|
|
108
124
|
let t = [];
|
|
109
|
-
if (Array.isArray(
|
|
110
|
-
t =
|
|
125
|
+
if (Array.isArray(n) && n.length > 0)
|
|
126
|
+
t = n.map((a) => `${r}${a}`.replaceAll(/\/\//g, "/").replace(/^\//, ""));
|
|
111
127
|
else {
|
|
112
128
|
let a;
|
|
113
129
|
try {
|
|
114
130
|
do {
|
|
115
|
-
const u = await ((
|
|
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) || [];
|
|
116
132
|
t.push(...p.map((b) => b.name)), a = u == null ? void 0 : u.nextMarker;
|
|
117
133
|
} while (a);
|
|
118
134
|
} catch (u) {
|
|
@@ -121,13 +137,13 @@ class C {
|
|
|
121
137
|
}
|
|
122
138
|
if (t.length === 0)
|
|
123
139
|
return s == null || s.info("[%s] no objects to delete for prefix: %s", e.requestId, r), [];
|
|
124
|
-
const
|
|
140
|
+
const o = 1e3, h = [];
|
|
125
141
|
try {
|
|
126
|
-
for (let a = 0; a < t.length; a +=
|
|
127
|
-
const u = t.slice(a, a +
|
|
128
|
-
|
|
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);
|
|
129
145
|
}
|
|
130
|
-
return s == null || s.info("[%s] delete oss objects success, count: %d", e.requestId, t.length),
|
|
146
|
+
return s == null || s.info("[%s] delete oss objects success, count: %d", e.requestId, t.length), h;
|
|
131
147
|
} catch (a) {
|
|
132
148
|
return s == null || s.error("[%s] delete oss objects failed: %s - %j", e.requestId, r, a), [];
|
|
133
149
|
}
|
|
@@ -137,9 +153,9 @@ class C {
|
|
|
137
153
|
* @param url 待签名的url
|
|
138
154
|
* @param expires 过期时间,单位秒
|
|
139
155
|
*/
|
|
140
|
-
async signature(
|
|
156
|
+
async signature(c, n = 60) {
|
|
141
157
|
var e;
|
|
142
|
-
return (e = this.client) == null ? void 0 : e.signatureUrl(
|
|
158
|
+
return (e = this.client) == null ? void 0 : e.signatureUrl(c, { expires: n });
|
|
143
159
|
}
|
|
144
160
|
}
|
|
145
161
|
export {
|
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"})});
|