Add files via upload

This commit is contained in:
Tomáš Dvořák
2025-05-27 08:56:21 +02:00
committed by GitHub
parent 7c1b422797
commit 7e119ab943
5 changed files with 471 additions and 476 deletions
+17 -22
View File
@@ -710,6 +710,7 @@
}
}
// Save banner
async function saveBanner(event) {
event.preventDefault();
@@ -729,39 +730,33 @@
formData.append('text', document.getElementById('bannerText').value);
formData.append('link', document.getElementById('bannerLink').value);
// 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));
// 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);
// Log form data for debugging
console.log('Odesílám data:');
console.log('Odesílám data:');
for (let [key, value] of formData.entries()) {
console.log(key, value);
}
// Create headers object
const headers = {};
// 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
// Add Authorization header if token exists
const token = localStorage.getItem('token');
if (token) {
headers['Authorization'] = `Bearer ${token}`;
headers.append('Authorization', `Bearer ${token}`);
}
// Note: Don't set Content-Type header when using FormData with files
// The browser will set it automatically with the correct boundary
const response = await fetch('/api/banner/update', {
method: 'POST',
headers: headers,
@@ -1009,4 +1004,4 @@
document.addEventListener('DOMContentLoaded', loadBanner);
</script>
</body>
</html>
</html>