@idm-plugin/aliclient2 0.0.1 → 0.0.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.
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  /// <reference types="node" />
4
+ import OSS from 'ali-oss';
4
5
  import { ReadStream } from 'fs';
5
6
  /**
6
7
  * 阿里云OSS客户端, 限NODE环境中使用
@@ -25,6 +26,19 @@ export declare class AliOssClient {
25
26
  aliSign: boolean;
26
27
  external: string;
27
28
  }[] | never[]>;
29
+ /**
30
+ * 删除对象
31
+ * @param filePath
32
+ * @param options
33
+ */
34
+ deleteObject(filePath: string, options?: any): Promise<OSS.DeleteResult | null | undefined>;
35
+ /**
36
+ * 删除目录下所有对象或按names列表删除
37
+ * @param directory
38
+ * @param names
39
+ * @param options
40
+ */
41
+ deleteObjects(directory: string, names?: string[], options?: any): Promise<any[]>;
28
42
  /**
29
43
  * 签名
30
44
  * @param url 待签名的url
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
- var g = Object.defineProperty;
2
- var d = (n, t, e) => t in n ? g(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
- var a = (n, t, e) => (d(n, typeof t != "symbol" ? t + "" : t, e), e);
4
- import w from "@log4js-node/log4js-api";
5
- import u from "ali-oss";
6
- import { ReadStream as f } from "fs";
7
- let m;
1
+ var j = Object.defineProperty;
2
+ var w = (o, c, i) => c in o ? j(o, c, { enumerable: !0, configurable: !0, writable: !0, value: i }) : o[c] = i;
3
+ var p = (o, c, i) => (w(o, typeof c != "symbol" ? c + "" : c, i), i);
4
+ import x from "@log4js-node/log4js-api";
5
+ import f from "ali-oss";
6
+ import { ReadStream as y } from "fs";
7
+ let s;
8
8
  try {
9
- m = w.getLogger("ali-client");
9
+ s = x.getLogger("ali-client");
10
10
  } catch {
11
11
  } finally {
12
12
  }
13
- class b {
13
+ class I {
14
14
  /**
15
15
  * 创建阿里云OSS客户端
16
16
  * @param region enum [tk, hz]
@@ -18,49 +18,102 @@ class b {
18
18
  * @param accessKeySecret
19
19
  * @param internal boolean true 内网访问
20
20
  */
