Documentation
¶
Overview ¶
Package httpshared holds the leaf HTTP helpers shared between package handlers and its subpackage handlers/local. It exists to break the bidirectional import cycle: local handlers need a few HLS/transcode/promote helpers that used to live in package handlers, while handlers needs the local mount/scoping helpers. Everything here is self-contained (depends only on gin, the stdlib and internal/transcode) so both sides can import it without either importing the other.
Index ¶
- Constants
- func EnsureVODSegment(sess *transcode.HLSSession, segName string)
- func ListDirs(entries []os.DirEntry) []string
- func NativeHLSParam(c *gin.Context) bool
- func ParseIntOr(s string, def int) int
- func PlaybackSession(c *gin.Context) string
- func PlaybackSessionSuffix(c *gin.Context) string
- func ResolveTargetBase(targetBase, sharedDir string, dests []PromoteDest) (string, error)
- func SanitizeSubdir(subdir string) (string, error)
- func ServeSegment(c *gin.Context, sess *transcode.HLSSession, segName string)
- type PromoteDest
Constants ¶
const ( CacheControl = "Cache-Control" ContentType = "Content-Type" HeaderAuthorization = "Authorization" MIMEJPEG = "image/jpeg" MIMEMPEGURL = "application/vnd.apple.mpegurl" MIMEVTT = "text/vtt; charset=utf-8" CachePublicDay = "public, max-age=86400" CachePublicYear = "public, max-age=31536000" CacheNoStore = "no-store" CacheImmutable = "public, max-age=86400, immutable" ErrFileNotFound = "file not found" ErrPathIsDir = "path is a directory" ErrInvalidData = "dados inválidos" )
HTTP/MIME/cache and error-message constants shared by package handlers and its handlers/local subpackage. They live here (not in package handlers) so local can reference them without importing handlers, which would re-create the import cycle. Constants used by only one side stay in their own package.
const HLSVODSegDur = 4
HLSVODSegDur must match transcode.hlsSegDur — the segment length the encoder targets with forced keyframes. The synthesised playlist declares each segment as this long so Safari's timeline (sum of EXTINF) matches the media.
Variables ¶
This section is empty.
Functions ¶
func EnsureVODSegment ¶
func EnsureVODSegment(sess *transcode.HLSSession, segName string)
EnsureVODSegment forces the encoder to produce segName if the session is in VOD mode and the segment isn't on disk yet (seek-restart on demand).
func ListDirs ¶
ListDirs returns the sorted names of the non-hidden subdirectories in entries. Always non-nil so a folder with no subdirs serializes as JSON [] (not null): the UI does `dirs.length` on the result.
func NativeHLSParam ¶
NativeHLSParam reads the client-class flag the frontend appends to HLS URLs (1 = Safari/iOS native HLS). Drives the VOD policy + session keying.
func ParseIntOr ¶
ParseIntOr parses s as an int, returning def when s is empty or invalid.
func PlaybackSession ¶ added in v0.98.2
PlaybackSession returns a filesystem-safe, client-generated playback ID. It is deliberately separate from authentication: its only purpose is to isolate HLS encoders when different viewers seek through the same media.
func PlaybackSessionSuffix ¶ added in v0.98.2
PlaybackSessionSuffix returns the stable session-key suffix for this playback, or empty for legacy clients that do not send a playback ID.
func ResolveTargetBase ¶
func ResolveTargetBase(targetBase, sharedDir string, dests []PromoteDest) (string, error)
ResolveTargetBase resolves a targetBase string against the list of destinations. If targetBase is empty, returns sharedDir (default). Returns error if targetBase doesn't match any destination path.
func SanitizeSubdir ¶
SanitizeSubdir valida o subdir digitado pelo usuário pra não escapar do sharedDir via "..", caminhos absolutos. Retorna o caminho limpo (Clean) ou erro descritivo.
func ServeSegment ¶
func ServeSegment(c *gin.Context, sess *transcode.HLSSession, segName string)
ServeSegment waits for the requested .ts segment (up to 30s) and streams it.
Types ¶
type PromoteDest ¶
PromoteDest represents a named promote destination (shared dir or extra).