This commit is contained in:
Tomas Dvorak
2025-10-25 16:33:53 +02:00
parent 857e6f007d
commit 3d621e2187
9 changed files with 238 additions and 121 deletions
+3 -14
View File
@@ -129,20 +129,9 @@ const SponsorsAdminPage: React.FC = () => {
if (!file) return;
try {
const res = await uploadFile(file);
const apiOrigin = new URL(API_URL, window.location.origin).origin;
// If backend returned an absolute URL pointing to the dev host (same origin as app), rewrite to API origin
let url = res.url || '';
try {
const parsed = new URL(url, window.location.origin);
const appOrigin = window.location.origin;
if (parsed.origin === appOrigin) {
// replace with API origin while keeping path
url = apiOrigin + parsed.pathname + parsed.search + parsed.hash;
}
} catch (e) {
// ignore
}
setEditing((prev) => ({ ...(prev || {}), logo_url: url }));
// uploadFile already normalizes to a backend-relative URL like '/uploads/2025/10/...'
// Store that relative path to keep it portable across environments
setEditing((prev) => ({ ...(prev || {}), logo_url: res.url || '' }));
toast({ title: 'Logo nahráno', status: 'success' });
} catch (err) {
toast({ title: 'Nahrání loga selhalo', status: 'error' });