29 lines
645 B
Go
29 lines
645 B
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func proxyHandler(w http.ResponseWriter, r *http.Request) {
|
|
key := r.URL.Query().Get("key")
|
|
|
|
if key == "" {
|
|
http.Error(w, "Missing key param", http.StatusBadRequest)
|
|
return
|
|
}
|
|
if !strings.HasPrefix(key, s3Prefix+"/") && !strings.HasPrefix(key, "docs/") {
|
|
http.Error(w, "Forbidden", http.StatusForbidden)
|
|
return
|
|
}
|
|
|
|
presigned, err := s3Client.PresignedGetObject(r.Context(), bucketName, key, 15*time.Minute, nil)
|
|
if err != nil {
|
|
http.Error(w, "Failed to sign object", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
http.Redirect(w, r, presigned.String(), http.StatusFound)
|
|
}
|