refactor: replace server action with API route for image uploads and update Nginx rate limiting configuration

This commit is contained in:
2026-05-30 01:06:52 +07:00 Unverified
parent bf215bb9cf
commit 96c52e8ad6
4 changed files with 76 additions and 46 deletions
+13 -2
View File
@@ -18,7 +18,6 @@ import {
deleteQuestion,
reorderQuestions,
} from "@/app/actions/questions";
import { uploadImage } from "@/app/actions/upload";
import { Plus, Trash, ArrowUp, ArrowDown, Loader2, Save, Image as ImageIcon, X } from "lucide-react";
import Image from 'next/image';
@@ -146,7 +145,19 @@ export default function FormEditorClient({ form, initialQuestions }: FormEditorC
setUploadingId(questionId);
toast.promise(
uploadImage(formData).then(async (imageUrl) => {
new Promise<string>(async (resolve, reject) => {
try {
const res = await fetch("/api/upload", {
method: "POST",
body: formData,
});
const data = await res.json();
if (!res.ok) throw new Error(data.error || "Failed to upload image");
resolve(data.url);
} catch (error) {
reject(error);
}
}).then(async (imageUrl) => {
await updateQuestion(questionId, form.id, { imageUrl });
setQuestions((prev) =>
prev.map((q) => (q.id === questionId ? { ...q, imageUrl } : q))