Change encrypted URL format to /v1/e/{token}/img.{ext}
Add trailing filename to encrypted URLs for better browser compatibility. The filename is ignored by the server but helps browsers identify content type.
This commit is contained in:
@@ -154,8 +154,14 @@ func (s *Handlers) HandleGenerateURL() http.HandlerFunc {
|
|||||||
scheme = "http"
|
scheme = "http"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine file extension for the trailing filename
|
||||||
|
ext := format
|
||||||
|
if ext == "" || ext == "orig" {
|
||||||
|
ext = "jpg" // Default extension
|
||||||
|
}
|
||||||
|
|
||||||
host := r.Host
|
host := r.Host
|
||||||
generatedURL := scheme + "://" + host + "/v1/e/" + url.PathEscape(token)
|
generatedURL := scheme + "://" + host + "/v1/e/" + url.PathEscape(token) + "/img." + ext
|
||||||
|
|
||||||
// Format expiry for display
|
// Format expiry for display
|
||||||
expiresAtStr := "Never"
|
expiresAtStr := "Never"
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ import (
|
|||||||
"sneak.berlin/go/pixa/internal/imgcache"
|
"sneak.berlin/go/pixa/internal/imgcache"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HandleImageEnc handles requests to /v1/e/{token} for encrypted image URLs.
|
// HandleImageEnc handles requests to /v1/e/{token}/* for encrypted image URLs.
|
||||||
|
// The trailing path (e.g., /img.jpg) is ignored but helps browsers identify the content type.
|
||||||
func (s *Handlers) HandleImageEnc() http.HandlerFunc {
|
func (s *Handlers) HandleImageEnc() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ func (s *Server) SetupRoutes() {
|
|||||||
s.router.Head("/v1/image/*", s.h.HandleImage())
|
s.router.Head("/v1/image/*", s.h.HandleImage())
|
||||||
|
|
||||||
// Encrypted image URL route
|
// Encrypted image URL route
|
||||||
s.router.Get("/v1/e/{token}", s.h.HandleImageEnc())
|
// The trailing filename (e.g., /img.jpg) is ignored but helps browsers with content type
|
||||||
|
s.router.Get("/v1/e/{token}/*", s.h.HandleImageEnc())
|
||||||
|
|
||||||
// Metrics endpoint with auth
|
// Metrics endpoint with auth
|
||||||
if s.config.MetricsUsername != "" {
|
if s.config.MetricsUsername != "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user