picgo-plugin-s3 1.5.0 → 1.5.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.
Files changed (3) hide show
  1. package/README.md +9 -4
  2. package/dist/utils.js +19 -13
  3. package/package.json +19 -21
package/README.md CHANGED
@@ -70,6 +70,11 @@ picgo set uploader s3
70
70
  | `{sha1}` | 图片 SHA1 |
71
71
  | `{sha256}` | 图片 SHA256 |
72
72
 
73
+ 对于 MD5、SHA1、SHA256,支持这几种截断方式:
74
+
75
+ - `{sha256:2}`:从第三个字符开始,例如 `abcd -> cd`
76
+ - `{sha256:2,4}`:从第三个字符开始,截取长度为4,例如 `abcdefgh`
77
+
73
78
  ---
74
79
 
75
80
  #### 自定义输出 URL 模板 (`outputURLPattern`)
@@ -83,9 +88,9 @@ picgo set uploader s3
83
88
  | `{protocol}` | URL 协议 | `http` 或 `https` |
84
89
  | `{host}` | URL 域名 | `s3.amazonaws.com` |
85
90
  | `{port}` | URL 端口 | `80` |
86
- | `{dir}` | 上传目录 | `my-bucket/2024/12` |
87
- | `{file}` | 上传后的文件名 (含扩展名) | `4aa4f41e38817e5fd38ac870f40dbc70.jpg` |
88
- | `{path}` | 完整路径 (`{dir}/{file}`) | `my-bucket/2024/12/4aa4f41e38817e5fd38ac870f40dbc70.jpg` |
91
+ | `{dir}` | 上传目录 | `xxx/2024/12` |
92
+ | `{uploadedFileName}` | 上传后的文件名 (含扩展名) | `4aa4f41e38817e5fd38ac870f40dbc70.jpg` |
93
+ | `{path}` | 完整路径 (`{dir}/{uploadedFileName}`) | `xxx/2024/12/4aa4f41e38817e5fd38ac870f40dbc70.jpg` |
89
94
  | `{fileName}` | **源**文件名 (含扩展名) | `test.jpg` |
90
95
  | `{extName}` | **源**文件扩展名 (不含 `.`) | `jpg` |
91
96
  | `{query}` | URL 查询参数 (不含 `?`) | `height=100&width=200` |
@@ -94,7 +99,7 @@ picgo set uploader s3
94
99
 
95
100
  ##### 正则替换
96
101
 
97
- 每个变量都支持通过正则表达式进行替换。
102
+ 每个变量都支持通过正则表达式进行替换(正则替换表达式中间不能有空格)。
98
103
 
99
104
  **语法:**
