@yayoyunlm/utils_sql_storage 1.1.0 → 1.2.0
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/dist/index.cjs +20 -0
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +21 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -109,6 +109,26 @@ var S3Uploader = class _S3Uploader {
|
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
+
async delete(s3Path) {
|
|
113
|
+
try {
|
|
114
|
+
const normalizedKey = s3Path.replace(/^\//, "");
|
|
115
|
+
const command = new import_client_s3.DeleteObjectCommand({
|
|
116
|
+
Bucket: this.bucket,
|
|
117
|
+
Key: normalizedKey
|
|
118
|
+
});
|
|
119
|
+
await this.s3Client.send(command);
|
|
120
|
+
return {
|
|
121
|
+
success: true,
|
|
122
|
+
s3Path: normalizedKey
|
|
123
|
+
};
|
|
124
|
+
} catch (err) {
|
|
125
|
+
console.error("\u5220\u9664\u5931\u8D25", err);
|
|
126
|
+
return {
|
|
127
|
+
success: false,
|
|
128
|
+
error: err instanceof Error ? err.message : "\u672A\u77E5\u9519\u8BEF"
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
112
132
|
};
|
|
113
133
|
// Annotate the CommonJS export names for ESM import in node:
|
|
114
134
|
0 && (module.exports = {
|
package/dist/index.d.cts
CHANGED
|
@@ -26,6 +26,11 @@ interface UploadResult {
|
|
|
26
26
|
s3Path?: string;
|
|
27
27
|
error?: string;
|
|
28
28
|
}
|
|
29
|
+
interface DeleteResult {
|
|
30
|
+
success: boolean;
|
|
31
|
+
s3Path?: string;
|
|
32
|
+
error?: string;
|
|
33
|
+
}
|
|
29
34
|
declare class S3Uploader {
|
|
30
35
|
static endpoint: string | undefined;
|
|
31
36
|
static bucket: string | undefined;
|
|
@@ -39,6 +44,7 @@ declare class S3Uploader {
|
|
|
39
44
|
constructor(config?: S3UploaderConfig);
|
|
40
45
|
upload(fileContent: string | Buffer, // 接收文件路径 或 文件二进制流
|
|
41
46
|
s3Path: string, contentType?: string): Promise<UploadResult>;
|
|
47
|
+
delete(s3Path: string): Promise<DeleteResult>;
|
|
42
48
|
}
|
|
43
49
|
|
|
44
|
-
export { S3Uploader, type S3UploaderConfig, type UploadResult, createDbClient };
|
|
50
|
+
export { type DeleteResult, S3Uploader, type S3UploaderConfig, type UploadResult, createDbClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -26,6 +26,11 @@ interface UploadResult {
|
|
|
26
26
|
s3Path?: string;
|
|
27
27
|
error?: string;
|
|
28
28
|
}
|
|
29
|
+
interface DeleteResult {
|
|
30
|
+
success: boolean;
|
|
31
|
+
s3Path?: string;
|
|
32
|
+
error?: string;
|
|
33
|
+
}
|
|
29
34
|
declare class S3Uploader {
|
|
30
35
|
static endpoint: string | undefined;
|
|
31
36
|
static bucket: string | undefined;
|
|
@@ -39,6 +44,7 @@ declare class S3Uploader {
|
|
|
39
44
|
constructor(config?: S3UploaderConfig);
|
|
40
45
|
upload(fileContent: string | Buffer, // 接收文件路径 或 文件二进制流
|
|
41
46
|
s3Path: string, contentType?: string): Promise<UploadResult>;
|
|
47
|
+
delete(s3Path: string): Promise<DeleteResult>;
|
|
42
48
|
}
|
|
43
49
|
|
|
44
|
-
export { S3Uploader, type S3UploaderConfig, type UploadResult, createDbClient };
|
|
50
|
+
export { type DeleteResult, S3Uploader, type S3UploaderConfig, type UploadResult, createDbClient };
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ function createDbClient(PrismaClientConstructor, connectionString) {
|
|
|
9
9
|
|
|
10
10
|
// linkstorage.ts
|
|
11
11
|
import fs from "fs";
|
|
12
|
-
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
|
|
12
|
+
import { S3Client, PutObjectCommand, DeleteObjectCommand } from "@aws-sdk/client-s3";
|
|
13
13
|
var S3Uploader = class _S3Uploader {
|
|
14
14
|
// 1. 静态属性:初始化为 undefined,支持“不传”
|
|
15
15
|
static endpoint = void 0;
|
|
@@ -72,6 +72,26 @@ var S3Uploader = class _S3Uploader {
|
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
+
async delete(s3Path) {
|
|
76
|
+
try {
|
|
77
|
+
const normalizedKey = s3Path.replace(/^\//, "");
|
|
78
|
+
const command = new DeleteObjectCommand({
|
|
79
|
+
Bucket: this.bucket,
|
|
80
|
+
Key: normalizedKey
|
|
81
|
+
});
|
|
82
|
+
await this.s3Client.send(command);
|
|
83
|
+
return {
|
|
84
|
+
success: true,
|
|
85
|
+
s3Path: normalizedKey
|
|
86
|
+
};
|
|
87
|
+
} catch (err) {
|
|
88
|
+
console.error("\u5220\u9664\u5931\u8D25", err);
|
|
89
|
+
return {
|
|
90
|
+
success: false,
|
|
91
|
+
error: err instanceof Error ? err.message : "\u672A\u77E5\u9519\u8BEF"
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
75
95
|
};
|
|
76
96
|
export {
|
|
77
97
|
S3Uploader,
|