This commit is contained in:
Tomáš Dvořák
2025-10-03 22:05:32 +02:00
parent f15b2b5630
commit eeff13d5bb
5 changed files with 63 additions and 22 deletions
+23 -10
View File
@@ -407,7 +407,7 @@ func listLogos(c *gin.Context) {
logo.HasSVG = hasSVG == 1
logo.HasPNG = hasPNG == 1
if logo.HasPNG {
logo.LogoURL = fmt.Sprintf("%s/logos/%s?format=png", baseURL, logo.ID)
} else if logo.HasSVG {
@@ -433,26 +433,39 @@ func uploadLogo(c *gin.Context) {
return
}
// Get club name from form (required)
// Read metadata from form
clubName := c.PostForm("club_name")
if clubName == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "club_name is required"})
return
}
// Optional fields
clubCity := c.PostForm("club_city")
clubType := c.PostForm("club_type")
clubWebsite := c.PostForm("club_website")
// Derive metadata if missing
if clubName == "" {
if club, err := facrClient.GetClub(id); err == nil && club != nil {
if club.Name != "" {
clubName = club.Name
}
if clubType == "" && club.Type != "" {
clubType = club.Type
}
if clubCity == "" && club.City != "" {
clubCity = club.City
}
if clubWebsite == "" && club.Website != "" {
clubWebsite = club.Website
}
}
if clubName == "" {
clubName = "Club " + id
}
}
// Get uploaded file
file, err := c.FormFile("file")
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "no file provided"})
return
}
// Validate file type
ext := strings.ToLower(filepath.Ext(file.Filename))
if ext != ".svg" && ext != ".png" && ext != ".pdf" {
c.JSON(http.StatusBadRequest, gin.H{"error": "only .svg, .png and .pdf files are allowed"})
+4 -5
View File
@@ -72,19 +72,18 @@
>
</div>
<!-- Club Name (Required) -->
<!-- Club Name (Optional) -->
<div>
<label class="block text-sm font-medium text-gray-400 mb-2">
Název Klubu <span class="text-red-500">*</span>
Název Klubu <span class="text-gray-500 text-xs">(volitelné)</span>
</label>
<input
type="text"
id="clubName"
required
placeholder="AC Sparta Praha"
class="w-full bg-dark-bg border border-dark-border rounded-lg px-4 py-3 text-white focus:outline-none focus:border-accent-blue transition-smooth"
>
<p class="text-xs text-gray-500 mt-1">Povinné: Nahrání bude zamítnuto bez názvu klubu</p>
<p class="text-xs text-gray-500 mt-1">Volitelné: Pokud název neuvedete, doplníme jej automaticky dle FAČR (podle UUID)</p>
</div>
<!-- Club Type -->
@@ -178,7 +177,7 @@
<div class="bg-red-900/20 border border-red-800 rounded-lg p-4 text-sm">
<p class="font-semibold text-red-400 mb-2">⚠️ Požadavky na nahrání:</p>
<ul class="list-disc list-inside space-y-1 text-red-300/80">
<li>Název klubu je povinný (automatické zamítnutí bez něj)</li>
<li>Název klubu je volitelný (doplníme dle FAČR podle UUID)</li>
<li>UUID klubu musí být platné</li>
<li>Akceptovány pouze SVG, PNG a PDF soubory</li>
<li>Doporučeno průhledné pozadí</li>
+1 -1
View File
@@ -52,7 +52,7 @@
<h1 id="clubName" class="text-4xl font-bold gradient-text mb-2"></h1>
<p id="clubMeta" class="text-gray-400"></p>
</div>
<a href="/admin.html" class="px-4 py-2 bg-accent-blue rounded-lg hover:bg-blue-600 transition-smooth">
<a id="editButton" href="/admin.html" class="px-4 py-2 bg-accent-blue rounded-lg hover:bg-blue-600 transition-smooth">
✏️ Upravit
</a>
</div>
+32 -5
View File
@@ -385,11 +385,6 @@ uploadForm.addEventListener('submit', async (e) => {
return
}
if (!clubName) {
showNotification('Název klubu je povinný', 'error')
return
}
if (selectedFiles.length === 0) {
showNotification('Vyberte prosím soubor loga', 'error')
return
@@ -508,6 +503,38 @@ console.log('🇨🇿 České Kluby Loga API - Administrace')
console.log('Backend API:', API_BASE_URL)
console.log('FAČR API:', FACR_API_URL)
// Prefill editing when navigated with ?id=<uuid>
try {
const params = new URLSearchParams(window.location.search)
const editId = params.get('id')
if (editId) {
// Fill UUID and show upload section
const uuidInput = document.getElementById('clubUuid')
uuidInput.value = editId
uploadSection.classList.remove('hidden')
uploadSection.scrollIntoView({ behavior: 'smooth', block: 'start' })
showNotification('Režim úprav pro existující logo', 'info')
// Load metadata to prefill fields
;(async () => {
try {
const resp = await fetch(`${API_BASE_URL}/logos/${editId}/json`)
if (resp.ok) {
const contentType = resp.headers.get('content-type') || ''
if (contentType.includes('application/json')) {
const data = await resp.json()
if (data.club_name) document.getElementById('clubName').value = data.club_name
if (data.club_type) document.getElementById('clubType').value = data.club_type
if (data.club_website) document.getElementById('clubWebsite').value = data.club_website
}
}
} catch (e) {
// Non-fatal
}
})()
}
} catch (_) {}
// Load from URL functionality
const loadFromUrlBtn = document.getElementById('loadFromUrl')
const logoUrlInput = document.getElementById('logoUrl')
+3 -1
View File
@@ -43,6 +43,8 @@ function displayLogoDetails(logo) {
logoDetail.classList.remove('hidden')
// Club Info
const editBtn = document.getElementById('editButton')
if (editBtn) editBtn.href = `/admin.html?id=${logoId}`
document.getElementById('clubName').textContent = logo.club_name
document.getElementById('clubMeta').textContent = `${logo.club_type || 'fotbal'}`
@@ -137,7 +139,7 @@ function displayLogoDetails(logo) {
document.getElementById('uploadDate').textContent = formatDate(logo.created_at)
// API URLs
const baseUrl = window.location.origin
const baseUrl = API_BASE_URL
document.getElementById('apiUrlDefault').textContent = `${baseUrl}/logos/${logo.id}`
document.getElementById('apiUrlJson').textContent = `${baseUrl}/logos/${logo.id}/json`