use quality param

This commit is contained in:
Niko Storni 2021-07-19 20:14:42 +02:00
parent 11b1fe3b99
commit eb6418bc97

11
main.go
View file

@ -16,6 +16,7 @@ import (
"os/user" "os/user"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strconv"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -107,6 +108,7 @@ func view(c *gin.Context) {
} }
height := c.Query("height") height := c.Query("height")
width := c.Query("width") width := c.Query("width")
quality := c.Query("quality")
url = strings.TrimLeft(url, "/") url = strings.TrimLeft(url, "/")
if url == "" { if url == "" {
@ -119,7 +121,14 @@ func view(c *gin.Context) {
if height != "" && width != "" { if height != "" && width != "" {
redirectBaseURL = "" redirectBaseURL = ""
//resizeParams = fmt.Sprintf("&height=%s&width=%s&quality=80", height, width) //resizeParams = fmt.Sprintf("&height=%s&width=%s&quality=80", height, width)
redirectBaseURL = fmt.Sprintf("https://image-processor.vanwanet.com/optimize/s:%s:%s/quality:80/plain/https://cdn.lbryplayer.xyz/speech/", width, height) desiredQuality := 80
if quality != "" {
q, err := strconv.ParseInt(quality, 10, 32)
if err == nil && q < 100 {
desiredQuality = int(q)
}
}
redirectBaseURL = fmt.Sprintf("https://image-processor.vanwanet.com/optimize/s:%s:%s/quality:%d/plain/https://cdn.lbryplayer.xyz/speech/", width, height, desiredQuality)
} }
c.Header("Cache-Control", "max-age=604800") c.Header("Cache-Control", "max-age=604800")
if parts := regexp.MustCompile(`^(view/)?([a-f0-9]+)/(.*?)\.(.*)$`).FindStringSubmatch(url); parts != nil { if parts := regexp.MustCompile(`^(view/)?([a-f0-9]+)/(.*?)\.(.*)$`).FindStringSubmatch(url); parts != nil {