fix(uploads): serve private previews through API and show batch cover status
ci / mobile / mobile (Metro-бандл Android) (push) Successful in 1m30s
ci / ts / ts (packages + web) (push) Canceled after 4m13s
ci / module boundaries / boundaries (push) Successful in 8s
ci / api / api (push) Successful in 56s
ci / contract / contract (сгенерированный код совпадает с openapi.yaml) (push) Successful in 1m1s
ci / db / db (push) Successful in 1m7s
ci / mobile / mobile (Metro-бандл Android) (push) Successful in 1m30s
ci / ts / ts (packages + web) (push) Canceled after 4m13s
ci / module boundaries / boundaries (push) Successful in 8s
ci / api / api (push) Successful in 56s
ci / contract / contract (сгенерированный код совпадает с openapi.yaml) (push) Successful in 1m1s
ci / db / db (push) Successful in 1m7s
This commit is contained in:
1 parent
37e33c656b
commit
7d62531c02
15 files changed
+533
-410
No files matched your search
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -15,23 +14,17 @@ import (
|
||||
"pipu/api/internal/platform/httpx"
|
||||
)
|
||||
|
||||
// uploadStream — отдача файла staging с Range (сам api или X-Accel-Redirect).
|
||||
// uploadStream serves private staging files through the API with Range support.
|
||||
// Nginx runs as another user and cannot read tus files (0750 directories, 0640 files).
|
||||
type uploadStream struct {
|
||||
req *http.Request
|
||||
file string
|
||||
format string
|
||||
accel string
|
||||
xAccel bool
|
||||
}
|
||||
|
||||
func (s uploadStream) VisitStreamUploadResponse(w http.ResponseWriter) error {
|
||||
w.Header().Set("Content-Type", contentType(s.format))
|
||||
w.Header().Set("Cache-Control", "private, max-age=600")
|
||||
if s.xAccel && s.accel != "" {
|
||||
w.Header().Set("X-Accel-Redirect", s.accel)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
return nil
|
||||
}
|
||||
f, err := os.Open(s.file)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -69,8 +62,7 @@ func (h *Handler) StreamUpload(ctx context.Context, req gen.StreamUploadRequestO
|
||||
format = *f.Format
|
||||
}
|
||||
return uploadStream{
|
||||
req: httpx.RequestFrom(ctx), file: f.Abs, format: format, xAccel: h.xAccel,
|
||||
accel: "/_internal/uploads/" + filepath.ToSlash(f.StagingPath),
|
||||
req: httpx.RequestFrom(ctx), file: f.Abs, format: format,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user