Docker with minio
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user