Merge branch 'front' of ssh://meowgit.nekoea.red:22222/nihonium/nyanimedb into front
All checks were successful
Build (frontend build only) / build (push) Successful in 2m58s
All checks were successful
Build (frontend build only) / build (push) Successful in 2m58s
This commit is contained in:
commit
2bf268cbef
1 changed files with 31 additions and 22 deletions
|
|
@ -55,27 +55,36 @@ export const SettingsPage: React.FC = () => {
|
||||||
setUploading(true);
|
setUploading(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
|
|
||||||
|
// Создаем FormData строго по спецификации
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("file", file);
|
formData.append("image", file);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Используем fetch напрямую или убеждаемся, что клиент принимает FormData
|
||||||
const res = await postMediaUpload({
|
const res = await postMediaUpload({
|
||||||
|
// @ts-ignore - обходим строгую типизацию тела, если она ожидает объект
|
||||||
body: formData,
|
body: formData,
|
||||||
// Сбрасываем заголовок, чтобы браузер сам поставил multipart/form-data + boundary
|
headers: {
|
||||||
headers: { "Content-Type": undefined as any },
|
// УДАЛЯЕМ Content-Type вообще.
|
||||||
|
// Если оставить undefined, некоторые клиенты могут подставить 'application/json'.
|
||||||
|
// Нам нужно, чтобы заголовок отсутствовал в объекте headers,
|
||||||
|
// тогда fetch сам выставит multipart/form-data с boundary.
|
||||||
|
"X-XSRF-TOKEN": xsrfToken,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.data && res.data.id) {
|
if (res.data && res.data.id) {
|
||||||
setAvatarId(res.data.id);
|
setAvatarId(res.data.id);
|
||||||
setAvatarUrl(res.data.image_path ?? null); // Для мгновенного превью
|
setAvatarUrl(res.data.image_path ?? null);
|
||||||
setSuccess("Image uploaded!");
|
setSuccess("Image uploaded!");
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setError("Failed to upload image");
|
console.error("Upload error:", err);
|
||||||
|
setError("Upload failed. Check if the file is an image.");
|
||||||
} finally {
|
} finally {
|
||||||
setUploading(false);
|
setUploading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const saveSettings = async (e: React.FormEvent) => {
|
const saveSettings = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue