mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-21 22:09:36 +02:00
Docker with minio
This commit is contained in:
parent
1c7939f2b8
commit
4ed9ebc456
4 changed files with 49 additions and 5 deletions
|
@ -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
|
|
@ -19,3 +19,17 @@ services:
|
||||||
POSTGRES_DB: adventurelog
|
POSTGRES_DB: adventurelog
|
||||||
ports:
|
ports:
|
||||||
- "5432:5432"
|
- "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:
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
import { Client } from "minio";
|
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({
|
const minioClient = new Client({
|
||||||
endPoint: "localhost",
|
endPoint: MINIO_ENDPOINT ? MINIO_ENDPOINT : "localhost",
|
||||||
port: 9000,
|
port: port ? parseInt(port) : 9000,
|
||||||
useSSL: false,
|
useSSL: false,
|
||||||
accessKey: "minioadmin",
|
accessKey: MINIO_ACCESS_KEY,
|
||||||
secretKey: "minioadmin",
|
secretKey: MINIO_SECRET_KEY,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default minioClient;
|
export default minioClient;
|
||||||
|
|
|
@ -11,6 +11,25 @@ export async function POST(event: RequestEvent): Promise<Response> {
|
||||||
const fileExtension = contentType.split("/").pop();
|
const fileExtension = contentType.split("/").pop();
|
||||||
const fileName = `${generateId(25)}.${fileExtension}`;
|
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 fileBuffer = await event.request.arrayBuffer();
|
||||||
const metaData = {
|
const metaData = {
|
||||||
"Content-Type": contentType,
|
"Content-Type": contentType,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue