Skip to content

Commit 82b0ece

Browse files
committed
Config: Apply "golangci-lint" recommendation to customize package photoprism#5330
Signed-off-by: Michael Mayer <[email protected]>
1 parent b2448e5 commit 82b0ece

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

internal/config/customize/defaults.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ import (
66
)
77

88
var (
9-
DefaultTheme = "default"
9+
// DefaultTheme specifies the UI theme used when a user has not selected one.
10+
DefaultTheme = "default"
11+
// DefaultStartPage defines the default page shown after login.
1012
DefaultStartPage = "default"
13+
// DefaultMapsStyle is the map provider style used unless overridden by the user.
1114
DefaultMapsStyle = "default"
12-
DefaultLanguage = i18n.Default.Locale()
13-
DefaultTimeZone = tz.Local
15+
// DefaultLanguage is the fallback locale for the UI.
16+
DefaultLanguage = i18n.Default.Locale()
17+
// DefaultTimeZone is the default timezone applied to user sessions.
18+
DefaultTimeZone = tz.Local
1419
)

internal/config/customize/download.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package customize
22

3+
// DownloadName represents the naming mode used when exporting or downloading files.
34
type DownloadName = string
45

56
const (
6-
DownloadNameFile DownloadName = "file"
7+
// DownloadNameFile keeps the original file name when downloading.
8+
DownloadNameFile DownloadName = "file"
9+
// DownloadNameOriginal restores the original filename from metadata when available.
710
DownloadNameOriginal DownloadName = "original"
8-
DownloadNameShare DownloadName = "share"
11+
// DownloadNameShare uses the public share identifier for downloaded files.
12+
DownloadNameShare DownloadName = "share"
913
)
1014

15+
// DownloadNameDefault is the default naming mode for downloads.
1116
var DownloadNameDefault = DownloadNameFile
1217

1318
// DownloadSettings represents content download settings.

internal/config/customize/import.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ type ImportSettings struct {
1818
// DefaultImportDest specifies the default import destination file path in the Originals folder.
1919
// The date and time placeholders are described at https://pkg.go.dev/time#Layout.
2020
var DefaultImportDest = "2006/01/20060102_150405_82F63B78.jpg"
21-
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})$")
21+
22+
// ImportDestRegexp matches valid destination patterns that include timestamp, checksum, and extension parts.
23+
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})$`)
2224

2325
// GetPath returns the default import source path, or a custom path if set.
2426
func (s *ImportSettings) GetPath() string {

internal/config/customize/settings.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package customize
33
import (
44
"fmt"
55
"os"
6+
"path/filepath"
67

78
"gopkg.in/yaml.v2"
89

@@ -11,6 +12,7 @@ import (
1112
"github.com/photoprism/photoprism/pkg/i18n"
1213
)
1314

15+
// RootPath defines the default root directory used for import and index settings.
1416
const (
1517
RootPath = "/"
1618
)
@@ -169,7 +171,9 @@ func (s *Settings) Load(fileName string) error {
169171
return fmt.Errorf("settings file not found: %s", clean.Log(fileName))
170172
}
171173

172-
yamlConfig, err := os.ReadFile(fileName)
174+
name := filepath.Clean(fileName)
175+
176+
yamlConfig, err := os.ReadFile(name) // #nosec G304 -- file path is provided by the caller and validated above
173177

174178
if err != nil {
175179
return err
@@ -198,9 +202,5 @@ func (s *Settings) Save(fileName string) error {
198202

199203
s.Propagate()
200204

201-
if err = os.WriteFile(fileName, data, fs.ModeConfigFile); err != nil {
202-
return err
203-
}
204-
205-
return nil
205+
return os.WriteFile(fileName, data, fs.ModeConfigFile)
206206
}

0 commit comments

Comments
 (0)