21
- constructor(t, e, r, o) {
22
- a(this, "client");
23
- a(this, "region");
24
- this.region = t, t === "tk" ? this.client = new u({
21
+ constructor(c, i, t, r) {
22
+ p(this, "client");
23
+ p(this, "region");
24
+ this.region = c, c === "tk" ? this.client = new f({
25
25
  secure: !0,
26
26
  region: "oss-ap-northeast-1",
27
- accessKeyId: e,
28
- accessKeySecret: r,
27
+ accessKeyId: i,
28
+ accessKeySecret: t,
29
29
  bucket: "idm-wx",
30
- internal: o,
30
+ internal: r,
31
31
  cname: !0,
32
32
  endpoint: "https://img.idmwx.com"
33
- }) : this.client = new u({
33
+ }) : this.client = new f({
34
34
  secure: !0,
35
35
  region: "oss-cn-hangzhou",
36
- accessKeyId: e,
37
- accessKeySecret: r,
36
+ accessKeyId: i,
37
+ accessKeySecret: t,
38
38
  bucket: "idm-hz",
39
- internal: o,
39
+ internal: r,
40
40
  cname: !0,
41
41
  endpoint: "https://osshz.idmwx.com"
42
42
  });
43
43
  }
44
- async putObjects(t, e, r = {}) {
45
- const o = e.map(async (s) => {
46
- var c, l;
47
- let i = `${t}/${s.name}`.replaceAll(/\/\//g, "/");
48
- i = i.startsWith("/") ? i.substring(1) : i;
49
- const h = this.region === "tk" ? `https://oss.idmwx.com/${i}` : `https://osshz.idmwx.com/${i}`, p = this.region === "tk" ? `https://img.idmwx.com/${i}` : `https://osshz.idmwx.com/${i}`;
50
- return s.stream instanceof f ? await ((c = this.client) == null ? void 0 : c.putStream(i, s.stream)) : await ((l = this.client) == null ? void 0 : l.put(i, s.stream)), { url: h, name: s.name, aliSign: !0, external: p };
44
+ async putObjects(c, i, t = {}) {
45
+ const r = i.map(async (e) => {
46
+ var u, n;
47
+ let a = `${c}/${e.name}`.replaceAll(/\/\//g, "/");
48
+ a = a.startsWith("/") ? a.substring(1) : a;
49
+ 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
51
  });
52
- return await Promise.all(o).then((s) => (m.info("[%s] upload to oss success, url: %j", r.requestId, s), s)).catch((s) => (m.error("[%s] upload to oss failed: %j-%s", r.requestId, s), []));
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
+ }
54
+ /**
55
+ * 删除对象
56
+ * @param filePath
57
+ * @param options
58
+ */
59
+ async deleteObject(c, i = {}) {
60
+ var r;
61
+ let t = `${c}`.replaceAll(/\/\//g, "/");
62
+ t = t.startsWith("/") ? t.substring(1) : t;
63
+ 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;
68
+ }
69
+ }
70
+ /**
71
+ * 删除目录下所有对象或按names列表删除
72
+ * @param directory
73
+ * @param names
74
+ * @param options
75
+ */
76
+ async deleteObjects(c, i, t = {}) {
77
+ var d, u;
78
+ let r = `${c}`.replaceAll(/\/\//g, "/");
79
+ r = r.startsWith("/") ? r.substring(1) : r, r && !r.endsWith("/") && (r += "/");
80
+ let e = [];
81
+ if (Array.isArray(i) && i.length > 0)
82
+ e = i.map((n) => `${r}${n}`.replaceAll(/\/\//g, "/").replace(/^\//, ""));
83
+ else {
84
+ let n;
85
+ try {
86
+ 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;
89
+ } while (n);
90
+ } catch (l) {
91
+ return s == null || s.error("[%s] list oss objects failed: %s - %j", t.requestId, r, l), [];
92
+ }
93
+ }
94
+ if (e.length === 0)
95
+ return s == null || s.info("[%s] no objects to delete for prefix: %s", t.requestId, r), [];
96
+ const a = 1e3, h = [];
97
+ 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 }));
100
+ h.push(m);
101
+ }
102
+ return s == null || s.info("[%s] delete oss objects success, count: %d", t.requestId, e.length), h;
103
+ } catch (n) {
104
+ return s == null || s.error("[%s] delete oss objects failed: %s - %j", t.requestId, r, n), [];
105
+ }
53
106
  }
54
107
  /**
55
108
  * 签名
56
109
  * @param url 待签名的url
57
110
  * @param expires 过期时间,单位秒
58
111
  */
59
- async signature(t, e = 60) {
60
- var r;
61
- return (r = this.client) == null ? void 0 : r.signatureUrl(t, { expires: e });
112
+ async signature(c, i = 60) {
113
+ var t;
114
+ return (t = this.client) == null ? void 0 : t.signatureUrl(c, { expires: i });
62
115
  }
63
116
  }
64
117
  export {
65
- b as AliOssClient
118
+ I as AliOssClient
66
119
  };
@@ -1 +1 @@
1
- (function(e,t){typeof exports=="object"&&typeof module<"u"?t(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"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e["idm-plugin-aliclient"]={},e["@log4js-node/log4js-api"],e.OSS,e.fs))})(this,function(e,t,n,h){"use strict";var j=Object.defineProperty;var x=(e,t,n)=>t in e?j(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var c=(e,t,n)=>(x(e,typeof t!="symbol"?t+"":t,n),n);let a;try{a=t.getLogger("ali-client")}catch{}finally{}class p{constructor(o,l,r,u){c(this,"client");c(this,"region");this.region=o,o==="tk"?this.client=new n({secure:!0,region:"oss-ap-northeast-1",accessKeyId:l,accessKeySecret:r,bucket:"idm-wx",internal:u,cname:!0,endpoint:"https://img.idmwx.com"}):this.client=new n({secure:!0,region:"oss-cn-hangzhou",accessKeyId:l,accessKeySecret:r,bucket:"idm-hz",internal:u,cname:!0,endpoint:"https://osshz.idmwx.com"})}async putObjects(o,l,r={}){const u=l.map(async s=>{var m,d;let i=`${o}/${s.name}`.replaceAll(/\/\//g,"/");i=i.startsWith("/")?i.substring(1):i;const f=this.region==="tk"?`https://oss.idmwx.com/${i}`:`https://osshz.idmwx.com/${i}`,w=this.region==="tk"?`https://img.idmwx.com/${i}`:`https://osshz.idmwx.com/${i}`;return s.stream instanceof h.ReadStream?await((m=this.client)==null?void 0:m.putStream(i,s.stream)):await((d=this.client)==null?void 0:d.put(i,s.stream)),{url:f,name:s.name,aliSign:!0,external:w}});return await Promise.all(u).then(s=>(a.info("[%s] upload to oss success, url: %j",r.requestId,s),s)).catch(s=>(a.error("[%s] upload to oss failed: %j-%s",r.requestId,s),[]))}async signature(o,l=60){var r;return(r=this.client)==null?void 0:r.signatureUrl(o,{expires:l})}}e.AliOssClient=p,Object.defineProperty(e,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 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"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idm-plugin/aliclient2",
3
3
  "private": false,
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "description": "idm plugin for ali used in backend",
6
6
  "type": "module",
7
7
  "keywords": [