100
105
  ```
package/dist/utils.js CHANGED
@@ -67,7 +67,7 @@ class Generateor {
67
67
  }
68
68
  class FileNameGenerator extends Generateor {
69
69
  constructor(info) {
70
- super(info.date);
70
+ super(info.uploadDate);
71
71
  this.info = info;
72
72
  }
73
73
  fullName() {
@@ -130,18 +130,24 @@ class FileNameGenerator extends Generateor {
130
130
  sha256: () => this.sha256(),
131
131
  };
132
132
  return Object.entries(formatters).reduce((result, [key, formatter]) => {
133
- const simplePattern = new RegExp(`{${key}}`, 'g');
133
+ const rangePattern = new RegExp(`{${key}:(\\d+),(\\d+)}`, 'g');
134
134
  const truncatePattern = new RegExp(`{${key}:(\\d+)}`, 'g');
135
- if (truncatePattern.test(result)) {
136
- result = result.replace(truncatePattern, (match, length) => {
137
- const value = formatter();
138
- const truncateLength = parseInt(length, 10);
139
- return value.substring(0, truncateLength);
140
- });
141
- }
142
- else {
143
- result = result.replace(simplePattern, formatter());
144
- }
135
+ const simplePattern = new RegExp(`{${key}}`, 'g');
136
+ // Replace range patterns: {key:start,length}
137
+ result = result.replace(rangePattern, (match, start, length) => {
138
+ const value = formatter();
139
+ const startPos = parseInt(start, 10);
140
+ const subLength = parseInt(length, 10);
141
+ return value.substring(startPos, startPos + subLength);
142
+ });
143
+ // Replace truncate patterns: {key:length}
144
+ result = result.replace(truncatePattern, (match, length) => {
145
+ const value = formatter();
146
+ const truncateLength = parseInt(length, 10);
147
+ return value.substring(0, truncateLength);
148
+ });
149
+ // Replace simple patterns: {key}
150
+ result = result.replace(simplePattern, formatter());
145
151
  return result;
146
152
  }, super.format(s));
147
153
  }
@@ -149,7 +155,7 @@ class FileNameGenerator extends Generateor {
149
155
  exports.FileNameGenerator = FileNameGenerator;
150
156
  class OutputURLGenerator extends Generateor {
151
157
  constructor(config, info) {
152
- super(info.date);
158
+ super(info.uploadDate);
153
159
  this._config = config;
154
160
  this._info = info;
155
161
  // parse the url from storage
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "picgo-plugin-s3",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "picgo amazon s3 uploader",
5
5
  "main": "dist/index.js",
6
6
  "publishConfig": {
@@ -8,15 +8,9 @@
8
8
  },
9
9
  "type": "commonjs",
10
10
  "homepage": "https://github.com/wayjam/picgo-plugin-s3",
11
- "scripts": {
12
- "test": "echo \"Error: no test specified\" && exit 1",
13
- "build": "tsc -p .",
14
- "dev": "tsc -w -p .",
15
- "pub": "rm -rf dist/* && npm build && npm publish",
16
- "push": "git push origin main && git push origin --tags",
17
- "patch": "npm version patch -m 'bump version into v%s'",
18
- "minor": "npm version minor -m 'bump version into v%s'",
19
- "major": "npm version major -m 'bump version into v%s'"
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/wayjam/picgo-plugin-s3.git"
20
14
  },
21
15
  "keywords": [
22
16
  "amazon-s3",
@@ -29,16 +23,18 @@
29
23
  "author": "WayJam So",
30
24
  "license": "MIT",
31
25
  "devDependencies": {
32
- "@types/mime": "^3.0.4",
33
26
  "@eslint/js": "^9.16.0",
27
+ "@types/mime": "^3.0.4",
34
28
  "@types/node": "^22.10.1",
35
29
  "@typescript-eslint/eslint-plugin": "^8.17.0",
36
30
  "@typescript-eslint/parser": "^8.17.0",
31
+ "@vitest/ui": "^4.0.18",
37
32
  "eslint": "^9.16.0",
38
33
  "eslint-config-prettier": "^9.1.0",
39
34
  "eslint-plugin-prettier": "^5.2.1",
40
35
  "prettier": "^3.4.2",
41
- "typescript": "^5.7.2"
36
+ "typescript": "^5.7.2",
37
+ "vitest": "^4.0.18"
42
38
  },
43
39
  "dependencies": {
44
40
  "@aws-sdk/client-s3": "~3.729.0",
@@ -50,13 +46,15 @@
50
46
  "mime": ">=3.0.0 <4.0.0",
51
47
  "picgo": "^1.5.8"
52
48
  },
53
- "pnpm": {
54
- "overrides": {
55
- "got@<11.8.5": ">=11.8.5",
56
- "ejs@<3.1.7": ">=3.1.7",
57
- "http-cache-semantics@<4.1.1": ">=4.1.1",
58
- "axios@>=0.8.1 <0.28.0": ">=0.28.0",
59
- "ejs@<3.1.10": ">=3.1.10"
60
- }
49
+ "scripts": {
50
+ "test": "vitest run",
51
+ "test:watch": "vitest",
52
+ "build": "tsc -p .",
53
+ "dev": "tsc -w -p .",
54
+ "pub": "rm -rf dist/* && npm build && npm publish",
55
+ "push": "git push origin main && git push origin --tags",
56
+ "patch": "npm version patch -m 'bump version into v%s'",
57
+ "minor": "npm version minor -m 'bump version into v%s'",
58
+ "major": "npm version major -m 'bump version into v%s'"
61
59
  }
62
- }
60
+ }