Bot & Automation
AI Creator Studio Telegram
/root/hermes-projects/AI Creator Studio Telegram
packages/storage/src/storage-service.ts
text
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
export function createS3Client() {
return new S3Client({
endpoint: process.env.S3_ENDPOINT,
region: process.env.S3_REGION ?? "auto",
forcePathStyle: true,
credentials:
process.env.S3_ACCESS_KEY_ID && process.env.S3_SECRET_ACCESS_KEY
? {
accessKeyId: process.env.S3_ACCESS_KEY_ID,
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
}
: undefined,
});
}
export async function uploadBuffer(input: {
key: string;
body: Buffer;
contentType: string;
}): Promise<{ storageKey: string }> {
const bucket = process.env.S3_BUCKET;
if (!bucket) {
throw new Error("S3_BUCKET is required");
}
const client = createS3Client();
await client.send(
new PutObjectCommand({
Bucket: bucket,
Key: input.key,
Body: input.body,
ContentType: input.contentType,
}),
);
return { storageKey: input.key };
}