From 5e81c0612401857fbfe76d7a510389a1ac3a8dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Wed, 2 Sep 2026 07:19:20 +0300 Subject: [PATCH] =?UTF-8?q?docs:=20=D0=B2=D0=B5=D1=80=D0=BD=D1=83=D1=82?= =?UTF-8?q?=D1=8C=20=D1=81=D1=82=D1=80=D0=B8=D0=BC=D0=B8=D0=BD=D0=B3=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=BA=D1=83=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=B8=D0=B7=20S3=20=D1=87=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B7=20registry=20(v0.0.5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/docs.go | 33 ++++++++++++++++++++++++++------- server/main.go | 2 +- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/server/docs.go b/server/docs.go index 0762e6a..3333514 100644 --- a/server/docs.go +++ b/server/docs.go @@ -3,11 +3,12 @@ package main import ( "context" "fmt" + "io" "log" + "mime" "net/http" "path/filepath" "strings" - "time" s3 "github.com/minio/minio-go/v7" ) @@ -75,18 +76,36 @@ func docsHandler(w http.ResponseWriter, r *http.Request) { var lastErr error for _, key := range candidates { - _, err := s3Client.StatObject(ctx, bucketName, key, s3.GetObjectOptions{}) + obj, err := s3Client.GetObject(ctx, bucketName, key, s3.GetObjectOptions{}) if err != nil { lastErr = err continue } + stat, err := obj.Stat() + if err != nil { + lastErr = err + _ = obj.Close() + continue + } - presigned, err := s3Client.PresignedGetObject(ctx, bucketName, key, 15*time.Minute, nil) - if err != nil { - lastErr = err - continue + ext := filepath.Ext(key) + ctype := mime.TypeByExtension(ext) + if ctype == "" { + if ext == ".html" || strings.HasSuffix(key, "index.html") { + ctype = "text/html; charset=utf-8" + } else { + ctype = "application/octet-stream" + } } - http.Redirect(w, r, presigned.String(), http.StatusFound) + + w.Header().Set("Content-Type", ctype) + w.Header().Set("Content-Length", fmt.Sprintf("%d", stat.Size)) + w.Header().Set("Last-Modified", stat.LastModified.Format(http.TimeFormat)) + + if _, err := io.Copy(w, obj); err != nil { + log.Printf("Error streaming object %s: %v", key, err) + } + _ = obj.Close() return } diff --git a/server/main.go b/server/main.go index b26c65e..1585f2d 100644 --- a/server/main.go +++ b/server/main.go @@ -24,7 +24,7 @@ var ( s3Prefix = os.Getenv("S3_PREFIX") ) -const VERSION = "0.0.4" +const VERSION = "0.0.5" func main() { if hostname == "" {