31 lines
786 B
TypeScript
31 lines
786 B
TypeScript
// 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()
|