import { Client } from 'minio' import { env } from './env' const client = new Client({ endPoint: env.MINIO_ENDPOINT, port: env.MINIO_PORT, useSSL: env.MINIO_USE_SSL, accessKey: env.MINIO_ACCESS_KEY, secretKey: env.MINIO_SECRET_KEY, }) // Auto-create bucket if it doesn't exist client.bucketExists(env.MINIO_BUCKET).then(async (exists) => { if (!exists) { await client.makeBucket(env.MINIO_BUCKET) console.log(`[MinIO] Bucket "${env.MINIO_BUCKET}" created.`) } }).catch((err) => { console.error('[MinIO] Failed to check/create bucket:', err.message) }) export async function uploadBugImage(file: File): Promise { const ext = file.name.split('.').pop()?.toLowerCase() ?? 'bin' const objectName = `${env.MINIO_UPLOAD_DIR}/${crypto.randomUUID()}.${ext}` const buffer = Buffer.from(await file.arrayBuffer()) await client.putObject(env.MINIO_BUCKET, objectName, buffer, file.size, { 'Content-Type': file.type, }) return objectName // e.g. bug-reports/uuid.jpg } export async function getMinioDownloadUrl(objectName: string): Promise { return client.presignedGetObject(env.MINIO_BUCKET, objectName, 3600) }