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