import { Client } from "minio"; const rawEndpoint = process.env.MINIO_ENDPOINT ?? "http://localhost:9000"; const endpointUrl = new URL(rawEndpoint); export const minioClient = new Client({ endPoint: endpointUrl.hostname, port: endpointUrl.port ? parseInt(endpointUrl.port) : endpointUrl.protocol === "https:" ? 443 : 80, useSSL: endpointUrl.protocol === "https:", accessKey: process.env.MINIO_ROOT_USER ?? "", secretKey: process.env.MINIO_ROOT_PASSWORD ?? "", }); export const MINIO_BUCKET = process.env.MINIO_BUCKET ?? "garden"; let bucketReady = false; export async function ensureBucket(): Promise { if (bucketReady) return; const exists = await minioClient.bucketExists(MINIO_BUCKET); if (!exists) { await minioClient.makeBucket(MINIO_BUCKET); } bucketReady = true; }