1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-18 20:39:36 +02:00

Docker with minio

This commit is contained in:
Sean Morley 2024-06-09 18:10:17 +00:00
parent 1c7939f2b8
commit 4ed9ebc456
4 changed files with 49 additions and 5 deletions

View file

@ -1 +1,7 @@
DATABASE_URL=
DATABASE_URL=
MINIO_URL=http://localhost:9000
MINIO_ENDPOINT=localhost
MINIO_ACCESS_KEY=minioadmin
MINIO_SECRET_KEY=minioadmin
MINIO_USE_SSL=false

View file

@ -19,3 +19,17 @@ services:
POSTGRES_DB: adventurelog
ports:
- "5432:5432"
minio:
image: quay.io/minio/minio
command: server /data --console-address ":9001"
environment:
- MINIO_ROOT_USER=minioadmin
- MINIO_ROOT_PASSWORD=minioadmin
volumes:
- minio_data:/data
ports:
- "9000:9000"
- "9001:9001"
volumes:
minio_data:

View file

@ -1,11 +1,16 @@
import { Client } from "minio";
import { MINIO_URL } from "$env/static/private";
import { MINIO_ACCESS_KEY } from "$env/static/private";
import { MINIO_SECRET_KEY } from "$env/static/private";
import { MINIO_ENDPOINT } from "$env/static/private";
const port = MINIO_URL?.split(":").pop(); // 9000
const minioClient = new Client({
endPoint: "localhost",
port: 9000,
endPoint: MINIO_ENDPOINT ? MINIO_ENDPOINT : "localhost",
port: port ? parseInt(port) : 9000,
useSSL: false,
accessKey: "minioadmin",
secretKey: "minioadmin",
accessKey: MINIO_ACCESS_KEY,
secretKey: MINIO_SECRET_KEY,
});
export default minioClient;

View file

@ -11,6 +11,25 @@ export async function POST(event: RequestEvent): Promise<Response> {
const fileExtension = contentType.split("/").pop();
const fileName = `${generateId(25)}.${fileExtension}`;
if (!fileExtension || !fileName) {
return new Response(JSON.stringify({ error: "Invalid file type" }), {
status: 400,
headers: {
"Content-Type": "application/json",
},
});
}
// check if the file is an image
if (!contentType.startsWith("image")) {
return new Response(JSON.stringify({ error: "Invalid file type" }), {
status: 400,
headers: {
"Content-Type": "application/json",
},
});
}
const fileBuffer = await event.request.arrayBuffer();
const metaData = {
"Content-Type": contentType,