diff --git a/filehandlers/imgs/img.go b/filehandlers/imgs/img.go index c62ffaa8..2223db18 100644 --- a/filehandlers/imgs/img.go +++ b/filehandlers/imgs/img.go @@ -83,7 +83,7 @@ func (h *UploadImgHandler) metaImg(data *PostMetaData) error { img, err := shared.GetImageForOptimization(tee, data.MimeType) finalName := shared.SanitizeFileExt(data.Filename) - if errors.Is(err, shared.AlreadyWebPError) { + if errors.Is(err, shared.ErrAlreadyWebPError) { h.Cfg.Logger.Infof("(%s) is already webp, skipping encoding", data.Filename) finalName = fmt.Sprintf("%s.webp", finalName) webpReader = tee diff --git a/shared/img.go b/shared/img.go index de760615..d618629d 100644 --- a/shared/img.go +++ b/shared/img.go @@ -40,8 +40,8 @@ type Ratio struct { Height int } -var AlreadyWebPError = errors.New("image is already webp") -var IsSvgError = errors.New("image is an svg") +var ErrAlreadyWebPError = errors.New("image is already webp") +var ErrIsSvgError = errors.New("image is an svg") func GetImageForOptimization(r io.Reader, mimeType string) (image.Image, error) { switch mimeType { @@ -54,7 +54,7 @@ func GetImageForOptimization(r io.Reader, mimeType string) (image.Image, error) case "image/gif": return gif.Decode(r) case "image/webp": - return nil, AlreadyWebPError + return nil, ErrAlreadyWebPError } return nil, fmt.Errorf("(%s) not supported for optimization", mimeType) diff --git a/shared/util.go b/shared/util.go index e00b7c52..a54d5c40 100644 --- a/shared/util.go +++ b/shared/util.go @@ -41,8 +41,12 @@ func FilenameToTitle(filename string, title string) string { func ToUpper(str string) string { pre := fnameRe.ReplaceAllString(str, " ") + r := []rune(pre) - r[0] = unicode.ToUpper(r[0]) + if len(r) > 0 { + r[0] = unicode.ToUpper(r[0]) + } + return string(r) }