Skip to content

Commit

Permalink
fix: serve webp from jpg
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc committed Dec 21, 2024
1 parent 39a024b commit efae88e
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"path"
"path/filepath"
"strconv"
"strings"

"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/smithy-go"
Expand Down Expand Up @@ -83,14 +82,23 @@ type Handle struct {
uncachedRequestHist prometheus.Histogram
}

func (h Handle) fetchRawImage(ctx context.Context, p string, hd bool) ([]byte, string, error) {
s3Path := strings.TrimPrefix(p, "pic/")
if hd {
s3Path = "hd/" + s3Path
func convertWebpToJpgPath(p string) string {
if filepath.Ext(p) == ".webp" {
return p[:len(p)-len(".webp")] + ".jpg"
}
return p
}

func (h Handle) fetchRawImage(ctx context.Context, p string, hd bool) ([]byte, string, error) {
// s3Path := strings.TrimPrefix(p, "pic/")
// if hd {
// s3Path = "hd/" + s3Path
// }

imagePath := convertWebpToJpgPath(p)

// 生产环境走的是内网,不能用 https
sourceURL := "http://lain.bgm.tv/" + p
sourceURL := "http://lain.bgm.tv/" + imagePath
if hd {
sourceURL += "?hd=1"
}
Expand Down

0 comments on commit efae88e

Please sign in to comment.