Commit 96bba54
Eric Bower
·
2026-06-13 20:39:16 -0400 EDT
parent 668e3cf
fix(pgs): broken url for imgproxy integration
3 files changed,
+12,
-20
+1,
-16
| ... | ... | @@ -6,29 +6,14 @@ REGISTRY_URL=registry:5000 | |
| 6 | 6 | PICO_SECRET="" | |
| 7 | 7 | PICO_SECRET_WEBHOOK="" | |
| 8 | 8 | ||
| 9 | - | MINIO_CADDYFILE=./caddy/Caddyfile.minio | |
| 10 | - | MINIO_DOMAIN=minio.dev.pico.sh | |
| 11 | - | MINIO_EMAIL=hello@pico.sh | |
| 12 | - | MINIO_URL=http://minio:9000 | |
| 13 | - | MINIO_BROWSER_REDIRECT_URL=http://console.$MINIO_DOMAIN:9001 | |
| 14 | - | MINIO_ROOT_USER=miniosecret | |
| 15 | - | MINIO_ROOT_PASSWORD=miniosecret | |
| 16 | - | MINIO_PROMETHEUS_AUTH_TYPE=public | |
| 17 | - | MINIO_PROMETHEUS_URL= | |
| 18 | - | MINIO_PROMETHEUS_JOB_ID=minio | |
| 19 | - | ||
| 20 | 9 | IMGPROXY_DOMAIN=imgproxy.dev.pico.sh | |
| 21 | 10 | IMGPROXY_URL=http://imgproxy:8080 | |
| 22 | - | IMGPROXY_ALLOWED_SOURCES=s3://,local:// | |
| 11 | + | IMGPROXY_ALLOWED_SOURCES=local:// | |
| 23 | 12 | IMGPROXY_LOCAL_FILESYSTEM_ROOT=/storage | |
| 24 | - | IMGPROXY_USE_S3=true | |
| 25 | 13 | IMGPROXY_USE_LAST_MODIFIED=true | |
| 26 | 14 | IMGPROXY_USE_ETAG=true | |
| 27 | - | IMGPROXY_S3_ENDPOINT=http://minio:9000 | |
| 28 | 15 | IMGPROXY_KEY=6465616462656566 # deadbeef | |
| 29 | 16 | IMGPROXY_SALT=6465616462656566 # deadbeef | |
| 30 | - | AWS_ACCESS_KEY_ID=$MINIO_ROOT_USER | |
| 31 | - | AWS_SECRET_ACCESS_KEY=$MINIO_ROOT_PASSWORD | |
| 32 | 17 | IMGPROXY_PROMETHEUS_BIND=:8081 | |
| 33 | 18 | IMGPROXY_PROMETHEUS_NAMESPACE=imgproxy | |
| 34 | 19 |
+1,
-1
| ... | ... | @@ -153,7 +153,7 @@ func (h *ApiAssetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
| 153 | 153 | attempts = append(attempts, fpath) | |
| 154 | 154 | logger = logger.With("object", fpath) | |
| 155 | 155 | ||
| 156 | - | imgproxy := storage.NewImgProxy(fpath, h.ImgProcessOpts) | |
| 156 | + | imgproxy := storage.NewImgProxy(fmt.Sprintf("%s/%s", h.Bucket.Name, fpath), h.ImgProcessOpts) | |
| 157 | 157 | err = imgproxy.CanServe() | |
| 158 | 158 | if err == nil { | |
| 159 | 159 | logger.Info("serving image with imgproxy") |
+10,
-3
| ... | ... | @@ -25,13 +25,14 @@ type ImgProxy struct { | |
| 25 | 25 | } | |
| 26 | 26 | ||
| 27 | 27 | func NewImgProxy(fp string, opts *ImgProcessOpts) *ImgProxy { | |
| 28 | - | return &ImgProxy{ | |
| 28 | + | img := &ImgProxy{ | |
| 29 | 29 | url: os.Getenv("IMGPROXY_URL"), | |
| 30 | 30 | salt: os.Getenv("IMGPROXY_SALT"), | |
| 31 | 31 | key: os.Getenv("IMGPROXY_KEY"), | |
| 32 | 32 | filepath: fp, | |
| 33 | 33 | opts: opts, | |
| 34 | 34 | } | |
| 35 | + | return img | |
| 35 | 36 | } | |
| 36 | 37 | ||
| 37 | 38 | func (img *ImgProxy) CanServe() error { |
| ... | ... | @@ -90,7 +91,13 @@ func (img *ImgProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
| 90 | 91 | http.Error(w, msg, http.StatusInternalServerError) | |
| 91 | 92 | return | |
| 92 | 93 | } | |
| 93 | - | proxy := httputil.NewSingleHostReverseProxy(destUrl) | |
| 94 | + | proxy := &httputil.ReverseProxy{ | |
| 95 | + | Rewrite: func(r *httputil.ProxyRequest) { | |
| 96 | + | r.SetURL(destUrl) | |
| 97 | + | r.Out.URL.Path = destUrl.Path | |
| 98 | + | r.Out.URL.RawPath = destUrl.RawPath | |
| 99 | + | }, | |
| 100 | + | } | |
| 94 | 101 | proxy.ServeHTTP(w, r) | |
| 95 | 102 | } | |
| 96 | 103 |
| ... | ... | @@ -189,7 +196,7 @@ func (img *ImgProcessOpts) String() string { | |
| 189 | 196 | // Only 0, 90, 180, 270, etc., degree angles are supported. | |
| 190 | 197 | if img.Rotate != 0 { | |
| 191 | 198 | rot := img.Rotate | |
| 192 | - | if rot == 90 || rot == 180 || rot == 280 { | |
| 199 | + | if rot == 90 || rot == 180 || rot == 270 { | |
| 193 | 200 | processOpts = fmt.Sprintf( | |
| 194 | 201 | "%s/rotate:%d", | |
| 195 | 202 | processOpts, |