This commit is contained in:
2025-06-10 16:48:40 +02:00
parent 49aa47ab10
commit 839b307edd
8 changed files with 473 additions and 57 deletions

View File

@@ -4,12 +4,20 @@ import { promises as fs } from 'fs';
import mime from 'mime-types';
export default defineEventHandler(async (event) => {
const xTagHeader = getRequestHeader(event, "x-tag");
if (!xTagHeader || (xTagHeader !== "094ut234" && xTagHeader !== "pjnvü1230")) {
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
}
try {
// Get the current path and bucket from query params
const query = getQuery(event);
const currentPath = (query.path as string) || '';
const bucket = (query.bucket as string) || 'client-portal'; // Default bucket
console.log('[Upload] Request received for bucket:', bucket, 'path:', currentPath);
// Parse multipart form data
const form = formidable({
maxFileSize: 50 * 1024 * 1024, // 50MB limit
@@ -50,6 +58,15 @@ export default defineEventHandler(async (event) => {
} else {
// For other buckets, use the MinIO client directly
const client = getMinioClient();
// Ensure bucket exists
try {
await client.bucketExists(bucket);
} catch (err) {
console.log(`[Upload] Bucket ${bucket} doesn't exist, creating it...`);
await client.makeBucket(bucket, 'us-east-1');
}
await client.putObject(bucket, fullPath, fileBuffer, fileBuffer.length, {
'Content-Type': contentType,
});