fix: init bucket before upload and remove MinIO UI references
This commit is contained in:
@@ -2,13 +2,14 @@
|
||||
|
||||
import { PutObjectCommand } from "@aws-sdk/client-s3";
|
||||
import { s3Client, BUCKET_NAME } from "@/lib/s3";
|
||||
import { initMinio } from "@/lib/init-minio";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
// Get the public URL for MinIO files
|
||||
// Get the public URL for files
|
||||
// In production, files are served through /api/files proxy
|
||||
function getPublicUrl(fileName: string): string {
|
||||
// Always use our API proxy route to serve files
|
||||
// This ensures files are accessible even when MinIO is not publicly exposed
|
||||
// This ensures files are accessible even when storage is not publicly exposed
|
||||
return `/api/files/${BUCKET_NAME}/${fileName}`;
|
||||
}
|
||||
|
||||
@@ -19,6 +20,9 @@ export async function uploadFile(formData: FormData) {
|
||||
throw new Error("No file provided");
|
||||
}
|
||||
|
||||
// Ensure bucket exists before upload
|
||||
await initMinio();
|
||||
|
||||
const buffer = Buffer.from(await file.arrayBuffer());
|
||||
const fileName = `${uuidv4()}-${file.name}`;
|
||||
|
||||
@@ -34,9 +38,8 @@ export async function uploadFile(formData: FormData) {
|
||||
// Return the URL to access the file
|
||||
const url = getPublicUrl(fileName);
|
||||
return { success: true, url, fileName };
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error("Upload error:", error);
|
||||
return { success: false, error: "Failed to upload file" };
|
||||
return { success: false, error: error.message || "Failed to upload file" };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ export default function SetupPage() {
|
||||
{isUploading ? (
|
||||
<div className="flex flex-col items-center">
|
||||
<Loader2 size={48} className="mb-4 text-blue-500 animate-spin" />
|
||||
<p className="text-sm font-medium">Enviando para o MinIO...</p>
|
||||
<p className="text-sm font-medium">Enviando...</p>
|
||||
</div>
|
||||
) : formData.logoUrl ? (
|
||||
<div className="flex flex-col items-center">
|
||||
@@ -217,7 +217,7 @@ export default function SetupPage() {
|
||||
<>
|
||||
<CloudUpload size={48} className="mb-4 group-hover:text-blue-500 transition-colors" />
|
||||
<p className="text-sm font-medium">Arraste sua logo ou clique para buscar</p>
|
||||
<p className="text-xs mt-1">PNG, JPG até 5MB (Será salva no MinIO)</p>
|
||||
<p className="text-xs mt-1">PNG, JPG até 5MB</p>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user