Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
n0vad3v committed Jun 28, 2024
1 parent efcfdfb commit da00222
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tools-dir:

install-staticcheck: tools-dir
GOBIN=`pwd`/tools/bin go install honnef.co/go/tools/cmd/staticcheck@latest
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b ./tools/bin v1.52.2
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b ./tools/bin v1.59.1

static-check: install-staticcheck
#S1000,SA1015,SA4006,SA4011,S1023,S1034,ST1003,ST1005,ST1016,ST1020,ST1021
Expand All @@ -39,6 +39,5 @@ test:
clean:
rm -rf prefetch remote-raw exhaust tools coverage.txt metadata exhaust_test


docker:
DOCKER_BUILDKIT=1 docker build -t webpsh/webps .
10 changes: 9 additions & 1 deletion encoder/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,18 @@ func convertImage(rawPath, optimizedPath, imageType string, extraParams config.E
FailOnError: boolFalse,
NumPages: intMinusOne,
})
if err != nil {
log.Warnf("Can't open source image: %v", err)
return err
}
defer img.Close()

// Pre-process image(auto rotate, resize, etc.)
preProcessImage(img, imageType, extraParams)
err = preProcessImage(img, imageType, extraParams)
if err != nil {
log.Warnf("Can't pre-process source image: %v", err)
return err
}

switch imageType {
case "webp":
Expand Down
5 changes: 1 addition & 4 deletions helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ func CheckAllowedType(imgFilename string) bool {
}
imgFilenameExtension := strings.ToLower(path.Ext(imgFilename))
imgFilenameExtension = strings.TrimPrefix(imgFilenameExtension, ".") // .jpg -> jpg
if slices.Contains(config.Config.AllowedTypes, imgFilenameExtension) {
return true
}
return false
return slices.Contains(config.Config.AllowedTypes, imgFilenameExtension)
}

func GenOptimizedAbsPath(metadata config.MetaFile, subdir string) (string, string, string) {
Expand Down

0 comments on commit da00222

Please sign in to comment.