mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-21 13:23:14 +01:00
Fix Windows Paths (#917)
* In theory this should fix the issue with Windows paths * Fix Windows path handling in file storage connections for non-default
This commit is contained in:
@@ -5,6 +5,15 @@ import (
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"image"
|
||||
"io"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/evanoberholster/imagemeta"
|
||||
"github.com/gen2brain/avif"
|
||||
"github.com/gen2brain/heic"
|
||||
@@ -16,13 +25,6 @@ import (
|
||||
"github.com/sysadminsmedia/homebox/backend/pkgs/utils"
|
||||
"github.com/zeebo/blake3"
|
||||
"golang.org/x/image/draw"
|
||||
"image"
|
||||
"io"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/sysadminsmedia/homebox/backend/internal/data/ent"
|
||||
@@ -100,13 +102,30 @@ func (r *AttachmentRepo) path(gid uuid.UUID, hash string) string {
|
||||
}
|
||||
|
||||
func (r *AttachmentRepo) GetConnString() string {
|
||||
// Handle the default case for file storage
|
||||
// which is file:///./ meaning relative to the current working directory
|
||||
if strings.HasPrefix(r.storage.ConnString, "file:///./") {
|
||||
dir, err := filepath.Abs(strings.TrimPrefix(r.storage.ConnString, "file:///./"))
|
||||
if runtime.GOOS == "windows" {
|
||||
dir = fmt.Sprintf("/%s", dir)
|
||||
}
|
||||
if err != nil {
|
||||
log.Err(err).Msg("failed to get absolute path for attachment directory")
|
||||
return r.storage.ConnString
|
||||
}
|
||||
return fmt.Sprintf("file://%s?no_tmp_dir=true", dir)
|
||||
return strings.ReplaceAll(fmt.Sprintf("file://%s?no_tmp_dir=true", dir), "\\", "/")
|
||||
} else if strings.HasPrefix(r.storage.ConnString, "file://") {
|
||||
// Handle the case for file storage with an absolute path
|
||||
// Convert Windows paths to a format compatible with fileblob
|
||||
// e.g. file:///C:/path/to/file becomes file:///C/path
|
||||
dir := strings.TrimPrefix(strings.ReplaceAll(r.storage.ConnString, "\\", "/"), "file://")
|
||||
if runtime.GOOS == "windows" {
|
||||
// Remove the colon from the drive letter (in case the user adds it)
|
||||
dir = strings.ReplaceAll(dir, ":", "")
|
||||
// Ensure the path starts with a slash for Windows compatibility
|
||||
dir = fmt.Sprintf("/%s", dir)
|
||||
}
|
||||
return fmt.Sprintf("file://%s", dir)
|
||||
}
|
||||
return r.storage.ConnString
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user