public

package
v0.0.0-...-ca8de47 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowedExtension

func AllowedExtension(ext string) bool

AllowedExtension returns if ext is an allowed extension for the uploaded audio files

func ParsePostNewsEntryForm

func ParsePostNewsEntryForm(r *http.Request) (*radio.NewsComment, error)

func PendingFromProbe

func PendingFromProbe(filename string) (*radio.PendingSong, error)

PendingFromProbe runs ffprobe on the given filename and constructs a PendingSong with the information found

func Route

func Route(ctx context.Context, s State) func(chi.Router)

Types

type ChatInput

type ChatInput struct {
	middleware.Input
}

func NewChatInput

func NewChatInput(r *http.Request) ChatInput

func (ChatInput) TemplateBundle

func (ChatInput) TemplateBundle() string

type FaveDownloadEntry

type FaveDownloadEntry struct {
	ID            *radio.TrackID `json:"tracks_id"`
	Metadata      string         `json:"meta"`
	LastRequested *int64         `json:"lastrequested"`
	LastPlayed    *int64         `json:"lastplayed"`
	RequestCount  *int           `json:"requestcount"`
}

func NewFaveDownload

func NewFaveDownload(songs []radio.Song) []FaveDownloadEntry

func NewFaveDownloadEntry

func NewFaveDownloadEntry(song radio.Song) FaveDownloadEntry

type FavesInput

type FavesInput struct {
	middleware.Input
	CSRFTokenInput  template.HTML
	Nickname        string
	CanRequest      bool
	RequestCooldown time.Duration
	DownloadURL     string
	Faves           []radio.Song
	FaveCount       int64
	Page            *shared.Pagination
}

func NewFavesInput

func NewFavesInput(ss radio.SongStorage, rs radio.RequestStorage, r *http.Request, requestDelay time.Duration) (*FavesInput, error)

func (FavesInput) TemplateBundle

func (FavesInput) TemplateBundle() string

type HelpInput

type HelpInput struct {
	middleware.Input
}

func NewHelpInput

func NewHelpInput(r *http.Request) HelpInput

func (HelpInput) TemplateBundle

func (HelpInput) TemplateBundle() string

type HomeInput

type HomeInput struct {
	middleware.Input

	Queue      radio.Queue
	LastPlayed []radio.Song
	News       []NewsInputPost
}

func NewHomeInput

func NewHomeInput(r *http.Request) HomeInput

func (HomeInput) TemplateBundle

func (HomeInput) TemplateBundle() string

type LastPlayedInput

type LastPlayedInput struct {
	middleware.Input

	Songs []radio.Song
	Page  *shared.FromPagination[radio.LastPlayedKey]
}

func (LastPlayedInput) TemplateBundle

func (LastPlayedInput) TemplateBundle() string

type NewsEntryComment

type NewsEntryComment struct {
	ID         radio.NewsCommentID
	PostID     radio.NewsPostID
	Body       template.HTML
	Identifier string

	User      *radio.User
	DeletedAt *time.Time
	CreatedAt time.Time
	UpdatedAt *time.Time
}

type NewsEntryInput

type NewsEntryInput struct {
	middleware.Input
	CSRFTokenInput template.HTML
	Post           NewsEntryPost
}

func NewNewsEntryInput

func NewNewsEntryInput(cache *shared.NewsCache, ns radio.NewsStorage, r *http.Request) (*NewsEntryInput, error)

func (NewsEntryInput) TemplateBundle

func (NewsEntryInput) TemplateBundle() string

type NewsEntryPost

type NewsEntryPost struct {
	ID        radio.NewsPostID
	Title     string
	User      radio.User
	DeletedAt *time.Time
	CreatedAt time.Time
	UpdatedAt *time.Time
	Body      template.HTML

	Comments []NewsEntryComment
}

type NewsInput

type NewsInput struct {
	middleware.Input

	News      []NewsInputPost
	NewsTotal int
	Page      *shared.Pagination
}

func NewNewsInput

func NewNewsInput(cache *shared.NewsCache, ns radio.NewsStorageService, r *http.Request) (*NewsInput, error)

func (NewsInput) TemplateBundle

func (NewsInput) TemplateBundle() string

type NewsInputPost

type NewsInputPost struct {
	ID     radio.NewsPostID
	Title  string
	Header template.HTML
	User   radio.User

	CreatedAt time.Time
	UpdatedAt *time.Time
}

func AsNewsInputPost

func AsNewsInputPost(ctx context.Context, cache *shared.NewsCache, entries []radio.NewsPost) ([]NewsInputPost, error)

type QueueInput

type QueueInput struct {
	middleware.Input

	Queue []radio.QueueEntry
}

func NewQueueInput

func NewQueueInput(qs radio.QueueService, r *http.Request) (*QueueInput, error)

func (QueueInput) TemplateBundle

func (QueueInput) TemplateBundle() string

type ScheduleInput

type ScheduleInput struct {
	middleware.Input

	Schedule []*radio.ScheduleEntry
}

func (ScheduleInput) TemplateBundle

func (ScheduleInput) TemplateBundle() string

type SearchInput

type SearchInput struct {
	middleware.Input
	SearchSharedInput
	CSRFLegacyFix template.HTML

	// IsError indicates if the message given is an error
	IsError bool
	// Message to show at the top of the page
	Message string
}

func NewSearchInput

func NewSearchInput(s radio.SearchService, rs radio.RequestStorage, r *http.Request, requestDelay time.Duration) (*SearchInput, error)

