Add portfolio thingies

This commit is contained in:
2025-12-25 09:24:27 +01:00
parent ee454261cb
commit ededf3df06
13 changed files with 332 additions and 103 deletions

View File

@ -1,23 +1,18 @@
import { s3 } from "@/lib/s3";
import { GetObjectCommand } from "@aws-sdk/client-s3";
import "dotenv/config";
import { Readable } from "stream";
export async function getImageBufferFromS3(fileKey: string, fileType?: string): Promise<Buffer> {
// const type = fileType ? fileType.split("/")[1] : "webp";
export async function getImageBufferFromS3Key(s3Key: string): Promise<Buffer> {
const command = new GetObjectCommand({
Bucket: `${process.env.BUCKET_NAME}`,
Key: `original/${fileKey}.${fileType}`,
Bucket: process.env.BUCKET_NAME!,
Key: s3Key,
});
const response = await s3.send(command);
const stream = response.Body as Readable;
const chunks: Uint8Array[] = [];
for await (const chunk of stream) {
chunks.push(chunk);
}
for await (const chunk of stream) chunks.push(chunk);
return Buffer.concat(chunks);
}