diff --git a/server/main.go b/server/main.go index b4f607f..90f140f 100644 --- a/server/main.go +++ b/server/main.go @@ -24,7 +24,7 @@ var ( s3Prefix = os.Getenv("S3_PREFIX") ) -const VERSION = "0.0.2" +const VERSION = "0.0.3" func main() { if hostname == "" { diff --git a/server/proxy.go b/server/proxy.go index 82bf0b6..c1668f4 100644 --- a/server/proxy.go +++ b/server/proxy.go @@ -1,15 +1,9 @@ package main import ( - "context" - "fmt" - "io" - "log" "net/http" "strings" "time" - - s3 "github.com/minio/minio-go/v7" ) func proxyHandler(w http.ResponseWriter, r *http.Request) { @@ -24,32 +18,11 @@ func proxyHandler(w http.ResponseWriter, r *http.Request) { return } - ctx, cancel := context.WithTimeout(r.Context(), 60*time.Second) - defer cancel() - - obj, err := s3Client.GetObject(ctx, bucketName, key, s3.GetObjectOptions{}) + presigned, err := s3Client.PresignedGetObject(r.Context(), bucketName, key, 15*time.Minute, nil) if err != nil { - log.Printf("Error getting object %s/%s: %v", bucketName, key, err) - http.Error(w, "File not found", http.StatusNotFound) - return - } - defer obj.Close() - - stat, err := obj.Stat() - if err != nil { - log.Printf("Error stating object %s/%s: %v", bucketName, key, err) - http.Error(w, "File not found or not accessible", http.StatusNotFound) + http.Error(w, "Failed to sign object", http.StatusInternalServerError) return } - w.Header().Set("Content-Length", fmt.Sprintf("%d", stat.Size)) - w.Header().Set("Content-Type", "application/octet-stream") - w.Header().Set("Last-Modified", stat.LastModified.Format(http.TimeFormat)) - - written, err := io.Copy(w, obj) - if err != nil { - log.Printf("Error streaming object: %v (sent %d/%d bytes)", err, written, stat.Size) - } else { - log.Printf("Proxy: sent %d bytes for %s", written, key) - } + http.Redirect(w, r, presigned.String(), http.StatusFound) }