refactor: replace server action with API route for image uploads and update Nginx rate limiting configuration
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user