@idm-plugin/aliclient2 0.0.8 → 0.1.0
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/index.js +16 -16
- package/dist/index.umd.cjs +1 -1
- package/package.json +6 -4
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
var j = Object.defineProperty;
|
|
2
|
-
var w = (
|
|
3
|
-
var p = (
|
|
2
|
+
var w = (l, c, i) => c in l ? j(l, c, { enumerable: !0, configurable: !0, writable: !0, value: i }) : l[c] = i;
|
|
3
|
+
var p = (l, c, i) => (w(l, typeof c != "symbol" ? c + "" : c, i), i);
|
|
4
4
|
import x from "@log4js-node/log4js-api";
|
|
5
5
|
import f from "ali-oss";
|
|
6
|
-
import { ReadStream as
|
|
6
|
+
import { ReadStream as k } from "fs";
|
|
7
7
|
let s;
|
|
8
8
|
try {
|
|
9
9
|
s = x.getLogger("ali-client");
|
|
10
10
|
} catch {
|
|
11
11
|
} finally {
|
|
12
12
|
}
|
|
13
|
-
class
|
|
13
|
+
class I {
|
|
14
14
|
/**
|
|
15
15
|
* 创建阿里云OSS客户端
|
|
16
16
|
* @param region enum [tk, hz]
|
|
@@ -30,7 +30,7 @@ class A {
|
|
|
30
30
|
bucket: "idm-wx",
|
|
31
31
|
internal: r,
|
|
32
32
|
cname: t,
|
|
33
|
-
endpoint: t ? "https://
|
|
33
|
+
endpoint: t ? "https://osstk.ormwx.com" : void 0
|
|
34
34
|
}) : this.client = new f({
|
|
35
35
|
secure: !0,
|
|
36
36
|
region: "oss-cn-hangzhou",
|
|
@@ -44,11 +44,11 @@ class A {
|
|
|
44
44
|
}
|
|
45
45
|
async putObjects(c, i, e = {}) {
|
|
46
46
|
const r = i.map(async (t) => {
|
|
47
|
-
var n,
|
|
47
|
+
var n, o;
|
|
48
48
|
let a = `${c}/${t.name}`.replaceAll(/\/\//g, "/");
|
|
49
49
|
a = a.startsWith("/") ? a.substring(1) : a;
|
|
50
|
-
const u = this.region === "tk" ? `https://
|
|
51
|
-
return t.stream instanceof
|
|
50
|
+
const u = this.region === "tk" ? `https://osstk.ormwx.com/${a}` : `https://ossimg.ormwx.com/${a}`, h = this.region === "tk" ? `https://osstk.ormwx.com/${a}` : `https://ossimg.ormwx.com/${a}`, m = e.headers || {};
|
|
51
|
+
return t.stream instanceof k ? await ((n = this.client) == null ? void 0 : n.putStream(a, t.stream)) : await ((o = this.client) == null ? void 0 : o.put(a, t.stream, { headers: m })), { url: u, name: t.name, aliSign: !0, external: h };
|
|
52
52
|
});
|
|
53
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), []));
|
|
54
54
|
}
|
|
@@ -75,7 +75,7 @@ class A {
|
|
|
75
75
|
* @param options
|
|
76
76
|
*/
|
|
77
77
|
async deleteObjects(c, i, e = {}) {
|
|
78
|
-
var h,
|
|
78
|
+
var h, m;
|
|
79
79
|
let r = `${c}`.replaceAll(/\/\//g, "/");
|
|
80
80
|
r = r.startsWith("/") ? r.substring(1) : r, r && !r.endsWith("/") && (r += "/");
|
|
81
81
|
let t = [];
|
|
@@ -85,11 +85,11 @@ class A {
|
|
|
85
85
|
let n;
|
|
86
86
|
try {
|
|
87
87
|
do {
|
|
88
|
-
const
|
|
89
|
-
t.push(...
|
|
88
|
+
const o = await ((h = this.client) == null ? void 0 : h.list({ prefix: r, marker: n, "max-keys": 1e3 })), d = (o == null ? void 0 : o.objects) || [];
|
|
89
|
+
t.push(...d.map((b) => b.name)), n = o == null ? void 0 : o.nextMarker;
|
|
90
90
|
} while (n);
|
|
91
|
-
} catch (
|
|
92
|
-
return s == null || s.error("[%s] list oss objects failed: %s - %j", e.requestId, r,
|
|
91
|
+
} catch (o) {
|
|
92
|
+
return s == null || s.error("[%s] list oss objects failed: %s - %j", e.requestId, r, o), [];
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
if (t.length === 0)
|
|
@@ -97,8 +97,8 @@ class A {
|
|
|
97
97
|
const a = 1e3, u = [];
|
|
98
98
|
try {
|
|
99
99
|
for (let n = 0; n < t.length; n += a) {
|
|
100
|
-
const
|
|
101
|
-
u.push(
|
|
100
|
+
const o = t.slice(n, n + a), d = await ((m = this.client) == null ? void 0 : m.deleteMulti(o, { quiet: !0 }));
|
|
101
|
+
u.push(d);
|
|
102
102
|
}
|
|
103
103
|
return s == null || s.info("[%s] delete oss objects success, count: %d", e.requestId, t.length), u;
|
|
104
104
|
} catch (n) {
|
|
@@ -116,5 +116,5 @@ class A {
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
export {
|
|
119
|
-
|
|
119
|
+
I as AliOssClient
|
|
120
120
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -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
|
|
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 k=(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)=>(k(r,typeof c!="symbol"?c+"":c,d),d);let s;try{s=c.getLogger("ali-client")}catch{}finally{}class w{constructor(u,o,t,i,e=!0){j(this,"client");j(this,"region");this.region=u,u==="tk"?this.client=new d({secure:!0,region:"oss-ap-northeast-1",accessKeyId:o,accessKeySecret:t,bucket:"idm-wx",internal:i,cname:e,endpoint:e?"https://osstk.ormwx.com":void 0}):this.client=new d({secure:!0,region:"oss-cn-hangzhou",accessKeyId:o,accessKeySecret:t,bucket:"idm-hz",internal:i,cname:!0,endpoint:"https://ossimg.ormwx.com"})}async putObjects(u,o,t={}){const i=o.map(async e=>{var n,a;let l=`${u}/${e.name}`.replaceAll(/\/\//g,"/");l=l.startsWith("/")?l.substring(1):l;const h=this.region==="tk"?`https://osstk.ormwx.com/${l}`:`https://ossimg.ormwx.com/${l}`,f=this.region==="tk"?`https://osstk.ormwx.com/${l}`:`https://ossimg.ormwx.com/${l}`,m=t.headers||{};return e.stream instanceof b.ReadStream?await((n=this.client)==null?void 0:n.putStream(l,e.stream)):await((a=this.client)==null?void 0:a.put(l,e.stream,{headers:m})),{url:h,name:e.name,aliSign:!0,external:f}});return await Promise.all(i).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),[]))}async deleteObject(u,o={}){var i;let t=`${u}`.replaceAll(/\/\//g,"/");t=t.startsWith("/")?t.substring(1):t;try{const e=await((i=this.client)==null?void 0:i.delete(t));return s==null||s.info("[%s] delete oss object success: %s",o.requestId,t),e}catch(e){return s==null||s.error("[%s] delete oss object failed: %s - %j",o.requestId,t,e),null}}async deleteObjects(u,o,t={}){var f,m;let i=`${u}`.replaceAll(/\/\//g,"/");i=i.startsWith("/")?i.substring(1):i,i&&!i.endsWith("/")&&(i+="/");let e=[];if(Array.isArray(o)&&o.length>0)e=o.map(n=>`${i}${n}`.replaceAll(/\/\//g,"/").replace(/^\//,""));else{let n;try{do{const a=await((f=this.client)==null?void 0:f.list({prefix:i,marker:n,"max-keys":1e3})),p=(a==null?void 0:a.objects)||[];e.push(...p.map(x=>x.name)),n=a==null?void 0:a.nextMarker}while(n)}catch(a){return s==null||s.error("[%s] list oss objects failed: %s - %j",t.requestId,i,a),[]}}if(e.length===0)return s==null||s.info("[%s] no objects to delete for prefix: %s",t.requestId,i),[];const l=1e3,h=[];try{for(let n=0;n<e.length;n+=l){const a=e.slice(n,n+l),p=await((m=this.client)==null?void 0:m.deleteMulti(a,{quiet:!0}));h.push(p)}return s==null||s.info("[%s] delete oss objects success, count: %d",t.requestId,e.length),h}catch(n){return s==null||s.error("[%s] delete oss objects failed: %s - %j",t.requestId,i,n),[]}}async signature(u,o=60){var t;return(t=this.client)==null?void 0:t.signatureUrl(u,{expires:o})}}r.AliOssClient=w,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idm-plugin/aliclient2",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "orm plugin for ali used in backend",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"idm",
|
|
9
|
-
"ali"
|
|
9
|
+
"ali",
|
|
10
|
+
"orm",
|
|
11
|
+
"backend"
|
|
10
12
|
],
|
|
11
|
-
"author": "chenheng@
|
|
13
|
+
"author": "chenheng@ormwx.com",
|
|
12
14
|
"contributors": [
|
|
13
15
|
"ChenHeng"
|
|
14
16
|
],
|