This commit is contained in:
Tomas Dvorak
2025-10-28 22:38:27 +01:00
parent 3d621e2187
commit 823fabee02
106 changed files with 9011 additions and 3930 deletions
+13 -2
View File
@@ -10,6 +10,7 @@ import (
"path/filepath"
"strings"
"fotbal-club/internal/config"
"fotbal-club/internal/models"
"fotbal-club/internal/services"
"fotbal-club/pkg/logger"
@@ -233,7 +234,11 @@ func (fc *FilesController) GetFileUsages(c *gin.Context) {
// ScanAndSyncFiles scans the uploads directory and syncs with database
func (fc *FilesController) ScanAndSyncFiles(c *gin.Context) {
uploadsDir := "uploads"
// Use configured uploads directory (normalized to absolute in main startup)
uploadsDir := config.AppConfig.UploadDir
if strings.TrimSpace(uploadsDir) == "" {
uploadsDir = "./uploads"
}
var filesInDB []models.UploadedFile
if err := fc.DB.Find(&filesInDB).Error; err != nil {
@@ -287,7 +292,13 @@ func (fc *FilesController) ScanAndSyncFiles(c *gin.Context) {
if !existsOriginal && !existsNormalized {
// File exists on disk but not in database - add it
mimeType := detectMimeType(path)
fileURL := "/" + filepath.ToSlash(path)
// Compute public URL under /uploads by making path relative to uploadsDir
rel, rerr := filepath.Rel(uploadsDir, path)
if rerr != nil {
// If for some reason file is outside base (symlink), skip
return nil
}
fileURL := "/uploads/" + filepath.ToSlash(rel)
newFile := models.UploadedFile{
Filename: filename,