mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-05 04:52:58 +00:00
Add files via upload
This commit is contained in:
+22
-19
@@ -495,7 +495,7 @@
|
|||||||
}, delay);
|
}, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override fetch to include token
|
// Override fetch to include token (but NOT for FormData requests)
|
||||||
const originalFetch = window.fetch;
|
const originalFetch = window.fetch;
|
||||||
window.fetch = async function(resource, init = {}) {
|
window.fetch = async function(resource, init = {}) {
|
||||||
// Add token to headers if it's an API request
|
// Add token to headers if it's an API request
|
||||||
@@ -505,8 +505,8 @@
|
|||||||
headers.set('Authorization', `Bearer ${token}`);
|
headers.set('Authorization', `Bearer ${token}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set content type if not set
|
// Only set content type if not FormData (FormData sets its own)
|
||||||
if (!headers.has('Content-Type') && init.body) {
|
if (!headers.has('Content-Type') && init.body && !(init.body instanceof FormData)) {
|
||||||
headers.set('Content-Type', 'application/json');
|
headers.set('Content-Type', 'application/json');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -710,7 +710,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save banner
|
|
||||||
async function saveBanner(event) {
|
async function saveBanner(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
@@ -730,15 +729,20 @@
|
|||||||
formData.append('text', document.getElementById('bannerText').value);
|
formData.append('text', document.getElementById('bannerText').value);
|
||||||
formData.append('link', document.getElementById('bannerLink').value);
|
formData.append('link', document.getElementById('bannerLink').value);
|
||||||
|
|
||||||
// Add style properties to form data with the correct format
|
// Create style object with default values
|
||||||
formData.append('style.backgroundColor', document.getElementById('bannerBgColor').value);
|
const style = {
|
||||||
formData.append('style.textColor', document.getElementById('bannerTextColor').value);
|
backgroundColor: document.getElementById('bannerBgColor').value,
|
||||||
formData.append('style.textAlign', document.getElementById('bannerTextAlign').value);
|
textColor: document.getElementById('bannerTextColor').value,
|
||||||
formData.append('style.fontSize', document.getElementById('bannerFontSize').value);
|
textAlign: document.getElementById('bannerTextAlign').value,
|
||||||
formData.append('style.padding', document.getElementById('bannerPadding').value);
|
fontSize: document.getElementById('bannerFontSize').value || '16px',
|
||||||
formData.append('style.margin', document.getElementById('bannerMargin').value);
|
padding: document.getElementById('bannerPadding').value || '0px',
|
||||||
formData.append('style.borderRadius', document.getElementById('bannerBorderRadius').value);
|
margin: document.getElementById('bannerMargin').value || '0px',
|
||||||
formData.append('style.isVisible', document.getElementById('bannerVisible').checked);
|
borderRadius: document.getElementById('bannerBorderRadius').value || '0px',
|
||||||
|
isVisible: document.getElementById('bannerVisible').checked
|
||||||
|
};
|
||||||
|
|
||||||
|
// Convert style object to JSON string and append to form data
|
||||||
|
formData.append('style', JSON.stringify(style));
|
||||||
|
|
||||||
// Log form data for debugging
|
// Log form data for debugging
|
||||||
console.log('Odesílám data:');
|
console.log('Odesílám data:');
|
||||||
@@ -746,20 +750,19 @@
|
|||||||
console.log(key, value);
|
console.log(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new headers object
|
// Create headers object - DO NOT set Content-Type for FormData!
|
||||||
const headers = new Headers();
|
const headers = {};
|
||||||
// Don't set Content-Type header manually when using FormData
|
|
||||||
// The browser will set it automatically with the correct boundary
|
|
||||||
|
|
||||||
// Add Authorization header if token exists
|
// Add Authorization header if token exists
|
||||||
const token = localStorage.getItem('token');
|
const token = localStorage.getItem('token');
|
||||||
if (token) {
|
if (token) {
|
||||||
headers.append('Authorization', `Bearer ${token}`);
|
headers['Authorization'] = `Bearer ${token}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send request with FormData (browser will set correct Content-Type with boundary)
|
||||||
const response = await fetch('/api/banner/update', {
|
const response = await fetch('/api/banner/update', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: headers,
|
headers: headers, // No Content-Type header!
|
||||||
body: formData
|
body: formData
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user