Config: Apply "golangci-lint" recommendation to customize package #5330

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer
2025-11-21 14:16:03 +01:00
parent b2448e5be0
commit 82b0ecea65
4 changed files with 24 additions and 12 deletions

View File

@@ -6,9 +6,14 @@ import (
)
var (
DefaultTheme = "default"
// DefaultTheme specifies the UI theme used when a user has not selected one.
DefaultTheme = "default"
// DefaultStartPage defines the default page shown after login.
DefaultStartPage = "default"
// DefaultMapsStyle is the map provider style used unless overridden by the user.
DefaultMapsStyle = "default"
DefaultLanguage = i18n.Default.Locale()
DefaultTimeZone = tz.Local
// DefaultLanguage is the fallback locale for the UI.
DefaultLanguage = i18n.Default.Locale()
// DefaultTimeZone is the default timezone applied to user sessions.
DefaultTimeZone = tz.Local
)

View File

@@ -1,13 +1,18 @@
package customize
// DownloadName represents the naming mode used when exporting or downloading files.
type DownloadName = string
const (
DownloadNameFile DownloadName = "file"
// DownloadNameFile keeps the original file name when downloading.
DownloadNameFile DownloadName = "file"
// DownloadNameOriginal restores the original filename from metadata when available.
DownloadNameOriginal DownloadName = "original"
DownloadNameShare DownloadName = "share"
// DownloadNameShare uses the public share identifier for downloaded files.
DownloadNameShare DownloadName = "share"
)
// DownloadNameDefault is the default naming mode for downloads.
var DownloadNameDefault = DownloadNameFile
// DownloadSettings represents content download settings.

View File

@@ -18,7 +18,9 @@ type ImportSettings struct {
// DefaultImportDest specifies the default import destination file path in the Originals folder.
// The date and time placeholders are described at https://pkg.go.dev/time#Layout.
var DefaultImportDest = "2006/01/20060102_150405_82F63B78.jpg"
var ImportDestRegexp = regexp.MustCompile("^(?P<name>\\D*\\d{2,14}[\\-/_].*\\d{2,14}.*)(?P<checksum>[0-9a-fA-F]{8})(?P<count>\\.\\d{1,6}|\\.COUNT)?(?P<ext>\\.[0-9a-zA-Z]{2,8})$")
// ImportDestRegexp matches valid destination patterns that include timestamp, checksum, and extension parts.
var ImportDestRegexp = regexp.MustCompile(`^(?P<name>\D*\d{2,14}[-/_].*\d{2,14}.*)(?P<checksum>[0-9a-fA-F]{8})(?P<count>\.\d{1,6}|\.COUNT)?(?P<ext>\.[0-9a-zA-Z]{2,8})$`)
// GetPath returns the default import source path, or a custom path if set.
func (s *ImportSettings) GetPath() string {

View File

@@ -3,6 +3,7 @@ package customize
import (
"fmt"
"os"
"path/filepath"
"gopkg.in/yaml.v2"
@@ -11,6 +12,7 @@ import (
"github.com/photoprism/photoprism/pkg/i18n"
)
// RootPath defines the default root directory used for import and index settings.
const (
RootPath = "/"
)
@@ -169,7 +171,9 @@ func (s *Settings) Load(fileName string) error {
return fmt.Errorf("settings file not found: %s", clean.Log(fileName))
}
yamlConfig, err := os.ReadFile(fileName)
name := filepath.Clean(fileName)
yamlConfig, err := os.ReadFile(name) // #nosec G304 -- file path is provided by the caller and validated above
if err != nil {
return err
@@ -198,9 +202,5 @@ func (s *Settings) Save(fileName string) error {
s.Propagate()
if err = os.WriteFile(fileName, data, fs.ModeConfigFile); err != nil {
return err
}
return nil
return os.WriteFile(fileName, data, fs.ModeConfigFile)
}