This commit is contained in:
Moritz Utcke
2025-03-19 11:12:53 -03:00
parent 959fcd7f3b
commit aea651c7f7
7 changed files with 94 additions and 81 deletions

View File

@@ -94,14 +94,4 @@ export const SERVICES: Record<
};
export const BASE_URI = process.env.NODE_ENV == "production" ? "https://online-energieausweis.org" : "http://localhost:3000";
export const LEX_OFFICE_API_KEY = process.env.NODE_ENV == "production" ? "iwQLCU_ZAq6bVV7hmR8RO8MiC8Q" : "znjmkmbA3Hbx9dC7wdKp7TnOf1pcRl_tCUwEBZys7bj-QRPG"
export const s3Client = new S3Client({
region: "eu-central-1",
endpoint: "https://s3-eu-central-1.ionoscloud.com",
credentials: {
accessKeyId: "EEAAAAHYzkBh2aRNC4OEVfqCRCviXoIZ3wm9UieAVCeLbWnJrQAAAAECGy6_AAAAAAIbLr9zLHhcZE7kGJngOPTFoODh",
secretAccessKey: "zlRI0jK+A8CIxir0QPdXNFUV+L9XjFTGyBvdUT1dvgY4FNlsOJgNJ+5xW5oShzmy",
},
forcePathStyle: true,
});
export const LEX_OFFICE_API_KEY = process.env.NODE_ENV == "production" ? "iwQLCU_ZAq6bVV7hmR8RO8MiC8Q" : "znjmkmbA3Hbx9dC7wdKp7TnOf1pcRl_tCUwEBZys7bj-QRPG"

44
src/lib/s3.ts Normal file
View File

@@ -0,0 +1,44 @@
import { GetObjectCommand, S3Client } from "@aws-sdk/client-s3";
import * as fs from "fs";
export const s3Client = new S3Client({
region: "eu-central-1",
endpoint: "https://s3-eu-central-1.ionoscloud.com",
credentials: {
accessKeyId:
"EEAAAAHYzkBh2aRNC4OEVfqCRCviXoIZ3wm9UieAVCeLbWnJrQAAAAECGy6_AAAAAAIbLr9zLHhcZE7kGJngOPTFoODh",
secretAccessKey:
"zlRI0jK+A8CIxir0QPdXNFUV+L9XjFTGyBvdUT1dvgY4FNlsOJgNJ+5xW5oShzmy",
},
forcePathStyle: true,
});
export async function getS3File(
bucket: string,
key: string
): Promise<Buffer | null> {
try {
let command = new GetObjectCommand({ Bucket: bucket, Key: key });
let response = await s3Client.send(command);
const body = response.Body;
if (!body) {
return null;
}
let buffer = await streamToBuffer(body as unknown as fs.ReadStream);
return buffer;
} catch (e) {
return null;
}
}
async function streamToBuffer(stream: fs.ReadStream): Promise<Buffer> {
return new Promise((resolve, reject) => {
const chunks: any[] = [];
stream.on("data", (chunk) => chunks.push(chunk));
stream.on("error", reject);
stream.on("end", () => resolve(Buffer.concat(chunks)));
});
}