Documentation ¶
Index ¶
- Constants
- type Authenticator
- type CloudflareService
- type CloudflareVideoInfo
- type Config
- type Controller
- func (c *Controller) DeleteVideo(gCtx *gin.Context)
- func (c *Controller) GetVideoInfo(gCtx *gin.Context)
- func (c *Controller) HandleMethodNotAllowed(gCtx *gin.Context)
- func (c *Controller) ListUserVideos(gCtx *gin.Context)
- func (c *Controller) RegisterL402Routes(router *gin.Engine)
- func (c *Controller) RegisterProtectedRoutes(router *gin.Engine)
- func (c *Controller) RegisterPublicRoutes(router *gin.Engine)
- func (c *Controller) StreamVideo(gCtx *gin.Context)
- func (c *Controller) StreamVideoGET(gCtx *gin.Context)
- func (c *Controller) UpdateVideoInfo(gCtx *gin.Context)
- func (c *Controller) UploadVideo(gCtx *gin.Context)
- type CreateVideoParams
- type Manager
- func (m *Manager) CreateL402Challenge(ctx context.Context, pubKeyHex string, externalID string) (*l402.Challenge, error)
- func (m *Manager) DeleteVideo(ctx context.Context, externalID string) error
- func (m *Manager) GenerateStreamURL(ctx context.Context, externalID string) (string, string, error)
- func (m *Manager) GenerateVideoUploadURL(ctx context.Context) (string, string, error)
- func (m *Manager) IsVideoReady(ctx context.Context, externalID string) error
- func (m *Manager) PrepareVideoUpload(ctx context.Context, userID int64, req UploadVideoRequest) (string, string, error)
- func (m *Manager) ProcessAndUploadCoverImage(gCtx context.Context, externalID string, ...) (string, error)
- func (m *Manager) RecordPurchaseAndView(ctx context.Context, externalID, paymentHash, serviceType string) error
- func (m *Manager) UpdateVideoInfo(ctx context.Context, externalID string, req UpdateVideoInfoRequest) (*Video, error)
- type NotificationService
- type OrdersMgr
- type Store
- type StreamVideoRequest
- type UpdateVideoInfoParams
- type UpdateVideoInfoRequest
- type UploadVideoRequest
- type UploadVideoResponse
- type ValidatorFunc
- type Video
Constants ¶
const ( // ExpirationTime is the time after which a macaroon expires. ExpirationTime = 24 * time.Hour * 30 * 12 // 12 months )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authenticator ¶
type Authenticator interface { ValidateSignature(pubKeyHex, signatureHex, domain string, timestamp int64) error NewChallenge(ctx context.Context, domain, pubKeyHex string, priceInCents uint64, caveats map[string]string) (*l402.Challenge, error) ValidateL402Credentials(ctx context.Context, authHeader string) (string, error) }
type CloudflareService ¶
type CloudflareService interface { GetStreamVideoInfo(ctx context.Context, externalID string) (*cloudflare.StreamVideo, error) GenerateVideoUploadURL(ctx context.Context) (string, string, error) UploadPublicFile(ctx context.Context, key, prefix string, reader io.ReadSeeker) (string, error) GenerateStreamURL(ctx context.Context, externalID string) (string, string, error) }
type CloudflareVideoInfo ¶
type Config ¶
type Config struct { L402BaseURL string `long:"l402_base_url" description:"L402 base URL"` L402InfoURI string `long:"l402_info_uri" description:"L402 info URI"` }
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns all default values for the Config struct.
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
func NewController ¶
func NewController(videosMgr *Manager, authenticator Authenticator, store Store, logger *slog.Logger, cfg *Config) *Controller
func (*Controller) DeleteVideo ¶
func (c *Controller) DeleteVideo(gCtx *gin.Context)
func (*Controller) GetVideoInfo ¶
func (c *Controller) GetVideoInfo(gCtx *gin.Context)
GetVideoInfo returns the L402 stream information for a given video
func (*Controller) HandleMethodNotAllowed ¶
func (c *Controller) HandleMethodNotAllowed(gCtx *gin.Context)
Add this new method to the Controller
func (*Controller) ListUserVideos ¶
func (c *Controller) ListUserVideos(gCtx *gin.Context)
func (*Controller) RegisterL402Routes ¶
func (c *Controller) RegisterL402Routes(router *gin.Engine)
func (*Controller) RegisterProtectedRoutes ¶
func (c *Controller) RegisterProtectedRoutes(router *gin.Engine)
func (*Controller) RegisterPublicRoutes ¶
func (c *Controller) RegisterPublicRoutes(router *gin.Engine)
func (*Controller) StreamVideo ¶
func (c *Controller) StreamVideo(gCtx *gin.Context)
func (*Controller) StreamVideoGET ¶
func (c *Controller) StreamVideoGET(gCtx *gin.Context)
func (*Controller) UpdateVideoInfo ¶
func (c *Controller) UpdateVideoInfo(gCtx *gin.Context)
func (*Controller) UploadVideo ¶
func (c *Controller) UploadVideo(gCtx *gin.Context)
type CreateVideoParams ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is the main video service interface.
func NewManager ¶
func NewManager(orders OrdersMgr, cf CloudflareService, authenticator Authenticator, store Store, logger *slog.Logger, clock utils.Clock) *Manager
NewManager creates a new storage service.
func (*Manager) CreateL402Challenge ¶
func (m *Manager) CreateL402Challenge(ctx context.Context, pubKeyHex string, externalID string) (*l402.Challenge, error)
CreateChallenge creates a new L402 challenge for downloading a file from our storage service.
func (*Manager) DeleteVideo ¶
func (*Manager) GenerateStreamURL ¶
func (*Manager) GenerateVideoUploadURL ¶
func (*Manager) IsVideoReady ¶
updateVideoIfNeeded retrieves the video info from cloudflare and updates the video in the database if the video is not ready to stream. When uploaded videos are set as not ready to stream by default.
func (*Manager) PrepareVideoUpload ¶
func (*Manager) ProcessAndUploadCoverImage ¶
func (*Manager) RecordPurchaseAndView ¶
func (*Manager) UpdateVideoInfo ¶
type NotificationService ¶
type NotificationService interface { // RegisterNewPurchaseEvent sends a notification for a new purchase. RegisterNewPurchaseEvent(externalID, paymentHash, email string) error // RegisterNewVideoUploadEvent sends a notification for a new video upload. RegisterNewVideoUploadEvent(externalID, email string) error }
NotificationService is the interface for sending notifications.
type OrdersMgr ¶
type OrdersMgr interface { // CreateOffer creates a new offer. CreateOffer(ctx context.Context, userID int64, PriceInCents uint64, externalID, paymentHash string) error // RecordPurchase creates a new purchase if there is not one already for // the given payment hash. RecordPurchase(ctx context.Context, paymentHash, serviceType string) error }
type Store ¶
type Store interface { GetOrCreateUserByEmail(ctx context.Context, email string) (int64, error) CreateVideo(ctx context.Context, params CreateVideoParams) (*Video, error) // UpdateCloudflareInfo updates the video with info retrieved from Cloudflare. // like the "readyToStream" status. UpdateCloudflareInfo(ctx context.Context, externalID string, params *CloudflareVideoInfo) (*Video, error) GetVideoByExternalID(ctx context.Context, externalID string) (*Video, error) ListUserVideos(ctx context.Context, userID int64) ([]*Video, error) // IncrementVideoViews increments the views of a video by 1. IncrementVideoViews(ctx context.Context, externalID string) error // UpdateVideoInfo updates the video info the title, description and price. UpdateVideoInfo(ctx context.Context, externalID string, params *UpdateVideoInfoParams) (*Video, error) DeleteVideo(ctx context.Context, externalID string) error }
type StreamVideoRequest ¶
type UpdateVideoInfoParams ¶
type UpdateVideoInfoRequest ¶
type UploadVideoRequest ¶
type UploadVideoRequest struct { Email string `form:"email" binding:"required,email"` Title string `form:"title" binding:"required"` Description string `form:"description"` PriceInCents int64 `form:"price_in_cents" binding:"required,min=0"` CoverImage *multipart.FileHeader `form:"cover_image"` }
func (*UploadVideoRequest) Validate ¶
func (r *UploadVideoRequest) Validate() error
type UploadVideoResponse ¶
type UploadVideoResponse struct { VideoID string `json:"video_id"` UploadURL string `json:"upload_url"` }
UploadFileResponse represents a response to uploading a file.
type ValidatorFunc ¶
ValidatorFunc is a function type for request validation
type Video ¶
type Video struct { ID int64 `json:"-"` ExternalID string `json:"external_id"` UserID int64 `json:"-"` L402URL string `json:"l402_url"` L402InfoURI string `json:"l402_info_uri"` Title string `json:"title"` Description string `json:"description"` CoverURL string `json:"cover_url"` PriceInCents int64 `json:"price_in_cents"` TotalViews int64 `json:"total_views"` TotalPurchases int64 `json:"total_purchases"` ThumbnailURL string `json:"-"` HlsURL string `json:"-"` DashURL string `json:"-"` DurationInSeconds float64 `json:"duration_in_seconds"` SizeInBytes int64 `json:"size_in_bytes"` InputHeight int32 `json:"input_height"` InputWidth int32 `json:"input_width"` ReadyToStream bool `json:"ready_to_stream"` CreatedAt time.Time `json:"created_at"` }