@buka/nestjs-kit 4.3.1 → 4.3.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.
- package/CHANGELOG.md +7 -0
- package/dist/index.js +50 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3709,12 +3709,12 @@ let OpenBaoTokenManager = _OpenBaoTokenManager = class OpenBaoTokenManager {
|
|
|
3709
3709
|
this.logger.log("Token renewed successfully");
|
|
3710
3710
|
this.scheduleRenewal();
|
|
3711
3711
|
} catch (renewError) {
|
|
3712
|
-
this.logger.error("Failed to renew token, attempting re-authentication", renewError);
|
|
3712
|
+
this.logger.error("Failed to renew token, attempting re-authentication", renewError instanceof Error ? renewError.stack : void 0);
|
|
3713
3713
|
try {
|
|
3714
3714
|
await this.authenticate();
|
|
3715
3715
|
this.scheduleRenewal();
|
|
3716
3716
|
} catch (authError) {
|
|
3717
|
-
this.logger.error("Re-authentication also failed, will retry in 5s", authError);
|
|
3717
|
+
this.logger.error("Re-authentication also failed, will retry in 5s", authError instanceof Error ? authError.stack : void 0);
|
|
3718
3718
|
this.renewalTimer = setTimeout(() => {
|
|
3719
3719
|
this.renewToken();
|
|
3720
3720
|
}, 5e3);
|
|
@@ -9928,13 +9928,19 @@ let ObjectStorageService = _ObjectStorageService = class ObjectStorageService {
|
|
|
9928
9928
|
* @param options - 可选配置,如是否自动添加前缀
|
|
9929
9929
|
*/
|
|
9930
9930
|
async get(path, options) {
|
|
9931
|
+
const key = this.buildPath(path, options);
|
|
9931
9932
|
const command = new GetObjectCommand({
|
|
9932
9933
|
Bucket: this.config.bucket,
|
|
9933
|
-
Key:
|
|
9934
|
+
Key: key
|
|
9934
9935
|
});
|
|
9935
|
-
|
|
9936
|
-
|
|
9937
|
-
|
|
9936
|
+
try {
|
|
9937
|
+
const res = await this.client.send(command);
|
|
9938
|
+
if (!res.Body) throw new Error("No body");
|
|
9939
|
+
return Readable.fromWeb(res.Body.transformToWebStream());
|
|
9940
|
+
} catch (err) {
|
|
9941
|
+
this.logger.error(`对象存储下载失败, bucket: ${this.config.bucket}, key: ${key}`, err instanceof Error ? err.stack : void 0);
|
|
9942
|
+
throw err;
|
|
9943
|
+
}
|
|
9938
9944
|
}
|
|
9939
9945
|
/**
|
|
9940
9946
|
* 上传文件内容到指定路径。
|
|
@@ -9946,41 +9952,55 @@ let ObjectStorageService = _ObjectStorageService = class ObjectStorageService {
|
|
|
9946
9952
|
*/
|
|
9947
9953
|
async upload(path, contents, options) {
|
|
9948
9954
|
const key = this.buildPath(path, options);
|
|
9949
|
-
|
|
9955
|
+
const upload = new Upload({
|
|
9950
9956
|
client: this.client,
|
|
9951
9957
|
params: {
|
|
9952
9958
|
Bucket: this.config.bucket,
|
|
9953
9959
|
Key: key,
|
|
9954
9960
|
Body: contents
|
|
9955
9961
|
}
|
|
9956
|
-
})
|
|
9957
|
-
|
|
9962
|
+
});
|
|
9963
|
+
try {
|
|
9964
|
+
await upload.done();
|
|
9965
|
+
return key;
|
|
9966
|
+
} catch (err) {
|
|
9967
|
+
this.logger.error(`对象存储上传失败, bucket: ${this.config.bucket}, key: ${key}`, err instanceof Error ? err.stack : void 0);
|
|
9968
|
+
throw err;
|
|
9969
|
+
}
|
|
9958
9970
|
}
|
|
9959
9971
|
/**
|
|
9960
9972
|
* 获取文件的元数据(metadata)。
|
|
9961
9973
|
*/
|
|
9962
9974
|
async getMetadata(path, options) {
|
|
9975
|
+
const key = this.buildPath(path, options);
|
|
9963
9976
|
const command = new HeadObjectCommand({
|
|
9964
9977
|
Bucket: this.config.bucket,
|
|
9965
|
-
Key:
|
|
9978
|
+
Key: key
|
|
9966
9979
|
});
|
|
9967
|
-
|
|
9968
|
-
|
|
9969
|
-
|
|
9980
|
+
try {
|
|
9981
|
+
const res = await this.client.send(command);
|
|
9982
|
+
if (!res.Metadata) throw new Error("No metadata");
|
|
9983
|
+
return res.Metadata;
|
|
9984
|
+
} catch (err) {
|
|
9985
|
+
this.logger.error(`对象存储获取元数据失败, bucket: ${this.config.bucket}, key: ${key}`, err instanceof Error ? err.stack : void 0);
|
|
9986
|
+
throw err;
|
|
9987
|
+
}
|
|
9970
9988
|
}
|
|
9971
9989
|
/**
|
|
9972
9990
|
* 检查文件是否存在。
|
|
9973
9991
|
*/
|
|
9974
9992
|
async exists(path, options) {
|
|
9993
|
+
const key = this.buildPath(path, options);
|
|
9975
9994
|
const command = new HeadObjectCommand({
|
|
9976
9995
|
Bucket: this.config.bucket,
|
|
9977
|
-
Key:
|
|
9996
|
+
Key: key
|
|
9978
9997
|
});
|
|
9979
9998
|
try {
|
|
9980
9999
|
await this.client.send(command);
|
|
9981
10000
|
return true;
|
|
9982
10001
|
} catch (err) {
|
|
9983
10002
|
if (err instanceof Error && err.name === "NotFound") return false;
|
|
10003
|
+
this.logger.error(`对象存储检查文件存在性失败, bucket: ${this.config.bucket}, key: ${key}`, err instanceof Error ? err.stack : void 0);
|
|
9984
10004
|
throw err;
|
|
9985
10005
|
}
|
|
9986
10006
|
}
|
|
@@ -9988,11 +10008,17 @@ let ObjectStorageService = _ObjectStorageService = class ObjectStorageService {
|
|
|
9988
10008
|
* 删除指定路径的文件。
|
|
9989
10009
|
*/
|
|
9990
10010
|
async remove(path, options) {
|
|
10011
|
+
const key = this.buildPath(path, options);
|
|
9991
10012
|
const command = new DeleteObjectCommand({
|
|
9992
10013
|
Bucket: this.config.bucket,
|
|
9993
|
-
Key:
|
|
10014
|
+
Key: key
|
|
9994
10015
|
});
|
|
9995
|
-
|
|
10016
|
+
try {
|
|
10017
|
+
await this.client.send(command);
|
|
10018
|
+
} catch (err) {
|
|
10019
|
+
this.logger.error(`对象存储删除文件失败, bucket: ${this.config.bucket}, key: ${key}`, err instanceof Error ? err.stack : void 0);
|
|
10020
|
+
throw err;
|
|
10021
|
+
}
|
|
9996
10022
|
}
|
|
9997
10023
|
/**
|
|
9998
10024
|
* 获取文件的预签名 URL,用于临时授权访问。
|
|
@@ -10002,11 +10028,17 @@ let ObjectStorageService = _ObjectStorageService = class ObjectStorageService {
|
|
|
10002
10028
|
* @param options - 可选配置
|
|
10003
10029
|
*/
|
|
10004
10030
|
async getSignedUrl(path, expiresInSecond, options) {
|
|
10031
|
+
const key = this.buildPath(path, options);
|
|
10005
10032
|
const command = new GetObjectCommand({
|
|
10006
10033
|
Bucket: this.config.bucket,
|
|
10007
|
-
Key:
|
|
10034
|
+
Key: key
|
|
10008
10035
|
});
|
|
10009
|
-
|
|
10036
|
+
try {
|
|
10037
|
+
return await getSignedUrl(this.client, command, { expiresIn: expiresInSecond });
|
|
10038
|
+
} catch (err) {
|
|
10039
|
+
this.logger.error(`对象存储获取签名URL失败, bucket: ${this.config.bucket}, key: ${key}`, err instanceof Error ? err.stack : void 0);
|
|
10040
|
+
throw err;
|
|
10041
|
+
}
|
|
10010
10042
|
}
|
|
10011
10043
|
};
|
|
10012
10044
|
ObjectStorageService = _ObjectStorageService = __decorate([
|