Skip to content

Commit 6630a5a

Browse files
committed
CI: Apply Go linter recommendations to "internal/thumb/..." photoprism#5330
Signed-off-by: Michael Mayer <michael@photoprism.app>
1 parent 7c0f0b4 commit 6630a5a

File tree

9 files changed

+23
-16
lines changed

9 files changed

+23
-16
lines changed

internal/thumb/avatar/avatar.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ Additional information can be found in our Developer Guide:
2525
package avatar
2626

2727
import (
28-
_ "image/gif"
29-
_ "image/jpeg"
30-
_ "image/png"
28+
_ "image/gif" // register gif decoder
29+
_ "image/jpeg" // register jpeg decoder
30+
_ "image/png" // register png decoder
3131

32-
_ "golang.org/x/image/bmp"
33-
_ "golang.org/x/image/tiff"
34-
_ "golang.org/x/image/webp"
32+
_ "golang.org/x/image/bmp" // register bmp decoder
33+
_ "golang.org/x/image/tiff" // register tiff decoder
34+
_ "golang.org/x/image/webp" // register webp decoder
3535

3636
"github.com/photoprism/photoprism/internal/event"
3737
)

internal/thumb/avatar/download_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestSafeDownload_Succeeds(t *testing.T) {
6363
if err := SafeDownload(dest, ts.URL, &safe.Options{Timeout: 5 * time.Second, MaxSizeBytes: 1 << 20, AllowPrivate: true}); err != nil {
6464
t.Fatalf("unexpected error: %v", err)
6565
}
66-
b, err := os.ReadFile(dest)
66+
b, err := os.ReadFile(dest) //nolint:gosec // test reads temp file
6767
if err != nil {
6868
t.Fatalf("read: %v", err)
6969
}

internal/thumb/crop/errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ import (
55
)
66

77
var (
8+
// ErrNotFound indicates the requested crop size or option was not found.
89
ErrNotFound = errors.New("not found")
910
)

internal/thumb/crop/image.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,13 @@ func findIdealThumbFileName(hash string, width int, filePath string) (fileName s
154154
// Resolve symlinks.
155155
name, err := fs.Resolve(filepath.Join(filePath, fmt.Sprintf(thumbFileNames[i], hash)))
156156

157-
if err != nil || !fs.FileExists(name) {
157+
switch {
158+
case err != nil || !fs.FileExists(name):
158159
continue
159-
} else if s.Width < width {
160+
case s.Width < width:
160161
fileName = name
161162
continue
162-
} else {
163+
default:
163164
return name
164165
}
165166
}
@@ -176,7 +177,7 @@ func openIdealThumbFile(fileName, hash string, area Area, size Size) (result ima
176177

177178
if len(hash) != 40 || area.W <= 0 || size.Width <= 0 {
178179
// Not a standard thumb name with sha1 hash prefix.
179-
if imageBuffer, err := os.ReadFile(fileName); err != nil {
180+
if imageBuffer, err := os.ReadFile(fileName); err != nil { //nolint:gosec // file path comes from resolved thumbnails
180181
return nil, err
181182
} else {
182183
return imaging.Decode(bytes.NewReader(imageBuffer), imaging.AutoOrientation(true))
@@ -187,7 +188,7 @@ func openIdealThumbFile(fileName, hash string, area Area, size Size) (result ima
187188
fileName = name
188189
}
189190

190-
if imageBuffer, err := os.ReadFile(fileName); err != nil {
191+
if imageBuffer, err := os.ReadFile(fileName); err != nil { //nolint:gosec // file path comes from resolved thumbnails
191192
return nil, err
192193
} else {
193194
return imaging.Decode(bytes.NewReader(imageBuffer))

internal/thumb/crop/request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func FromRequest(hash, area string, size Size, thumbPath string) (fileName strin
3131
cropBase := fmt.Sprintf("%s_%dx%d_crop_%s%s", hash, size.Width, size.Height, area, fs.ExtJpeg)
3232
cropName := filepath.Join(filepath.Dir(thumbName), cropBase)
3333

34-
imageBuffer, err := os.ReadFile(thumbName)
34+
imageBuffer, err := os.ReadFile(thumbName) //nolint:gosec // thumbName resolved from validated cache path
3535

3636
if err != nil {
3737
return "", err

internal/thumb/crop/sizes.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package crop
33
import "github.com/photoprism/photoprism/internal/thumb"
44

55
var (
6+
// DefaultOptions are the resample options applied to most crop sizes.
67
DefaultOptions = []thumb.ResampleOption{thumb.ResampleFillCenter, thumb.ResampleDefault}
78
)
89

10+
// Size defines a thumbnail size and resample options.
911
type Size struct {
1012
Name Name `json:"name"`
1113
Source Name `json:"-"`
@@ -15,6 +17,7 @@ type Size struct {
1517
Options []thumb.ResampleOption `json:"-"`
1618
}
1719

20+
// SizeMap maps size names to size definitions.
1821
type SizeMap map[Name]Size
1922

2023
// Sizes contains the properties of all thumbnail sizes.

internal/thumb/frame/angle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ func RandomAngle(max float64) float64 {
2020

2121
r := 2 * max
2222

23-
return (rand.Float64() - 0.5) * r
23+
return (rand.Float64() - 0.5) * r //nolint:gosec // visual randomness only
2424
}

internal/thumb/frame/frame.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Additional information can be found in our Developer Guide:
2424
*/
2525
package frame
2626

27+
// Type defines the frame style identifier.
2728
type Type string
2829

30+
// Polaroid represents the Polaroid-style frame type.
2931
const Polaroid = "polaroid"

internal/thumb/frame/point.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ func RandomPoint(xMin, yMin, xMax, yMax int) image.Point {
1616
}
1717

1818
xDiff := float64(xMax - xMin)
19-
x := xMin + int(rand.Float64()*xDiff)
19+
x := xMin + int(rand.Float64()*xDiff) //nolint:gosec // visual randomness only
2020

2121
if yMin > yMax {
2222
yMin = yMax
2323
}
2424

2525
yDiff := float64(yMax - yMin)
26-
y := yMin + int(rand.Float64()*yDiff)
26+
y := yMin + int(rand.Float64()*yDiff) //nolint:gosec // visual randomness only
2727

2828
return image.Pt(x, y)
2929
}

0 commit comments

Comments
 (0)