Files
pipu-music/services/api/internal/platform/httpx/request.go
T
mrleo1nidandClaude Opus 5.5 c05e523cbe
ci / api / api (push) Successful in 29s
ci / contract / contract (сгенерированный код совпадает с openapi.yaml) (push) Successful in 35s
ci / ts / ts (packages + web) (push) Failing after 49s
ci / mobile / mobile (Metro-бандл Android) (push) Successful in 1m1s
feat(api): streaming, transcoding, events, history and likes (M3)
- tracks carry a stream_url signed for the user for 12 h and the
  user's reaction; /stream checks the signature, expiry and that the
  user is not blocked, then hands the file to nginx by X-Accel-Redirect
  (or serves it with Range support when X_ACCEL=false)
- original by default; formats browsers can't play and explicit
  high/medium/low go through Opus transcoding, never upwards: a lossy
  source under the target bitrate stays original; transcodes are
  cached per file and size, deduplicated in flight, limited by
  TRANSCODE_CONCURRENCY and trimmed hourly by LRU to the size limit
- /events takes up to 500 events with client UUIDs, drops repeats and
  events older than 30 days, counts plays (≥ half or 4 min, or
  finished), early skips and history entries (≥ 30 s)
- history with clearing, likes and dislikes with cursors and totals,
  track reactions, playback state with last-write-wins, tracks batch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 07:25:15 +03:00

25 lines
882 B
Go

package httpx
import (
"context"
"net/http"
strictnethttp "github.com/oapi-codegen/runtime/strictmiddleware/nethttp"
)
type requestKey struct{}
// StrictRequest — middleware strict-сервера: кладёт *http.Request в контекст для обработчиков,
// которым нужен сам запрос (Range при отдаче файлов без nginx).
func StrictRequest(next strictnethttp.StrictHTTPHandlerFunc, _ string) strictnethttp.StrictHTTPHandlerFunc {
return func(ctx context.Context, w http.ResponseWriter, r *http.Request, req any) (any, error) {
return next(context.WithValue(ctx, requestKey{}, r), w, r, req)
}
}
// RequestFrom — исходный HTTP-запрос (nil вне strict-обработчика).
func RequestFrom(ctx context.Context) *http.Request {
r, _ := ctx.Value(requestKey{}).(*http.Request)
return r
}