docs: вернуть стриминг документации из S3 через registry (v0.0.5)

This commit is contained in:
“Naeel”
2026-09-02 07:19:20 +03:00
parent 8bbb5adf21
commit 5e81c06124
2 changed files with 27 additions and 8 deletions
+26 -7
View File
@@ -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
}
+1 -1
View File
@@ -24,7 +24,7 @@ var (
s3Prefix = os.Getenv("S3_PREFIX")
)
const VERSION = "0.0.4"
const VERSION = "0.0.5"
func main() {
if hostname == "" {