2 Commits

Author SHA1 Message Date
orangix
74782230ce allow external origin to access media files (#246)
closes #138

Reviewed-on: https://codeberg.org/rimgo/rimgo/pulls/246
Co-authored-by: orangix <uleo8b8g@anonaddy.me>
Co-committed-by: orangix <uleo8b8g@anonaddy.me>
2026-03-16 23:18:42 +01:00
orangix
a44272699f fix double WriteHeader call 2026-03-12 06:56:13 +01:00
2 changed files with 7 additions and 2 deletions

View File

@@ -34,6 +34,9 @@ func HandleUserAvatar(w http.ResponseWriter, r *http.Request) error {
func handleMedia(w http.ResponseWriter, r *http.Request, url string) error { func handleMedia(w http.ResponseWriter, r *http.Request, url string) error {
utils.SetHeaders(w) utils.SetHeaders(w)
if !utils.Config.RestrictiveCORS {
w.Header().Set("Access-Control-Allow-Origin", "*")
}
path := r.URL.Path path := r.URL.Path
if utils.Config.ForceWebp && if utils.Config.ForceWebp &&
@@ -84,6 +87,6 @@ func handleMedia(w http.ResponseWriter, r *http.Request, url string) error {
w.Header().Set("Content-Range", res.Header.Get("Content-Range")) w.Header().Set("Content-Range", res.Header.Get("Content-Range"))
} }
_, err = io.Copy(w, res.Body) io.Copy(w, res.Body)
return err return nil // don't call RenderError after this point
} }

View File

@@ -12,6 +12,7 @@ type config struct {
ProtocolDetection bool ProtocolDetection bool
Secure bool Secure bool
ForceWebp bool ForceWebp bool
RestrictiveCORS bool
ImageCache bool ImageCache bool
CleanupInterval time.Duration CleanupInterval time.Duration
CacheDir string CacheDir string
@@ -39,6 +40,7 @@ func LoadConfig() {
ProtocolDetection: envBool("PROTOCOL_DETECTION"), ProtocolDetection: envBool("PROTOCOL_DETECTION"),
Secure: envBool("SECURE"), Secure: envBool("SECURE"),
ForceWebp: envBool("FORCE_WEBP"), ForceWebp: envBool("FORCE_WEBP"),
RestrictiveCORS: envBool("RESTRICTIVE_CORS"),
Privacy: map[string]interface{}{ Privacy: map[string]interface{}{
"set": os.Getenv("PRIVACY_NOT_COLLECTED") != "", "set": os.Getenv("PRIVACY_NOT_COLLECTED") != "",
"policy": os.Getenv("PRIVACY_POLICY"), "policy": os.Getenv("PRIVACY_POLICY"),