Documentation
¶
Index ¶
- Variables
- func RegisterRoutes(r modulekit.Mux, store *sessions.CookieStore, c *Controller, ...)
- func Wire(d modulekit.Deps) modulekit.Parts
- type Controller
- type Embed
- type Fetcher
- type Filter
- type Match
- type Provider
- type Repo
- type Service
- func (s *Service) Embeds(ctx context.Context, matches []Match) map[string]Embed
- func (s *Service) FetchPending(ctx context.Context) error
- func (s *Service) Resolve(ctx context.Context, m Match) (Embed, error)
- func (s *Service) SaveSettings(ctx context.Context, st Settings) error
- func (s *Service) Settings(ctx context.Context) Settings
- type Settings
Constants ¶
This section is empty.
Variables ¶
var Assets embed.FS
Assets - the module's templates/ and static/, built into the binary (modules.Assets, paths.SetModuleAssets): a site runs without the module's source directory.
Functions ¶
func RegisterRoutes ¶
func RegisterRoutes(r modulekit.Mux, store *sessions.CookieStore, c *Controller, admin func(http.Handler) http.Handler)
RegisterRoutes registers the settings page (behind admin) and the editor's check of a link (signed in, rate limited: it may ask a video service).
Types ¶
type Controller ¶
type Controller struct {
*modulekit.BaseController
// contains filtered or unexported fields
}
Controller - the module's settings page and the editor's check of a link.
func NewController ¶
func NewController(base *modulekit.BaseController, service *Service) *Controller
NewController creates a Controller.
func (*Controller) Resolve ¶
func (c *Controller) Resolve(w http.ResponseWriter, r *http.Request)
Resolve handles GET /api/video-embed?url=: the editor's "Video" button and cards (signed in). The service is asked once; afterwards the answer is the table's.
func (*Controller) SaveSettings ¶
func (c *Controller) SaveSettings(w http.ResponseWriter, r *http.Request)
SaveSettings handles POST /admin/config/video-embed.
func (*Controller) Settings ¶
func (c *Controller) Settings(w http.ResponseWriter, r *http.Request)
Settings renders GET /admin/config/video-embed: the services, the preview and the player's loading.
type Embed ¶
type Embed struct {
URL string
Provider string
Title string
ThumbnailURL string
ThumbnailFile string
Width int
Height int
Failed bool
FetchedAt time.Time
}
Embed - what a video's service says about it (oEmbed or Open Graph): Title, the preview (ThumbnailURL - the service's, ThumbnailFile - the site's copy, relative to the public files, "" - none), the player's proportions (0 - unknown); Failed - the service didn't answer (asked again after retryAfter).
type Fetcher ¶
type Fetcher struct {
// contains filtered or unexported fields
}
Fetcher asks a video's service about it (oEmbed, else its page's Open Graph tags) and copies its preview to the site.
func NewFetcher ¶
func NewFetcher() *Fetcher
NewFetcher creates a Fetcher keeping the previews under the public files' video_embed/.
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter turns the video links standing alone in a paragraph into the videos (the module's text filter).
func (*Filter) Apply ¶
Apply returns s with the video links standing alone in a paragraph made the videos; s itself when it has none.
func (*Filter) FieldFormatters ¶
func (f *Filter) FieldFormatters() []modulekit.FieldFormatter
FieldFormatters - the module's ways of showing a link field (modulekit.AddFieldFormatter): with the services' sites to offer as the field's allowed ones and the content form's preview of a link.
func (*Filter) TextFilter ¶
func (f *Filter) TextFilter() modulekit.TextFilter
TextFilter - the module's text filter, with the editor's "Video" button (modulekit.AddTextFilter).
type Match ¶
Match - a link recognized as a provider's video: URL as written, the player's address (PlayerAutoplay - starting at once), the proportions its link kind fixes (0 - none).
func MatchURL ¶
MatchURL recognizes link as a video of one of the providers on (on - by name); false - not a video link of theirs.
func (Match) PlayerAutoplay ¶
PlayerAutoplay - the player's address starting the video at once (a click on the preview asked for it).
type Provider ¶
type Provider struct {
Name string `json:"name"`
Label string `json:"label"`
Hosts string `json:"hosts"`
Sites []string `json:"sites"`
On bool `json:"on"`
URLs []providerURL `json:"urls"`
Player string `json:"player"`
Autoplay string `json:"autoplay"`
OEmbed string `json:"oembed"`
OpenGraph bool `json:"opengraph"`
ThumbnailHosts []string `json:"thumbnail_hosts"`
}
Provider - a video service (providers.json): Name - its machine name (the settings' list), Label, Hosts - what the settings page shows; Sites - the hosts of its links (a link field's allowed sites); On - on unless the settings say otherwise; URLs - the links to its videos; Player - the player's address, {id}/{oid} from the link; Autoplay - the query parameter starting it at once (after a click); OEmbed - the address of its oEmbed answer ({url} - the link), or OpenGraph - the video's page's Open Graph tags instead; ThumbnailHosts - the hosts (and their subdomains) its previews may come from.
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo - the module's tables.
func (*Repo) Embeds ¶
Embeds returns what's known about the links, by link (a link not asked about yet - absent).
func (*Repo) SaveEmbed ¶
SaveEmbed stores what the service said about the link (replacing what was known).
func (*Repo) SaveSettings ¶
SaveSettings saves the module's settings.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service knows the videos linked in texts: what's known in memory (a text is shown often), from the table otherwise; a link not known yet waits for the background job (FetchPending), the editor's "Video" button asks at once (Resolve).
func NewService ¶
NewService creates a Service.
func (*Service) Embeds ¶
Embeds returns what's known about the matched links; one not known (or failed long enough ago) is queued for FetchPending.
func (*Service) FetchPending ¶
FetchPending asks the services about the links waiting (up to fetchPerRun at a time) - the module's background job.
func (*Service) Resolve ¶
Resolve asks the service about the link now (the editor's button) and keeps the answer.
func (*Service) SaveSettings ¶
SaveSettings saves the settings.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ent - the video embed module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, scripts/migrations_gen.sh writes them), apart from the core's: the module's set of migrations (Schema).
|
Package ent - the video embed module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, scripts/migrations_gen.sh writes them), apart from the core's: the module's set of migrations (Schema). |
|
schema
Package schema - the video embed module's own ent schema: what the video services say about the videos linked in texts, and the module's settings.
|
Package schema - the video embed module's own ent schema: what the video services say about the videos linked in texts, and the module's settings. |
|
Package manifest declares the video embed module (its registry entry): a link to a video on its own line in a text shows as the video's player.
|
Package manifest declares the video embed module (its registry entry): a link to a video on its own line in a text shows as the video's player. |