@maiyunnet/kebab 7.3.0 → 7.3.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 +4 -2
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/s3.d.ts +6 -1
- package/lib/s3.js +16 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
<p align="center"><img src="./doc/icon.png" width="64" height="64" alt="Kebab"></p>
|
|
2
2
|
<p align="center">
|
|
3
|
-
<a href="https://github.com/maiyun/kebab/blob/
|
|
3
|
+
<a href="https://github.com/maiyun/kebab/blob/main/LICENSE">
|
|
4
4
|
<img alt="License" src="https://img.shields.io/github/license/maiyun/kebab?color=blue" />
|
|
5
5
|
</a>
|
|
6
|
+
<a href="https://www.npmjs.com/package/@maiyunnet/kebab">
|
|
7
|
+
<img alt="NPM stable version" src="https://img.shields.io/npm/v/@maiyunnet/kebab?color=brightgreen&logo=npm" />
|
|
8
|
+
</a>
|
|
6
9
|
<a href="https://github.com/maiyun/kebab/releases">
|
|
7
10
|
<img alt="GitHub releases" src="https://img.shields.io/github/v/release/maiyun/kebab?color=brightgreen&logo=github" />
|
|
8
|
-
<img alt="GitHub pre-releases" src="https://img.shields.io/github/v/release/maiyun/kebab?color=yellow&logo=github&include_prereleases" />
|
|
9
11
|
</a>
|
|
10
12
|
<a href="https://github.com/maiyun/kebab/issues">
|
|
11
13
|
<img alt="GitHub issues" src="https://img.shields.io/github/issues/maiyun/kebab?color=blue&logo=github" />
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
7
7
|
*/
|
|
8
8
|
/** --- 当前系统版本号 --- */
|
|
9
|
-
export const VER = '7.3.
|
|
9
|
+
export const VER = '7.3.1';
|
|
10
10
|
// --- 服务端用的路径 ---
|
|
11
11
|
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
12
12
|
/** --- /xxx/xxx --- */
|
package/lib/s3.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Project: Kebab, User: Tang Rukun, JianSuoQiYue
|
|
3
3
|
* Date: 2024-2-18 18:32:45
|
|
4
|
-
* Last: 2024-2-18 18:32:47, 2024-3-16 16:42:27, 2024-5-31 21:36:26, 2024-7-8 00:28:42, 2024-7-19 11:32:43, 2025-6-10 21:45:34
|
|
4
|
+
* Last: 2024-2-18 18:32:47, 2024-3-16 16:42:27, 2024-5-31 21:36:26, 2024-7-8 00:28:42, 2024-7-19 11:32:43, 2025-6-10 21:45:34, 2025-12-5 23:42:59
|
|
5
5
|
*/
|
|
6
6
|
import * as s3 from '@aws-sdk/client-s3';
|
|
7
7
|
import * as stream from 'stream';
|
|
@@ -79,6 +79,11 @@ export declare class S3 {
|
|
|
79
79
|
* @param bucket bucket 名
|
|
80
80
|
*/
|
|
81
81
|
headObject(key: string, bucket?: string): Promise<s3.HeadObjectCommandOutput | false>;
|
|
82
|
+
/**
|
|
83
|
+
* --- 销毁连接,释放资源 ---
|
|
84
|
+
* --- 一般会自动垃圾回收,但高频接口也可主动调用 ---
|
|
85
|
+
*/
|
|
86
|
+
destroy(): void;
|
|
82
87
|
}
|
|
83
88
|
/**
|
|
84
89
|
* --- 创建一个对象存储对象 ---
|
package/lib/s3.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Project: Kebab, User: Tang Rukun, JianSuoQiYue
|
|
3
3
|
* Date: 2024-2-18 18:32:45
|
|
4
|
-
* Last: 2024-2-18 18:32:47, 2024-3-16 16:42:27, 2024-5-31 21:36:26, 2024-7-8 00:28:42, 2024-7-19 11:32:43, 2025-6-10 21:45:34
|
|
4
|
+
* Last: 2024-2-18 18:32:47, 2024-3-16 16:42:27, 2024-5-31 21:36:26, 2024-7-8 00:28:42, 2024-7-19 11:32:43, 2025-6-10 21:45:34, 2025-12-5 23:42:59
|
|
5
5
|
*/
|
|
6
6
|
// --- 库和定义 ---
|
|
7
7
|
import * as s3 from '@aws-sdk/client-s3';
|
|
8
8
|
import * as ls from '@aws-sdk/lib-storage';
|
|
9
9
|
import * as lCore from '#kebab/lib/core.js';
|
|
10
10
|
import * as lText from '#kebab/lib/text.js';
|
|
11
|
-
/** --- s3 的连接对象 --- */
|
|
12
|
-
const links = [];
|
|
13
11
|
/**
|
|
14
12
|
* --- s3 文档:https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3/ ---
|
|
15
13
|
*/
|
|
@@ -52,12 +50,6 @@ export class S3 {
|
|
|
52
50
|
endpoint = undefined;
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
|
-
const token = `${opt.service}-${account}-${secretId}-${region}`;
|
|
56
|
-
const link = links.find((item) => item.token === token);
|
|
57
|
-
if (link) {
|
|
58
|
-
this._link = link.link;
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
53
|
this._link = new s3.S3Client({
|
|
62
54
|
'region': region,
|
|
63
55
|
'credentials': {
|
|
@@ -66,10 +58,6 @@ export class S3 {
|
|
|
66
58
|
},
|
|
67
59
|
'endpoint': endpoint,
|
|
68
60
|
});
|
|
69
|
-
links.push({
|
|
70
|
-
'token': token,
|
|
71
|
-
'link': this._link,
|
|
72
|
-
});
|
|
73
61
|
}
|
|
74
62
|
/**
|
|
75
63
|
* --- 修改预定义 bucket ---
|
|
@@ -105,14 +93,14 @@ export class S3 {
|
|
|
105
93
|
'Body': content,
|
|
106
94
|
'ContentLength': length,
|
|
107
95
|
'ContentType': type,
|
|
108
|
-
'ContentDisposition': disposition
|
|
96
|
+
'ContentDisposition': disposition,
|
|
109
97
|
}
|
|
110
98
|
});
|
|
111
99
|
const res = await upload.done();
|
|
112
100
|
return (res.Location && res.Bucket && res.Key) ? res : false;
|
|
113
101
|
}
|
|
114
102
|
catch (e) {
|
|
115
|
-
lCore.log(this._ctr, '[S3][putObject] ' + lText.stringifyJson(e.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
103
|
+
lCore.log(this._ctr, '[LIB][S3][putObject] ' + lText.stringifyJson(e.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
116
104
|
return false;
|
|
117
105
|
}
|
|
118
106
|
}
|
|
@@ -131,8 +119,8 @@ export class S3 {
|
|
|
131
119
|
const r = await this._link.send(go);
|
|
132
120
|
return r.Body;
|
|
133
121
|
}
|
|
134
|
-
catch {
|
|
135
|
-
|
|
122
|
+
catch (e) {
|
|
123
|
+
lCore.log(this._ctr, '[LIB][S3][getObject] ' + lText.stringifyJson(e.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
136
124
|
return false;
|
|
137
125
|
}
|
|
138
126
|
}
|
|
@@ -150,8 +138,8 @@ export class S3 {
|
|
|
150
138
|
await this._link.send(doc);
|
|
151
139
|
return true;
|
|
152
140
|
}
|
|
153
|
-
catch {
|
|
154
|
-
|
|
141
|
+
catch (e) {
|
|
142
|
+
lCore.log(this._ctr, '[LIB][S3][deleteObject] ' + lText.stringifyJson(e.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
155
143
|
return false;
|
|
156
144
|
}
|
|
157
145
|
}
|
|
@@ -172,7 +160,7 @@ export class S3 {
|
|
|
172
160
|
return true;
|
|
173
161
|
}
|
|
174
162
|
catch (e) {
|
|
175
|
-
lCore.log(this._ctr, '[S3][deleteObjects] ' + lText.stringifyJson(e.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
163
|
+
lCore.log(this._ctr, '[LIB][S3][deleteObjects] ' + lText.stringifyJson(e.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
176
164
|
return false;
|
|
177
165
|
}
|
|
178
166
|
}
|
|
@@ -191,11 +179,18 @@ export class S3 {
|
|
|
191
179
|
}
|
|
192
180
|
catch (e) {
|
|
193
181
|
if (e.$metadata?.httpStatusCode !== 404) {
|
|
194
|
-
lCore.log(this._ctr, '[S3][headObject] ' + lText.stringifyJson(e.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
182
|
+
lCore.log(this._ctr, '[LIB][S3][headObject] ' + lText.stringifyJson(e.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
195
183
|
}
|
|
196
184
|
return false;
|
|
197
185
|
}
|
|
198
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* --- 销毁连接,释放资源 ---
|
|
189
|
+
* --- 一般会自动垃圾回收,但高频接口也可主动调用 ---
|
|
190
|
+
*/
|
|
191
|
+
destroy() {
|
|
192
|
+
this._link.destroy();
|
|
193
|
+
}
|
|
199
194
|
}
|
|
200
195
|
/**
|
|
201
196
|
* --- 创建一个对象存储对象 ---
|