mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 02:32:57 +00:00
de day #74
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user