wip
This commit is contained in:
30
src/storage/index.ts
Normal file
30
src/storage/index.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
// import { ListBucketsCommand, PutObjectCommand, S3Client } from '@aws-sdk/client-s3'
|
||||
import { S3Client, type S3File } from 'bun'
|
||||
|
||||
class Storage {
|
||||
client: S3Client
|
||||
|
||||
constructor() {
|
||||
this.client = new S3Client({
|
||||
region: 'cn-east-1',
|
||||
accessKeyId: process.env.RUSTFS_ACCESS_KEY_ID!,
|
||||
secretAccessKey: process.env.RUSTFS_SECRET_ACCESS_KEY!,
|
||||
bucket: 'stor1',
|
||||
endpoint: process.env.RUSTFS_ENDPOINT_URL!,
|
||||
})
|
||||
}
|
||||
|
||||
async upload(file: Blob, name: string): Promise<void> {
|
||||
const s3File: S3File = this.client.file(name)
|
||||
const result = await s3File.write(file)
|
||||
console.log({result})
|
||||
}
|
||||
|
||||
presign(name: string) {
|
||||
const s3File = this.client.file(name)
|
||||
|
||||
return s3File.presign({method: 'GET'})
|
||||
}
|
||||
}
|
||||
|
||||
export const storage = new Storage()
|
||||
Reference in New Issue
Block a user