Documentation
¶
Index ¶
- Variables
- func DeleteVideo(ctx context.Context, t core.TenantTx, rc *river.Client[pgx.Tx], id pgtype.UUID) error
- func EmitAsset(ctx context.Context, rc *river.Client[pgx.Tx], q tx, typ string, ...) error
- func EmitJob(ctx context.Context, rc *river.Client[pgx.Tx], q tx, typ string, ...) error
- func Hooks(d *core.Deps) transcoder.Hooks
- func LibraryPlayer(ctx context.Context, t core.TenantTx, id pgtype.UUID) ([]byte, error)
- func MinutesCommitted(ctx context.Context, t core.TenantTx, exclude pgtype.UUID) (float64, error)
- func Notices(ctx context.Context, t core.TenantTx, p core.Principal, now time.Time) ([]core.Notice, error)
- func PeriodicJobs() []*river.PeriodicJob
- func PlaybackCheck(ctx context.Context, d *core.Deps, tenant, asset pgtype.UUID) (map[string]any, error)
- func Routes(mux *http.ServeMux, d *core.Deps, o Options, player PlayerDocs) error
- func SetLibraryPlayer(ctx context.Context, t core.TenantTx, id pgtype.UUID, doc []byte) error
- func SourceKey(tenantID, assetID pgtype.UUID) string
- func StoredMinutes(ctx context.Context, pool *pgxpool.Pool) ([]db.StoredMinutesRow, error)
- func Technical(ctx context.Context, d *core.Deps, tenant, asset pgtype.UUID) (any, error)
- func Workers(w *river.Workers, d *core.Deps)
- type Access
- type AssetRef
- type AssetView
- type Chapter
- type CleanupArgs
- type Count
- type DefaultsView
- type DeletePrefixArgs
- type Distribution
- type FetchArgs
- type FolderView
- type ImageConvert
- type LibraryView
- type MakeDownloadArgs
- type ManagedCDN
- type MetaPair
- type Options
- type PlayerDocs
- type PosterView
- type PresetView
- type RenditionView
- type Stage
- type StatusCounts
- type TranscodingView
- type Viewing
Constants ¶
This section is empty.
Variables ¶
var CheckClient = &http.Client{Timeout: 15 * time.Second, CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}
CheckClient fetches from Ulka's own hosts for the playback check; tests replace it.
var FetchClient = func() *http.Client { c := core.PublicClient(0) c.CheckRedirect = func(_ *http.Request, via []*http.Request) error { if len(via) >= 5 { return errors.New("too many redirects") } return nil } return c }()
FetchClient follows a few redirects (signed storage links often redirect); every hop dials through the public-only check, so a redirect can't reach our own network. Tests replace it.
var PlaybackTTL = 30 * time.Second
PlaybackTTL is how long a ready video's playback facts are kept in memory: a viral video's viewers then cost the database one read per video per TTL instead of several per request. Signatures and country rules are still checked on every request; a workspace's own changes clear its entries at once (forgetting), others (an admin suspending the workspace, a download finishing in the worker, its CDN distribution going live) show within the TTL. Tests shorten it.
Functions ¶
func DeleteVideo ¶
func DeleteVideo(ctx context.Context, t core.TenantTx, rc *river.Client[pgx.Tx], id pgtype.UUID) error
DeleteVideo deletes a video for good, as DELETE /v1/assets/{id} does: asset.deleted is sent and its files go.
func Hooks ¶
func Hooks(d *core.Deps) transcoder.Hooks
Hooks is how the transcoder asks about videos and reports on them (transcoder.Hooks): this module keeps the records, the transcoder does the encoding, and neither reaches into the other's tables.
func LibraryPlayer ¶
LibraryPlayer is the player settings document a library stores (empty when it never set one); pgx.ErrNoRows when the library doesn't exist. The player module owns what the document means.
func MinutesCommitted ¶
MinutesCommitted is this month's encoded minutes plus videos accepted but not finished (except exclude), which will count when they do.
func Notices ¶
func Notices(ctx context.Context, t core.TenantTx, p core.Principal, now time.Time) ([]core.Notice, error)
Notices are videos that failed this week and the encoding limit nearing, for those who can read videos.
func PeriodicJobs ¶
func PeriodicJobs() []*river.PeriodicJob
func PlaybackCheck ¶
func PlaybackCheck(ctx context.Context, d *core.Deps, tenant, asset pgtype.UUID) (map[string]any, error)
PlaybackCheck plays one video as a player on another website would, read inside its tenant, for Ulka admin.
func SetLibraryPlayer ¶
SetLibraryPlayer stores a library's player settings document; pgx.ErrNoRows when the library doesn't exist.
func StoredMinutes ¶
StoredMinutes is every tenant's playable minutes, for the storage meter (across tenants, by a narrow function).
Types ¶
type Access ¶
type Access struct {
AllowedDomains []string `json:"allowed_domains"` // only these websites; empty for any
BlockedDomains []string `json:"blocked_domains"` // every website but these
CountryMode string `json:"country_mode"` // allow: everywhere but Countries; deny: only Countries
Countries []string `json:"countries"` // two-letter codes
}
Access is who may watch a library's videos (docs.ulka.co's referrer and country policies): by the website the player is on, and by the viewer's country. Signed tokens are the security; these keep casual copying out.
func (Access) CountryAllowed ¶
CountryAllowed checks the viewer's country. One the database can't place is allowed when the library allows by default and refused when it allows only some countries, except on this network. With no database the rule is off.
func (Access) WebsiteAllowed ¶
WebsiteAllowed checks the page the player is on (its address, from document.referrer) against the website lists.
type AssetRef ¶
type AssetRef = transcoder.AssetRef
AssetRef identifies the asset a job works on, and the public job it reports to; the transcoder carries it back.
type AssetView ¶
type AssetView struct {
ID pgtype.UUID `json:"id"`
Title string `json:"title"`
LibraryID pgtype.UUID `json:"library_id"`
FolderID pgtype.UUID `json:"folder_id"` // null: directly in Home
DeletedAt pgtype.Timestamptz `json:"deleted_at"` // set while the video is in the trash
Status string `json:"status"`
ErrorCode pgtype.Text `json:"error_code"`
Passthrough pgtype.Text `json:"passthrough"`
InputURL pgtype.Text `json:"input_url"` // where it was imported from; null when uploaded
Download pgtype.Text `json:"download"` // the MP4 download: null (off), preparing, ready or failed
DurationSeconds pgtype.Float8 `json:"duration_seconds"`
Width pgtype.Int4 `json:"width"`
Height pgtype.Int4 `json:"height"`
FrameRate *float64 `json:"frame_rate"` // frames per second once the video is read; null before
SizeBytes *int64 `json:"size_bytes"` // the original file's size once it has been read; null before
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
Renditions []RenditionView `json:"renditions"`
Progress map[string]Count `json:"progress"`
PlaybackPolicy string `json:"playback_policy"` // public, or signed: watching needs a signed address
PlaybackURL string `json:"playback_url"` // the HLS playlist on the player host (signed videos need a signature in front)
EmbedURL string `json:"embed_url"` // the watch page, for links and iframes
Description string `json:"description"`
Tags []string `json:"tags"`
Metadata []MetaPair `json:"metadata"`
Chapters []Chapter `json:"chapters"`
Poster PosterView `json:"poster"`
Timeline []Stage `json:"timeline"` // received, checked, playable, complete: each done, running, waiting or failed
}
AssetView is an asset as the API and webhooks show it: its state, planned renditions, encode progress and playback ids.
func AssetViews ¶
AssetViews builds views for many assets in two queries, however many assets there are.
type CleanupArgs ¶
type CleanupArgs struct{}
func (CleanupArgs) InsertOpts ¶
func (CleanupArgs) InsertOpts() river.InsertOpts
func (CleanupArgs) Kind ¶
func (CleanupArgs) Kind() string
type DefaultsView ¶
type DeletePrefixArgs ¶
type DeletePrefixArgs struct {
Prefix string `json:"prefix"`
}
func (DeletePrefixArgs) InsertOpts ¶
func (DeletePrefixArgs) InsertOpts() river.InsertOpts
func (DeletePrefixArgs) Kind ¶
func (DeletePrefixArgs) Kind() string
type Distribution ¶
type Distribution struct {
ID pgtype.UUID `json:"id"`
Name string `json:"name"`
Hostname string `json:"hostname"`
Active bool `json:"active"` // serving everywhere; until then segments come from the origin
}
Distribution is a managed CDN distribution as delivery shows it.
type FetchArgs ¶
FetchArgs imports a video from a URL: the worker downloads it to where an upload would land, then probes it.
func (FetchArgs) InsertOpts ¶
func (FetchArgs) InsertOpts() river.InsertOpts
type FolderView ¶
type FolderView struct {
ID pgtype.UUID `json:"id"`
ParentID pgtype.UUID `json:"parent_id"` // null: directly in Home
Name string `json:"name"`
Videos int32 `json:"videos"` // videos directly in it, not in folders below
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type ImageConvert ¶
type ImageConvert func(ctx context.Context, body []byte, width, quality int, ext string) ([]byte, error)
ImageConvert redraws a customer's picture as ext ("jpg" or "webp"), at most width wide (0 keeps its size), at quality (0 for the default). A file that isn't a picture is errNotAnImage; one too big is errImageTooLarge.
type LibraryView ¶
type LibraryView struct {
ID pgtype.UUID `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
IsDefault bool `json:"is_default"`
DefaultPlaybackPolicy string `json:"default_playback_policy"`
PresetTemplate string `json:"preset_template"` // the built-in preset in use, unless PresetID is set
PresetID pgtype.UUID `json:"preset_id"` // the workspace's own preset in use, or null
MP4Downloads bool `json:"mp4_downloads"`
Access
Inherits []string `json:"inherits"` // groups that follow the workspace's video defaults: player, transcoding, security
Videos int32 `json:"videos"`
Trashed int32 `json:"trashed"`
Minutes float64 `json:"minutes"`
StorageBytes int64 `json:"storage_bytes"` // source sizes of the live videos whose original still exists
ByStatus StatusCounts `json:"by_status"` // live videos by state
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type MakeDownloadArgs ¶
type MakeDownloadArgs struct {
TenantID pgtype.UUID `json:"tenant_id"`
AssetID pgtype.UUID `json:"asset_id"`
}
MakeDownloadArgs builds a video's MP4 download from its published HLS: the top rendition and the audio, decrypted and joined without encoding again. The encoded chunks are gone by then, so this works the same whether the download was asked for at upload or long after.
func (MakeDownloadArgs) InsertOpts ¶
func (MakeDownloadArgs) InsertOpts() river.InsertOpts
func (MakeDownloadArgs) Kind ¶
func (MakeDownloadArgs) Kind() string
type ManagedCDN ¶
type ManagedCDN interface {
// Create makes a distribution in the workspace that pulls from originHost, and returns its id.
Create(ctx context.Context, t core.TenantTx, originHost string) (pgtype.UUID, error)
// State is the distribution as it is now; false once it was deleted.
State(ctx context.Context, t core.TenantTx, id pgtype.UUID) (Distribution, bool, error)
}
ManagedCDN is a CDN an application built on ulka-vms runs for its workspaces (Ulka CDN, in Ulka). With one, delivery offers it in place of a workspace's own CDN.
type MetaPair ¶
A video's own words and labels (docs.ulka.co's names): metadata is key/value pairs an app attaches, like its own id; chapters mark parts of the video for the player's timeline.
type Options ¶
type Options struct {
ClickHouseURL string // where MP4 downloads are counted with delivery
Managed ManagedCDN // a CDN the application runs; nil offers the workspace's own CDN instead
ConvertImage ImageConvert // redraws uploaded covers; nil uses ffmpeg
}
Options are what an application built on ulka-vms adds to video; the zero value is ulka-vms on its own.
type PlayerDocs ¶
type PlayerDocs struct {
Clean func(raw []byte) ([]byte, error) // validates a document, returning the one to store
View func(stored []byte) any // the full settings a stored document means
// Config serves a video's config.json on the player host, once video has checked the viewer may watch.
Config func(w http.ResponseWriter, r *http.Request, v Viewing)
}
PlayerDocs is how the player module checks and shows the player settings document (video stores it, player owns its meaning).
type PosterView ¶
type PosterView struct {
Source string `json:"source"` // default, frame or upload
Time *float64 `json:"time"` // the frame's time in seconds; null for an upload or an unknown length
Suggestions []float64 `json:"suggestions"`
}
PosterView is a video's cover: the default frame, a frame chosen by time, or an uploaded picture; with the frames offered to choose from (empty until the video's length is known).
type PresetView ¶
type RenditionView ¶
type Stage ¶
type Stage struct {
Stage string `json:"stage"`
State string `json:"state"`
At *time.Time `json:"at"`
}
Stage is one step of a video's processing: done (with when, if known), running, waiting, or failed.
type StatusCounts ¶
type StatusCounts struct {
All int32 `json:"all"`
Ready int32 `json:"ready"`
Processing int32 `json:"processing"`
Errored int32 `json:"errored"`
}
StatusCounts: ready is `complete`; processing is waiting, processing and playable-but-finishing.
type TranscodingView ¶
type TranscodingView struct {
Templates []transcoder.Template `json:"templates"`
Presets []PresetView `json:"presets"`
ActiveKey string `json:"active_template"`
ActivePreset pgtype.UUID `json:"active_preset"`
QualityLevels []string `json:"-"`
}
TranscodingView is what a library's Transcoding page shows: the built-in templates, the workspace's own presets, and which one new videos use.
type Viewing ¶
type Viewing struct {
Title, Status, Policy string
DurationSeconds float64
Watermark string // from the viewer's verified signature
Access Access // which websites may embed it (countries are already checked)
Player []byte // the library's player settings document
Chapters []Chapter
Link func(file string) string // a file beside the video, with the viewer's signature when there is one
Poster string // the thumbnail's address, versioned by the choice so a new one shows at once
}
Viewing is what the player's config needs about a video a viewer may watch.
Source Files
¶
- access.go
- asset_actions.go
- assets.go
- cache.go
- captions.go
- cover.go
- defaults.go
- delivery.go
- details.go
- download.go
- events.go
- fetch.go
- folders.go
- images.go
- jobs.go
- libraries.go
- linkcheck.go
- module.go
- playback.go
- playcheck.go
- poster.go
- presets.go
- public.go
- report.go
- retention.go
- retention_worker.go
- technical.go
- timeline.go
- transcode.go
- tx.go
- upload.go
- uploadlock.go
- worker.go