httpshared

package
v0.100.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 10 Imported by: 0

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

View Source
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"
	ErrSharedDirNotConfig = "JACKUI_SHARED_DIR não configurado"
)

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.

View Source
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

func ListDirs(entries []os.DirEntry) []string

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

func NativeHLSParam(c *gin.Context) bool

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

func ParseIntOr(s string, def int) int

ParseIntOr parses s as an int, returning def when s is empty or invalid.

func PlaybackSession added in v0.98.2

func PlaybackSession(c *gin.Context) string

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

func PlaybackSessionSuffix(c *gin.Context) string

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

func SanitizeSubdir(subdir string) (string, error)

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

type PromoteDest struct {
	Name string `json:"name"`
	Path string `json:"path"`
}

PromoteDest represents a named promote destination (shared dir or extra).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL