@idm-plugin/aliclient2 0.0.2 → 0.0.4

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.
@@ -15,8 +15,9 @@ export declare class AliOssClient {
15
15
  * @param accessKeyId
16
16
  * @param accessKeySecret
17
17
  * @param internal boolean true 内网访问
18
+ * @param cname boolean 是否使用自定义域名访问
18
19
  */
19
- constructor(region: string, accessKeyId: string, accessKeySecret: string, internal: boolean);
20
+ constructor(region: string, accessKeyId: string, accessKeySecret: string, internal: boolean, cname?: boolean);
20
21
  putObjects(directory: string, streams: {
21
22
  name: string;
22
23
  stream: ReadStream | Buffer;
package/dist/index.js CHANGED
@@ -17,39 +17,40 @@ class I {
17
17
  * @param accessKeyId
18
18
  * @param accessKeySecret
19
19
  * @param internal boolean true 内网访问
20
+ * @param cname boolean 是否使用自定义域名访问
20
21
  */
21
- constructor(c, i, t, r) {
22
+ constructor(c, i, e, r, t = !0) {
22
23
  p(this, "client");
23
24
  p(this, "region");
24
25
  this.region = c, c === "tk" ? this.client = new f({
25
26
  secure: !0,
26
27
  region: "oss-ap-northeast-1",
27
28
  accessKeyId: i,
28
- accessKeySecret: t,
29
+ accessKeySecret: e,
29
30
  bucket: "idm-wx",
30
31
  internal: r,
31
- cname: !0,
32
- endpoint: "https://img.idmwx.com"
32
+ cname: t,
33
+ endpoint: t ? "https://img.idmwx.com" : void 0
33
34
  }) : this.client = new f({
34
35
  secure: !0,
35
36
  region: "oss-cn-hangzhou",
36
37
  accessKeyId: i,
37
- accessKeySecret: t,
38
+ accessKeySecret: e,
38
39
  bucket: "idm-hz",
39
40
  internal: r,
40
41
  cname: !0,
41
42
  endpoint: "https://osshz.idmwx.com"
42
43
  });
43
44
  }
44
- async putObjects(c, i, t = {}) {
45
- const r = i.map(async (e) => {
45
+ async putObjects(c, i, e = {}) {
46
+ const r = i.map(async (t) => {
46
47
  var u, n;
47
- let a = `${c}/${e.name}`.replaceAll(/\/\//g, "/");
48
+ let a = `${c}/${t.name}`.replaceAll(/\/\//g, "/");
48
49
  a = a.startsWith("/") ? a.substring(1) : a;
49
50
  const h = this.region === "tk" ? `https://oss.idmwx.com/${a}` : `https://osshz.idmwx.com/${a}`, d = this.region === "tk" ? `https://img.idmwx.com/${a}` : `https://osshz.idmwx.com/${a}`;
50
- return e.stream instanceof y ? await ((u = this.client) == null ? void 0 : u.putStream(a, e.stream)) : await ((n = this.client) == null ? void 0 : n.put(a, e.stream)), { url: h, name: e.name, aliSign: !0, external: d };
51
+ return t.stream instanceof y ? await ((u = this.client) == null ? void 0 : u.putStream(a, t.stream)) : await ((n = this.client) == null ? void 0 : n.put(a, t.stream)), { url: h, name: t.name, aliSign: !0, external: d };
51
52
  });
52
- return await Promise.all(r).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), []));
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), []));
53
54
  }
54
55
  /**
55
56
  * 删除对象
@@ -58,13 +59,13 @@ class I {
58
59
  */
59
60
  async deleteObject(c, i = {}) {
60
61
  var r;
61
- let t = `${c}`.replaceAll(/\/\//g, "/");
62
- t = t.startsWith("/") ? t.substring(1) : t;
62
+ let e = `${c}`.replaceAll(/\/\//g, "/");
63
+ e = e.startsWith("/") ? e.substring(1) : e;
63
64
  try {
64
- const e = await ((r = this.client) == null ? void 0 : r.delete(t));
65
- return s == null || s.info("[%s] delete oss object success: %s", i.requestId, t), e;
66
- } catch (e) {
67
- return s == null || s.error("[%s] delete oss object failed: %s - %j", i.requestId, t, e), null;
65
+ const t = await ((r = this.client) == null ? void 0 : r.delete(e));
66
+ return s == null || s.info("[%s] delete oss object success: %s", i.requestId, e), t;
67
+ } catch (t) {
68
+ return s == null || s.error("[%s] delete oss object failed: %s - %j", i.requestId, e, t), null;
68
69
  }
69
70
  }
70
71
  /**
@@ -73,35 +74,35 @@ class I {
73
74
  * @param names
74
75
  * @param options
75
76
  */
76
- async deleteObjects(c, i, t = {}) {
77
+ async deleteObjects(c, i, e = {}) {
77
78
  var d, u;
78
79
  let r = `${c}`.replaceAll(/\/\//g, "/");
79
80
  r = r.startsWith("/") ? r.substring(1) : r, r && !r.endsWith("/") && (r += "/");
80
- let e = [];
81
+ let t = [];
81
82
  if (Array.isArray(i) && i.length > 0)
82
- e = i.map((n) => `${r}${n}`.replaceAll(/\/\//g, "/").replace(/^\//, ""));
83
+ t = i.map((n) => `${r}${n}`.replaceAll(/\/\//g, "/").replace(/^\//, ""));
83
84
  else {
84
85
  let n;
85
86
  try {
86
87
  do {
87
- const l = await ((d = this.client) == null ? void 0 : d.list({ prefix: r, marker: n })), m = (l == null ? void 0 : l.objects) || [];
88
- e.push(...m.map((b) => b.name)), n = l == null ? void 0 : l.nextMarker;
88
+ const l = await ((d = this.client) == null ? void 0 : d.list({ prefix: r, marker: n, "max-keys": 1e3 })), m = (l == null ? void 0 : l.objects) || [];
89
+ t.push(...m.map((b) => b.name)), n = l == null ? void 0 : l.nextMarker;
89
90
  } while (n);
90
91
  } catch (l) {
91
- return s == null || s.error("[%s] list oss objects failed: %s - %j", t.requestId, r, l), [];
92
+ return s == null || s.error("[%s] list oss objects failed: %s - %j", e.requestId, r, l), [];
92
93
  }
93
94
  }
94
- if (e.length === 0)
95
- return s == null || s.info("[%s] no objects to delete for prefix: %s", t.requestId, r), [];
95
+ if (t.length === 0)
96
+ return s == null || s.info("[%s] no objects to delete for prefix: %s", e.requestId, r), [];
96
97
  const a = 1e3, h = [];
97
98
  try {
98
- for (let n = 0; n < e.length; n += a) {
99
- const l = e.slice(n, n + a), m = await ((u = this.client) == null ? void 0 : u.deleteMulti(l, { quiet: !0 }));
99
+ for (let n = 0; n < t.length; n += a) {
100
+ const l = t.slice(n, n + a), m = await ((u = this.client) == null ? void 0 : u.deleteMulti(l, { quiet: !0 }));
100
101
  h.push(m);
101
102
  }
102
- return s == null || s.info("[%s] delete oss objects success, count: %d", t.requestId, e.length), h;
103
+ return s == null || s.info("[%s] delete oss objects success, count: %d", e.requestId, t.length), h;
103
104
  } catch (n) {
104
- return s == null || s.error("[%s] delete oss objects failed: %s - %j", t.requestId, r, n), [];
105
+ return s == null || s.error("[%s] delete oss objects failed: %s - %j", e.requestId, r, n), [];
105
106
  }
106
107
  }
107
108
  /**
@@ -110,8 +111,8 @@ class I {
110
111
  * @param expires 过期时间,单位秒
111
112
  */
112
113
  async signature(c, i = 60) {
113
- var t;
114
- return (t = this.client) == null ? void 0 : t.signatureUrl(c, { expires: i });
114
+ var e;
115
+ return (e = this.client) == null ? void 0 : e.signatureUrl(c, { expires: i });
115
116
  }
116
117
  }
117
118
  export {
@@ -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 e;try{e=c.getLogger("ali-client")}catch{}finally{}class w{constructor(o,l,t,i){j(this,"client");j(this,"region");this.region=o,o==="tk"?this.client=new d({secure:!0,region:"oss-ap-northeast-1",accessKeyId:l,accessKeySecret:t,bucket:"idm-wx",internal:i,cname:!0,endpoint:"https://img.idmwx.com"}):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(o,l,t={}){const i=l.map(async s=>{var h,n;let a=`${o}/${s.name}`.replaceAll(/\/\//g,"/");a=a.startsWith("/")?a.substring(1):a;const f=this.region==="tk"?`https://oss.idmwx.com/${a}`:`https://osshz.idmwx.com/${a}`,m=this.region==="tk"?`https://img.idmwx.com/${a}`:`https://osshz.idmwx.com/${a}`;return s.stream instanceof b.ReadStream?await((h=this.client)==null?void 0:h.putStream(a,s.stream)):await((n=this.client)==null?void 0:n.put(a,s.stream)),{url:f,name:s.name,aliSign:!0,external:m}});return await Promise.all(i).then(s=>(e.info("[%s] upload to oss success, url: %j",t.requestId,s),s)).catch(s=>(e.error("[%s] upload to oss failed: %j-%s",t.requestId,s),[]))}async deleteObject(o,l={}){var i;let t=`${o}`.replaceAll(/\/\//g,"/");t=t.startsWith("/")?t.substring(1):t;try{const s=await((i=this.client)==null?void 0:i.delete(t));return e==null||e.info("[%s] delete oss object success: %s",l.requestId,t),s}catch(s){return e==null||e.error("[%s] delete oss object failed: %s - %j",l.requestId,t,s),null}}async deleteObjects(o,l,t={}){var m,h;let i=`${o}`.replaceAll(/\/\//g,"/");i=i.startsWith("/")?i.substring(1):i,i&&!i.endsWith("/")&&(i+="/");let s=[];if(Array.isArray(l)&&l.length>0)s=l.map(n=>`${i}${n}`.replaceAll(/\/\//g,"/").replace(/^\//,""));else{let n;try{do{const u=await((m=this.client)==null?void 0:m.list({prefix:i,marker:n})),p=(u==null?void 0:u.objects)||[];s.push(...p.map(x=>x.name)),n=u==null?void 0:u.nextMarker}while(n)}catch(u){return e==null||e.error("[%s] list oss objects failed: %s - %j",t.requestId,i,u),[]}}if(s.length===0)return e==null||e.info("[%s] no objects to delete for prefix: %s",t.requestId,i),[];const a=1e3,f=[];try{for(let n=0;n<s.length;n+=a){const u=s.slice(n,n+a),p=await((h=this.client)==null?void 0:h.deleteMulti(u,{quiet:!0}));f.push(p)}return e==null||e.info("[%s] delete oss objects success, count: %d",t.requestId,s.length),f}catch(n){return e==null||e.error("[%s] delete oss objects failed: %s - %j",t.requestId,i,n),[]}}async signature(o,l=60){var t;return(t=this.client)==null?void 0:t.signatureUrl(o,{expires:l})}}r.AliOssClient=w,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
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 t;try{t=c.getLogger("ali-client")}catch{}finally{}class w{constructor(a,l,s,i,e=!0){j(this,"client");j(this,"region");this.region=a,a==="tk"?this.client=new d({secure:!0,region:"oss-ap-northeast-1",accessKeyId:l,accessKeySecret:s,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:s,bucket:"idm-hz",internal:i,cname:!0,endpoint:"https://osshz.idmwx.com"})}async putObjects(a,l,s={}){const i=l.map(async e=>{var h,n;let o=`${a}/${e.name}`.replaceAll(/\/\//g,"/");o=o.startsWith("/")?o.substring(1):o;const f=this.region==="tk"?`https://oss.idmwx.com/${o}`:`https://osshz.idmwx.com/${o}`,m=this.region==="tk"?`https://img.idmwx.com/${o}`:`https://osshz.idmwx.com/${o}`;return e.stream instanceof b.ReadStream?await((h=this.client)==null?void 0:h.putStream(o,e.stream)):await((n=this.client)==null?void 0:n.put(o,e.stream)),{url:f,name:e.name,aliSign:!0,external:m}});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 deleteObject(a,l={}){var i;let s=`${a}`.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",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(a,l,s={}){var m,h;let i=`${a}`.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 u=await((m=this.client)==null?void 0:m.list({prefix:i,marker:n,"max-keys":1e3})),p=(u==null?void 0:u.objects)||[];e.push(...p.map(x=>x.name)),n=u==null?void 0:u.nextMarker}while(n)}catch(u){return t==null||t.error("[%s] list oss objects failed: %s - %j",s.requestId,i,u),[]}}if(e.length===0)return t==null||t.info("[%s] no objects to delete for prefix: %s",s.requestId,i),[];const o=1e3,f=[];try{for(let n=0;n<e.length;n+=o){const u=e.slice(n,n+o),p=await((h=this.client)==null?void 0:h.deleteMulti(u,{quiet:!0}));f.push(p)}return t==null||t.info("[%s] delete oss objects success, count: %d",s.requestId,e.length),f}catch(n){return t==null||t.error("[%s] delete oss objects failed: %s - %j",s.requestId,i,n),[]}}async signature(a,l=60){var s;return(s=this.client)==null?void 0:s.signatureUrl(a,{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.2",
4
+ "version": "0.0.4",
5
5
  "description": "idm plugin for ali used in backend",
6
6
  "type": "module",
7
7
  "keywords": [