新增支持s3协议对象存储

This commit is contained in:
eoao
2025-08-31 12:04:19 +08:00
parent 562528e968
commit 86a80900c1
27 changed files with 1981 additions and 277 deletions

View File

@@ -0,0 +1,54 @@
import { S3Client, PutObjectCommand, DeleteObjectsCommand } from "@aws-sdk/client-s3";
import settingService from './setting-service';
import domainUtils from '../utils/domain-uitls';
const s3Service = {
async putObj(c, key, content, metadata) {
const client = await this.client(c);
const { bucket } = await settingService.query(c);
await client.send(
new PutObjectCommand({ Bucket: bucket, Key: key, Body: content, ...metadata })
)
},
async deleteObj(c,keys) {
if (typeof keys === 'string') {
keys = [keys]
}
if (keys.length === 0) {
return
}
const client = await this.client(c)
const { bucket } = await settingService.query(c);
await client.send(
new DeleteObjectsCommand({
Bucket: bucket,
Delete: {
Objects: keys.map(key => ({Key: key}))
}
})
)
},
async client(c) {
const { region, endpoint, s3AccessKey, s3SecretKey } = await settingService.query(c);
return new S3Client({
region: region,
endpoint: domainUtils.toOssDomain(endpoint),
credentials: {
accessKeyId: s3AccessKey,
secretAccessKey: s3SecretKey,
},
});
}
}
export default s3Service