@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.
@@ -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环境中使用
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
1
  var j = Object.defineProperty;
2
- var w = (c, n, i) => n in c ? j(c, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : c[n] = i;
3
- var d = (c, n, i) => (w(c, typeof n != "symbol" ? n + "" : n, i), i);
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 y from "ali-oss";
6
- import { ReadStream as x } from "fs";
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__ */ ((c) => (c.tk = "tk", c.hz = "hz", c.sh = "sh", c))($ || {});
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(c, n) {
37
- return c.domain ? c.domain : `https://${c.bucket}.${c.region}${n ? "-internal" : ""}.aliyuncs.com`;
43
+ function v(i, n) {
44
+ return i.domain ? i.domain : `https://${i.bucket}.${i.region}${n ? "-internal" : ""}.aliyuncs.com`;
38
45
  }
39
- class O {
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, i, t, r, e = !0) {
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 a = f[this.region] || f.hz, u = !!a.endpoint && (a.forceCname ?? e);
54
- this.domain = I(a, r), this.client = new y({
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: a.region,
57
- accessKeyId: i,
58
- accessKeySecret: t,
59
- bucket: a.bucket,
63
+ region: c.region,
64
+ accessKeyId: o,
65
+ accessKeySecret: e,
66
+ bucket: c.bucket,
60
67
  internal: r,
61
- cname: u,
62
- endpoint: u ? a.endpoint : void 0
68
+ cname: l,
69
+ endpoint: l ? c.endpoint : void 0
63
70
  });
64
71
  }
65
- async putObjects(n, i, t = {}) {
66
- const r = i.map(async (e) => {
67
- var o, l;
68
- let a = `${n}/${e.name}`.replaceAll(/\/\//g, "/");
69
- a = a.startsWith("/") ? a.substring(1) : a;
70
- const u = `${this.domain}/${a}`, h = `${this.domain}/${a}`, m = t.headers || {};
71
- return e.stream instanceof x ? await ((o = this.client) == null ? void 0 : o.putStream(a, e.stream)) : await ((l = this.client) == null ? void 0 : l.put(a, e.stream, { headers: m })), { url: u, name: e.name, aliSign: !0, external: h };
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((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), []));
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, i = {}) {
87
+ async deleteObject(n, o = {}) {
81
88
  var r;
82
- let t = `${n}`.replaceAll(/\/\//g, "/");
83
- t = t.startsWith("/") ? t.substring(1) : t;
89
+ let e = `${n}`.replaceAll(/\/\//g, "/");
90
+ e = e.startsWith("/") ? e.substring(1) : e;
84
91
  try {
85
- const e = await ((r = this.client) == null ? void 0 : r.delete(t));
86
- return s == null || s.info("[%s] delete oss object success: %s", i.requestId, t), e;
87
- } catch (e) {
88
- return s == null || s.error("[%s] delete oss object failed: %s - %j", i.requestId, t, e), null;
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, i, t = {}) {
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 e = [];
102
- if (Array.isArray(i) && i.length > 0)
103
- e = i.map((o) => `${r}${o}`.replaceAll(/\/\//g, "/").replace(/^\//, ""));
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 o;
112
+ let a;
106
113
  try {
107
114
  do {
108
- const l = await ((h = this.client) == null ? void 0 : h.list({ prefix: r, marker: o, "max-keys": 1e3 })), p = (l == null ? void 0 : l.objects) || [];
109
- e.push(...p.map((b) => b.name)), o = l == null ? void 0 : l.nextMarker;
110
- } while (o);
111
- } catch (l) {
112
- return s == null || s.error("[%s] list oss objects failed: %s - %j", t.requestId, r, l), [];
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 (e.length === 0)
116
- return s == null || s.info("[%s] no objects to delete for prefix: %s", t.requestId, r), [];
117
- const a = 1e3, u = [];
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 o = 0; o < e.length; o += a) {
120
- const l = e.slice(o, o + a), p = await ((m = this.client) == null ? void 0 : m.deleteMulti(l, { quiet: !0 }));
121
- u.push(p);
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", t.requestId, e.length), u;
124
- } catch (o) {
125
- return s == null || s.error("[%s] delete oss objects failed: %s - %j", t.requestId, r, o), [];
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, i = 60) {
134
- var t;
135
- return (t = this.client) == null ? void 0 : t.signatureUrl(n, { expires: i });
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
- O as AliOssClient,
146
+ C as AliOssClient,
140
147
  $ as OSSRegion
141
148
  };
@@ -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 g=Object.defineProperty;var I=(r,c,h)=>c in r?g(r,c,{enumerable:!0,configurable:!0,writable:!0,value:h}):r[c]=h;var j=(r,c,h)=>(I(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))(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}};function x(u,d){return u.domain?u.domain:`https://${u.bucket}.${u.region}${d?"-internal":""}.aliyuncs.com`}class ${constructor(d,l,s,i,e=!0){j(this,"client");j(this,"region");j(this,"domain");this.region=d;const n=w[this.region]||w.hz,m=!!n.endpoint&&(n.forceCname??e);this.domain=x(n,i),this.client=new h({secure:!0,region:n.region,accessKeyId:l,accessKeySecret:s,bucket:n.bucket,internal:i,cname:m,endpoint:m?n.endpoint:void 0})}async putObjects(d,l,s={}){const i=l.map(async e=>{var o,a;let n=`${d}/${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 k.ReadStream?await((o=this.client)==null?void 0:o.putStream(n,e.stream)):await((a=this.client)==null?void 0:a.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 deleteObject(d,l={}){var i;let s=`${d}`.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(d,l,s={}){var f,p;let i=`${d}`.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(o=>`${i}${o}`.replaceAll(/\/\//g,"/").replace(/^\//,""));else{let o;try{do{const a=await((f=this.client)==null?void 0:f.list({prefix:i,marker:o,"max-keys":1e3})),b=(a==null?void 0:a.objects)||[];e.push(...b.map(q=>q.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,i,a),[]}}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 a=e.slice(o,o+n),b=await((p=this.client)==null?void 0:p.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,i,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"})});
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"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idm-plugin/aliclient2",
3
3
  "private": false,
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "description": "orm plugin for ali used in backend",
6
6
  "type": "module",
7
7
  "keywords": [