add: /uploaded_dicom for pydicom-google-upload to get shortlink

This commit is contained in:
mario
2025-05-16 10:36:19 +07:00
parent 28339e855c
commit 36417fe515
7 changed files with 283 additions and 15 deletions

View File

@@ -0,0 +1,32 @@
package middleware
import (
"net/http"
"go.uber.org/zap"
)
// PydicomAPIKey validates requests to pydicom endpoints by checking the API key
func PydicomAPIKey(apiKey string, logger *zap.Logger) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Check if the API key header is present
providedKey := r.Header.Get("X-PYDICOM-API-KEY")
if providedKey == "" {
logger.Warn("API key missing from PYDICOM request")
http.Error(w, "API key required", http.StatusUnauthorized)
return
}
// Validate the API key
if providedKey != apiKey {
logger.Warn("Invalid API key for PYDICOM request")
http.Error(w, "Invalid API key", http.StatusUnauthorized)
return
}
// API key is valid, proceed to the next handler
next.ServeHTTP(w, r)
})
}
}