func (SearchInput) TemplateBundle

func (SearchInput) TemplateBundle() string

type SearchSharedInput

type SearchSharedInput struct {
	CSRFTokenInput  template.HTML
	Query           string
	Songs           []radio.Song
	CanRequest      bool
	RequestCooldown time.Duration
	Page            *shared.Pagination
}

func NewSearchSharedInput

func NewSearchSharedInput(s radio.SearchService, rs radio.RequestStorage, r *http.Request, requestDelay time.Duration, pageSize int64) (*SearchSharedInput, error)

type StaffInput

type StaffInput struct {
	middleware.Input

	Users []radio.User
}

func NewStaffInput

func NewStaffInput(us radio.UserStorageService, r *http.Request) (*StaffInput, error)

func (StaffInput) Roles

func (si StaffInput) Roles() []string

func (StaffInput) TemplateBundle

func (StaffInput) TemplateBundle() string

type State

type State struct {
	config.Config

	Daypass   secret.Secret
	News      *shared.NewsCache
	Templates templates.Executor
	Manager   radio.ManagerService
	Streamer  radio.StreamerService
	Storage   radio.StorageService
	Search    radio.SearchService
}

func NewState

func NewState(
	ctx context.Context,
	cfg config.Config,
	dp secret.Secret,
	newsCache *shared.NewsCache,
	exec templates.Executor,
	manager radio.ManagerService,
	streamer radio.StreamerService,
	storage radio.StorageService,
	search radio.SearchService) State

func (State) GetChat

func (s State) GetChat(w http.ResponseWriter, r *http.Request)

func (State) GetFaves

func (s State) GetFaves(w http.ResponseWriter, r *http.Request)

func (State) GetHelp

func (s State) GetHelp(w http.ResponseWriter, r *http.Request)

func (State) GetHome

func (s State) GetHome(w http.ResponseWriter, r *http.Request)

func (State) GetLastPlayed

func (s State) GetLastPlayed(w http.ResponseWriter, r *http.Request)

func (State) GetNews

func (s State) GetNews(w http.ResponseWriter, r *http.Request)

func (State) GetNewsEntry

func (s State) GetNewsEntry(w http.ResponseWriter, r *http.Request)

func (State) GetQueue

func (s State) GetQueue(w http.ResponseWriter, r *http.Request)

func (State) GetSchedule

func (s State) GetSchedule(w http.ResponseWriter, r *http.Request)

func (State) GetSearch

func (s State) GetSearch(w http.ResponseWriter, r *http.Request)

func (State) GetStaff

func (s State) GetStaff(w http.ResponseWriter, r *http.Request)

func (State) GetSubmit

func (s State) GetSubmit(w http.ResponseWriter, r *http.Request)

func (State) PostFaves

func (s State) PostFaves(w http.ResponseWriter, r *http.Request)

func (State) PostNewsEntry

func (s State) PostNewsEntry(w http.ResponseWriter, r *http.Request)

func (State) PostSubmit

func (s State) PostSubmit(w http.ResponseWriter, r *http.Request)

type SubmissionForm

type SubmissionForm struct {
	CSRFTokenInput template.HTML
	// Success indicates if the upload was a success
	Success bool
	// IsDaypass is true if Daypass was valid
	IsDaypass bool
	// Errors is populated when any errors were found with the uploaded form
	// this is populated with their form field names as indicated below in addition to
	// the following possible keys:
	//		"postprocessing": something failed after successful form parsing but before we saved all the data
	//		"cooldown": indicates the user was not permitted to upload yet, they need to wait longer
	Errors map[string]string
	// form fields
	OriginalFilename    string         // name="track" The filename of the uploaded file
	Daypass             string         // name="daypass"
	Comment             string         // name="comment"
	Replacement         *radio.TrackID // name="replacement"
	NeedReplacementList []radio.Song   // possible songs for Replacement field

	// File is the on-disk filename for the uploaded file
	File string
	// Song we managed to populate by analyzing the uploaded file
	Song *radio.PendingSong
}

SubmissionForm is the form struct passed to the submit page templates as .Form

func NewSubmissionForm

func NewSubmissionForm(ts radio.TrackStorage, tempdir string, r *http.Request) (*SubmissionForm, error)

NewSubmissionForm parses a multipart form into the SubmissionForm

Go has standard library support to do this simpler, but it doesn't let you set limits on individual fields, so we're parsing each field ourselves so we can limit their length.

Fields supported:

"track":		audio file being submitted
"comment":		comment to be shown on the pending admin panel
"daypass":		daypass to bypass upload limits
"replacement":	an TrackID (number) indicating what song to replace in the database with this

Any other fields cause an error to be returned and all form parsing to stop.

func (SubmissionForm) TemplateBundle

func (SubmissionForm) TemplateBundle() string

func (SubmissionForm) TemplateName

func (SubmissionForm) TemplateName() string

func (*SubmissionForm) Validate

func (sf *SubmissionForm) Validate(ts radio.TrackStorage, dp secret.Secret) bool

Validate checks if required fields are filled in the SubmissionForm and if a daypass was supplied if it was a valid one. Populates sf.Errors with any errors that occur and what input field caused it.

type SubmitInput

type SubmitInput struct {
	middleware.Input
	Form  SubmissionForm
	Stats radio.SubmissionStats
}

func (SubmitInput) TemplateBundle

func (SubmitInput) TemplateBundle() string

Jump to

Keyboard shortcuts

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