@idm-plugin/aliclient2 0.0.1
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/README.md +2 -0
- package/dist/alioss/src/index.d.ts +1 -0
- package/dist/alioss/src/oss.d.ts +34 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +66 -0
- package/dist/index.umd.cjs +1 -0
- package/package.json +67 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './oss';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import { ReadStream } from 'fs';
|
|
5
|
+
/**
|
|
6
|
+
* 阿里云OSS客户端, 限NODE环境中使用
|
|
7
|
+
*/
|
|
8
|
+
export declare class AliOssClient {
|
|
9
|
+
private client;
|
|
10
|
+
private readonly region;
|
|
11
|
+
/**
|
|
12
|
+
* 创建阿里云OSS客户端
|
|
13
|
+
* @param region enum [tk, hz]
|
|
14
|
+
* @param accessKeyId
|
|
15
|
+
* @param accessKeySecret
|
|
16
|
+
* @param internal boolean true 内网访问
|
|
17
|
+
*/
|
|
18
|
+
constructor(region: string, accessKeyId: string, accessKeySecret: string, internal: boolean);
|
|
19
|
+
putObjects(directory: string, streams: {
|
|
20
|
+
name: string;
|
|
21
|
+
stream: ReadStream | Buffer;
|
|
22
|
+
}[], options?: any): Promise<{
|
|
23
|
+
url: string;
|
|
24
|
+
name: string;
|
|
25
|
+
aliSign: boolean;
|
|
26
|
+
external: string;
|
|
27
|
+
}[] | never[]>;
|
|
28
|
+
/**
|
|
29
|
+
* 签名
|
|
30
|
+
* @param url 待签名的url
|
|
31
|
+
* @param expires 过期时间,单位秒
|
|
32
|
+
*/
|
|
33
|
+
signature(url: string, expires?: number): Promise<string | undefined>;
|
|
34
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './alioss/src';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
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;
|
|
8
|
+
try {
|
|
9
|
+
m = w.getLogger("ali-client");
|
|
10
|
+
} catch {
|
|
11
|
+
} finally {
|
|
12
|
+
}
|
|
13
|
+
class b {
|
|
14
|
+
/**
|
|
15
|
+
* 创建阿里云OSS客户端
|
|
16
|
+
* @param region enum [tk, hz]
|
|
17
|
+
* @param accessKeyId
|
|
18
|
+
* @param accessKeySecret
|
|
19
|
+
* @param internal boolean true 内网访问
|
|
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({
|
|
25
|
+
secure: !0,
|
|
26
|
+
region: "oss-ap-northeast-1",
|
|
27
|
+
accessKeyId: e,
|
|
28
|
+
accessKeySecret: r,
|
|
29
|
+
bucket: "idm-wx",
|
|
30
|
+
internal: o,
|
|
31
|
+
cname: !0,
|
|
32
|
+
endpoint: "https://img.idmwx.com"
|
|
33
|
+
}) : this.client = new u({
|
|
34
|
+
secure: !0,
|
|
35
|
+
region: "oss-cn-hangzhou",
|
|
36
|
+
accessKeyId: e,
|
|
37
|
+
accessKeySecret: r,
|
|
38
|
+
bucket: "idm-hz",
|
|
39
|
+
internal: o,
|
|
40
|
+
cname: !0,
|
|
41
|
+
endpoint: "https://osshz.idmwx.com"
|
|
42
|
+
});
|
|
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 };
|
|
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), []));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 签名
|
|
56
|
+
* @param url 待签名的url
|
|
57
|
+
* @param expires 过期时间,单位秒
|
|
58
|
+
*/
|
|
59
|
+
async signature(t, e = 60) {
|
|
60
|
+
var r;
|
|
61
|
+
return (r = this.client) == null ? void 0 : r.signatureUrl(t, { expires: e });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
b as AliOssClient
|
|
66
|
+
};
|
|
@@ -0,0 +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"})});
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@idm-plugin/aliclient2",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "idm plugin for ali used in backend",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"idm",
|
|
9
|
+
"ali"
|
|
10
|
+
],
|
|
11
|
+
"author": "chenheng@idmwx.com",
|
|
12
|
+
"contributors": [
|
|
13
|
+
"ChenHeng"
|
|
14
|
+
],
|
|
15
|
+
"license": "GPL-3.0",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"main": "./dist/index.umd.cjs",
|
|
20
|
+
"module": "./dist/index.js",
|
|
21
|
+
"types": "index.d.ts",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"dev": "vite --config ./build/base.config.ts",
|
|
24
|
+
"build": "vite build --config ./build/lib.config.ts",
|
|
25
|
+
"lint:fix": "eslint --fix --ext .js,.ts,.",
|
|
26
|
+
"prettier": "yarn lint:fix && prettier --write '**/*.{js,ts}'",
|
|
27
|
+
"release": "yarn build && yarn publish --access public"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@log4js-node/log4js-api": "^1.0.2",
|
|
31
|
+
"ali-oss": "^6.23.0",
|
|
32
|
+
"axios": "^1.9.0",
|
|
33
|
+
"moment": "^2.30.1"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/ali-oss": "^6.16.13",
|
|
37
|
+
"@types/jest": "^25.2.2",
|
|
38
|
+
"@types/node": "^18.14.2",
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
|
40
|
+
"@typescript-eslint/parser": "^5.53.0",
|
|
41
|
+
"@vitejs/plugin-vue": "^4.2.3",
|
|
42
|
+
"eslint": "^8.35.0",
|
|
43
|
+
"eslint-config-prettier": "^8.6.0",
|
|
44
|
+
"eslint-define-config": "^1.15.0",
|
|
45
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
46
|
+
"jest": "^26.6.3",
|
|
47
|
+
"lint-staged": "^13.1.2",
|
|
48
|
+
"prettier": "^2.8.4",
|
|
49
|
+
"simple-git-hooks": "^2.8.1",
|
|
50
|
+
"stylelint": "^15.2.0",
|
|
51
|
+
"supertest": "^4.0.2",
|
|
52
|
+
"ts-jest": "^26.5.3",
|
|
53
|
+
"ts-node-dev": "^2.0.0-0",
|
|
54
|
+
"tsconfig-paths": "^3.12.0",
|
|
55
|
+
"typescript": "^4.9.3",
|
|
56
|
+
"vite": "^4.1.0",
|
|
57
|
+
"vite-plugin-dts": "^2.0.2",
|
|
58
|
+
"vite-plugin-static-copy": "^0.17.0"
|
|
59
|
+
},
|
|
60
|
+
"lint-staged": {
|
|
61
|
+
"*.{ts,tsx,js}": "eslint --fix",
|
|
62
|
+
"*.{ts,tsx,js,scss}": "prettier --write"
|
|
63
|
+
},
|
|
64
|
+
"simple-git-hooks": {
|
|
65
|
+
"pre-commit": "npx lint-staged"
|
|
66
|
+
}
|
|
67
|
+
}
|