Use WebP if the browser supports it (#32)
This commit is contained in:
parent
f3ac0369b1
commit
b323b26b57
|
@ -138,6 +138,7 @@ rimgo can be configured using environment variables.
|
||||||
| PORT | 3000 |
|
| PORT | 3000 |
|
||||||
| ADDRESS | 0.0.0.0 |
|
| ADDRESS | 0.0.0.0 |
|
||||||
| IMGUR_CLIENT_ID | 546c25a59c58ad7 |
|
| IMGUR_CLIENT_ID | 546c25a59c58ad7 |
|
||||||
|
| FORCE_WEBP | 0 |
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,9 @@ package pages
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"codeberg.org/video-prize-ranch/rimgo/utils"
|
"codeberg.org/video-prize-ranch/rimgo/utils"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
|
@ -27,6 +29,12 @@ func handleMedia(c *fiber.Ctx, url string) error {
|
||||||
utils.SetHeaders(c)
|
utils.SetHeaders(c)
|
||||||
c.Set("Content-Security-Policy", "default-src 'none'; media-src 'self'; style-src 'self'; img-src 'self'; font-src 'self'; manifest-src 'self'; block-all-mixed-content")
|
c.Set("Content-Security-Policy", "default-src 'none'; media-src 'self'; style-src 'self'; img-src 'self'; font-src 'self'; manifest-src 'self'; block-all-mixed-content")
|
||||||
|
|
||||||
|
if os.Getenv("FORCE_WEBP") == "1" && c.Query("no_webp") != "" && c.Accepts("image/webp") == "image/webp" {
|
||||||
|
url = strings.ReplaceAll(url, ".png", ".webp")
|
||||||
|
url = strings.ReplaceAll(url, ".jpg", ".webp")
|
||||||
|
url = strings.ReplaceAll(url, ".jpeg", ".webp")
|
||||||
|
}
|
||||||
|
|
||||||
res, err := http.Get(url)
|
res, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue