download

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package download aims to interact with the download job using Cloud and websocket features.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DownloadController

type DownloadController struct {
	// Reference to the base controller type
	controller.Controller
	// contains filtered or unexported fields
}

DownloadController is used to interact with the youtube download job

func NewDownloadController

func NewDownloadController(
	opt DownloadControllerOptions) (*DownloadController, error)

NewDownloadController builds a new DownloadController. It setup the task client and the Pub/Sub helper.

func (*DownloadController) Close

func (c *DownloadController) Close() error

Close closes the task client and the Pub/Sub helper

func (*DownloadController) Download

func (c *DownloadController) Download(g *gin.Context)

Download upgrades HTTP request to a websocket

@Summary		Download and save a new music file
@Description	Execute the Youtube-DL job using Cloud Task
@Accept			json
@Produces		json
@Param			payload	body	task.Payload	true	"Parameters to send to job"
@Success		201
@Router			/download/url [get]

func (*DownloadController) NewJob added in v0.1.1

func (c *DownloadController) NewJob(conn websocket.Conn) error

func (*DownloadController) OnReceive

func (c *DownloadController) OnReceive(
	ctx context.Context, message *pubsub.Message)

ReceiveCallback is called when a message is received from the subscription. It ensures that the message is acknowledged. The received message is parsed. Then, the calling websocket is retrieved in the store using the job ordering key. The parsed message is written on this websocket.

type DownloadControllerOptions

type DownloadControllerOptions struct {
	// The [controller] builder parameters
	ControllerOptions controller.ControllerOptions

	// The project ID in Google Cloud
	ProjectID string

	// The location ID configured in Cloud Tasks
	LocationID string

	// The queue ID where to push new tasks in Cloud Tasks
	QueueID string

	// The subscribe ID to use when pulling messages from Pub/Sub
	SubscriptionID string

	// The list of allowed origins that can interact with this controller using
	// websockets
	Origins []string

	// Custom provider
	Provider Provider
}

DownloadControllerOptions holds the parameters for the DownloadController builder

type Provider

type Provider interface {

	// Builds a new cloud task client.
	NewTaskClient(
		queuePath string, target string) (task.TaskClient, error)

	// Builds a new Pub/Sub client.
	NewSubscriber(
		onReceive func(ctx context.Context, message *pubsub.Message),
		projectID string, subscriptionID string,
		logger *log.Logger) (subscriber.Subscriber, error)

	// Builds a new websocket upgrader.
	// It also set the authorized origins for upgrades.
	NewWebsocket(
		origins []string) (websocket.Websocket, error)

	// Builds a new websocket store.
	NewWebsocketStore() websocket.Store
}

Provider which provides:

  • the cloud task client
  • the Pub/Sub subscriber
  • the websocket upgrader
  • the websocket store

Directories

Path Synopsis
Package subscribe is a helper that interacts with Pub/Sub Cloud feature.
Package subscribe is a helper that interacts with Pub/Sub Cloud feature.

Jump to

Keyboard shortcuts

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