picgo-plugin-s3 1.2.2 → 1.2.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.
package/.eslintrc CHANGED
@@ -5,7 +5,10 @@
5
5
  "plugin:@typescript-eslint/recommended",
6
6
  "prettier"
7
7
  ],
8
- "plugins": ["prettier", "@typescript-eslint"],
8
+ "plugins": [
9
+ "prettier",
10
+ "@typescript-eslint"
11
+ ],
9
12
  "env": {
10
13
  "es6": true,
11
14
  "node": true
package/README.md CHANGED
@@ -27,6 +27,7 @@ picgo set uploader aws-s3
27
27
  | `uploadPath` | 上传路径 | `{year}/{month}/{fullName}` |
28
28
  | `urlPrefix` | 最终生成图片 URL 的自定义前缀 | `https://img.example.com/my-blog/` |
29
29
  | `endpoint` | 指定自定义终端节点 | `s3.us-west-2.amazonaws.com` |
30
+ | `proxy` | 代理地址 | 支持http代理,例如 `http://127.0.0.1:1080` |
30
31
  | `region` | 指定执行服务请求的区域 | `us-west-1` |
31
32
  | `pathStyleAccess` | 是否启用 S3 Path style | 默认为 `false`,使用 minio 请设置为 `true` |
32
33
  | `rejectUnauthorized` | 是否拒绝无效 TLS 证书连接 | 默认为 `true`,如上传失败日志显示证书问题可设置为`false` |
package/dist/config.d.ts CHANGED
@@ -5,6 +5,7 @@ export interface IS3UserConfig {
5
5
  uploadPath: string;
6
6
  region?: string;
7
7
  endpoint?: string;
8
+ proxy?: string;
8
9
  urlPrefix?: string;
9
10
  pathStyleAccess?: boolean;
10
11
  rejectUnauthorized?: boolean;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import picgo from "picgo";
2
- declare const _default: (ctx: picgo) => {
1
+ import { PicGo } from "picgo";
2
+ declare const _default: (ctx: PicGo) => {
3
3
  register: () => void;
4
4
  };
5
5
  export = _default;
package/dist/index.js CHANGED
@@ -63,6 +63,14 @@ module.exports = (ctx) => {
63
63
  required: false,
64
64
  alias: "自定义节点",
65
65
  },
66
+ {
67
+ name: "proxy",
68
+ type: "input",
69
+ default: userConfig.proxy,
70
+ required: false,
71
+ alias: "代理",
72
+ message: "http://127.0.0.1:1080",
73
+ },
66
74
  {
67
75
  name: "urlPrefix",
68
76
  type: "input",
@@ -1,5 +1,5 @@
1
1
  import { S3 } from "aws-sdk";
2
- import { IImgInfo } from "picgo/dist/src/types";
2
+ import { IImgInfo } from "picgo";
3
3
  import { IS3UserConfig } from "./config";
4
4
  export interface IUploadResult {
5
5
  url: string;
package/dist/uploader.js CHANGED
@@ -15,7 +15,6 @@ function createS3Client(opts) {
15
15
  catch (_a) {
16
16
  // eslint-disable-next-line no-empty
17
17
  }
18
- const http = sslEnabled ? require("https") : require("http");
19
18
  const s3 = new aws_sdk_1.S3({
20
19
  region: opts.region,
21
20
  endpoint: opts.endpoint,
@@ -25,9 +24,7 @@ function createS3Client(opts) {
25
24
  s3BucketEndpoint: opts.bucketEndpoint,
26
25
  sslEnabled: sslEnabled,
27
26
  httpOptions: {
28
- agent: new http.Agent({
29
- rejectUnauthorized: opts.rejectUnauthorized,
30
- }),
27
+ agent: (0, utils_1.getProxyAgent)(opts.proxy, sslEnabled, opts.rejectUnauthorized),
31
28
  },
32
29
  });
33
30
  return s3;
package/dist/utils.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  /// <reference types="node" />
2
- import { IImgInfo } from "picgo/dist/src/types";
2
+ import { IImgInfo } from "picgo";
3
+ import { HttpsProxyAgent, HttpProxyAgent } from "hpagent";
3
4
  export declare function formatPath(info: IImgInfo, format?: string): string;
4
5
  export declare function extractInfo(info: IImgInfo): Promise<{
5
6
  body?: Buffer;
6
7
  contentType?: string;
7
8
  contentEncoding?: string;
8
9
  }>;
10
+ export declare function getProxyAgent(proxy: string | undefined, sslEnabled: boolean, rejectUnauthorized: boolean): HttpProxyAgent | HttpsProxyAgent | undefined;
package/dist/utils.js CHANGED
@@ -3,10 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.extractInfo = exports.formatPath = void 0;
6
+ exports.getProxyAgent = exports.extractInfo = exports.formatPath = void 0;
7
7
  const crypto_1 = __importDefault(require("crypto"));
8
8
  const file_type_1 = __importDefault(require("file-type"));
9
9
  const mime_1 = __importDefault(require("mime"));
10
+ const hpagent_1 = require("hpagent");
10
11
  class FileNameGenerator {
11
12
  constructor(info) {
12
13
  this.date = new Date();
@@ -37,6 +38,24 @@ class FileNameGenerator {
37
38
  md5() {
38
39
  return crypto_1.default.createHash("md5").update(this.imgBuffer()).digest("hex");
39
40
  }
41
+ md5B64() {
42
+ return crypto_1.default
43
+ .createHash("md5")
44
+ .update(this.imgBuffer())
45
+ .digest("base64")
46
+ .replace(/\+/g, "-")
47
+ .replace(/\//g, "_")
48
+ .replace(/=+$/, "");
49
+ }
50
+ md5B64Short() {
51
+ return crypto_1.default
52
+ .createHash("md5")
53
+ .update(this.imgBuffer())
54
+ .digest("base64")
55
+ .replace(/\+/g, "-")
56
+ .replace(/\//g, "_")
57
+ .slice(0, 7);
58
+ }
40
59
  sha1() {
41
60
  return crypto_1.default.createHash("sha1").update(this.imgBuffer()).digest("hex");
42
61
  }
@@ -55,6 +74,8 @@ FileNameGenerator.fields = [
55
74
  "fileName",
56
75
  "extName",
57
76
  "md5",
77
+ "md5B64",
78
+ "md5B64Short",
58
79
  "sha1",
59
80
  "sha256",
60
81
  ];
@@ -94,3 +115,34 @@ async function extractInfo(info) {
94
115
  return result;
95
116
  }
96
117
  exports.extractInfo = extractInfo;
118
+ function formatHttpProxyURL(url = "") {
119
+ if (!url)
120
+ return "";
121
+ if (!/^https?:\/\//.test(url)) {
122
+ const [host, port] = url.split(":");
123
+ return `http://${host.replace("127.0.0.1", "localhost")}:${port}`;
124
+ }
125
+ try {
126
+ const { protocol, hostname, port } = new URL(url);
127
+ return `${protocol}//${hostname.replace("127.0.0.1", "localhost")}:${port}`;
128
+ }
129
+ catch (e) {
130
+ return "";
131
+ }
132
+ }
133
+ function getProxyAgent(proxy, sslEnabled, rejectUnauthorized) {
134
+ const formatedProxy = formatHttpProxyURL(proxy);
135
+ if (!formatedProxy) {
136
+ return undefined;
137
+ }
138
+ const Agent = sslEnabled ? hpagent_1.HttpsProxyAgent : hpagent_1.HttpProxyAgent;
139
+ const options = {
140
+ keepAlive: true,
141
+ keepAliveMsecs: 1000,
142
+ scheduling: "lifo",
143
+ rejectUnauthorized,
144
+ proxy: formatedProxy,
145
+ };
146
+ return new Agent(options);
147
+ }
148
+ exports.getProxyAgent = getProxyAgent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "picgo-plugin-s3",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "picgo amazon s3 uploader",
5
5
  "main": "dist/index.js",
6
6
  "publishConfig": {
@@ -27,19 +27,21 @@
27
27
  "author": "WayJam So",
28
28
  "license": "MIT",
29
29
  "devDependencies": {
30
+ "@types/mime": "^3.0.1",
30
31
  "@types/node": "^18.7.23",
31
32
  "@typescript-eslint/eslint-plugin": "^5.38.1",
32
33
  "@typescript-eslint/parser": "^5.38.1",
33
34
  "eslint": "^8.25.0",
34
35
  "eslint-config-prettier": "^8.5.0",
35
36
  "eslint-plugin-prettier": "^4.2.1",
36
- "picgo": "^1.4.0 >1.4.16",
37
+ "picgo": "^1.5.0",
37
38
  "prettier": "^2.7.1",
38
39
  "typescript": "^4.8.4"
39
40
  },
40
41
  "dependencies": {
41
42
  "aws-sdk": "^2.839.0",
42
43
  "file-type": "^16.2.0",
44
+ "hpagent": "^1.2.0",
43
45
  "mime": "^2.5.2"
44
46
  }
45
47
  }