store

package
v0.0.0-...-eebc868 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FileURIScheme = "file"
)

Variables

View Source
var (
	ErrNotImplemented    = errors.New("not implemented")
	ErrNotFound          = gorm.ErrRecordNotFound
	ErrShowAlreadyExists = errors.New("show already exists")
	ErrFileNotNew        = errors.New("file does not exist or is not new")
	ErrFileImportNotDone = errors.New("file import is not done")

	ErrPlaylistHasMultipleNullDurationEntries = errors.New("playlists may only have one entry without a duration")
)

Functions

This section is empty.

Types

type AudioConfig

type AudioConfig struct {
	Format     AudioFormat `json:"format" yaml:"format" toml:"format"`
	SampleRate uint        `json:"sample-rate" yaml:"sample-rate" toml:"sample-rate"`
}

type AudioFormat

type AudioFormat int
const (
	FormatWAV AudioFormat = iota
	FormatFlac
)

func (AudioFormat) Extension

func (f AudioFormat) Extension() string

func (AudioFormat) MarshalText

func (f AudioFormat) MarshalText() (data []byte, err error)

func (AudioFormat) String

func (f AudioFormat) String() string

func (*AudioFormat) UnmarshalText

func (f *AudioFormat) UnmarshalText(data []byte) (err error)

type Config

type Config struct {
	BasePath string      `json:"path" yaml:"path" toml:"path"`
	Audio    AudioConfig `json:"audio" yaml:"audio" toml:"audio"`
	DB       DBConfig    `json:"db" yaml:"db" toml:"db"`
}

func (*Config) ExpandEnv

func (c *Config) ExpandEnv()

type DBConfig

type DBConfig struct {
	Type     string `json:"type" yaml:"type" toml:"type"`
	Host     string `json:"host" yaml:"host" toml:"host"`
	Port     uint16 `json:"port" yaml:"port" toml:"port"`
	TLS      string `json:"tls" yaml:"tls" toml:"tls"`
	Username string `json:"username" yaml:"username" toml:"username"`
	Password string `json:"password" yaml:"password" toml:"password"`
	DB       string `json:"database" yaml:"database" toml:"database"`
	Charset  string `json:"charset" yaml:"charset" toml:"charset"`
	Debug    bool   `json:"debug" yaml:"debug" toml:"debug"`
}

type ErrFileInUse

type ErrFileInUse struct {
	Playlists []Playlist `json:"playlists"`
}

func (*ErrFileInUse) Error

func (e *ErrFileInUse) Error() string

type ErrInvalidMetadataField

type ErrInvalidMetadataField string

func (ErrInvalidMetadataField) Error

func (e ErrInvalidMetadataField) Error() string

type ErrInvalidPlaylistEntry

type ErrInvalidPlaylistEntry struct {
	// contains filtered or unexported fields
}

func (ErrInvalidPlaylistEntry) Error

func (e ErrInvalidPlaylistEntry) Error() string

type File

type File struct {
	ID        uint64       `json:"id" gorm:"primary_key"`
	CreatedAt time.Time    `json:"created"`
	UpdatedAt time.Time    `json:"updated"`
	ShowID    uint64       `json:"showId" gorm:"not null;index"`
	Show      Show         `json:"-" gorm:"association_foreignkey:ID"`
	Source    FileSource   `json:"source" gorm:"embedded;embedded_prefix:source__"`
	Metadata  FileMetadata `json:"metadata" gorm:"embedded;embedded_prefix:metadata__"`
	Size      uint64       `json:"size"`
	Duration  float64      `json:"duration"`
}

type FileMetadata

type FileMetadata struct {
	// actually a full-text index would be nice here...
	Artist       string `json:"artist,omitempty" gorm:"index"`
	Title        string `json:"title,omitempty" gorm:"index"`
	Album        string `json:"album,omitempty" gorm:"index"`
	Organization string `json:"organization,omitempty" gorm:"index"`
	ISRC         string `json:"isrc,omitempty" gorm:"index"`
}

type FileSource

type FileSource struct {
	URI    string `json:"uri" gorm:"size:1024"`
	Hash   string `json:"hash"`
	Import Import `json:"import" gorm:"embedded;embedded_prefix:import__"`
}

type Import

type Import struct {
	State ImportState `json:"state" swaggertype:"string"`
	Error string      `json:"error,omitempty"`
}

type ImportLog

type ImportLog struct {
	ID         uint64 `gorm:"primary_key"`
	File       File   `gorm:"association_autoupdate:false;association_autocreate:false"`
	FileID     uint64 `gorm:"not null;index;unique_index:unique_import_log_step"`
	ImportStep string `gorm:"not null;index;unique_index:unique_import_log_step"`
	Encoded    []byte `gorm:"size:-1"`
}

type ImportLogs

type ImportLogs map[string]*Log

Mind that ImportLogs is not []ImportLog but rather a map containing objects of type LOG

type ImportState

type ImportState int
const (
	ImportNew ImportState = iota
	ImportInitializing
	ImportPending
	ImportRunning
	ImportDone
	ImportAborted
)

func (ImportState) MarshalText

func (s ImportState) MarshalText() (data []byte, err error)

func (ImportState) String

func (s ImportState) String() string

func (*ImportState) UnmarshalText

func (s *ImportState) UnmarshalText(data []byte) (err error)

type Log

type Log struct {
	// contains filtered or unexported fields
}

This implements json.Marshaler and therefore doesn't need `lines` to be public.

func (*Log) Append

func (l *Log) Append(stream, line string)

func (*Log) MarshalJSON

func (l *Log) MarshalJSON() ([]byte, error)

func (*Log) NewReader

func (l *Log) NewReader(stream string) *LogReader

type LogLine

type LogLine struct {
	Stream    string    `json:"stream"`
	Timestamp time.Time `json:"timestamp"`
	Line      string    `json:"line"`
}

type LogReader

type LogReader struct {
	// contains filtered or unexported fields
}

LogReader is not a perfect io.Reader:

  • lines longer than len(p) will be truncated !!!
  • it will only return one line on each invocation even if len(p) would allow us to return more than one line

func (*LogReader) Read

func (r *LogReader) Read(p []byte) (n int, err error)

type Playlist

type Playlist struct {
	ID          uint64          `json:"id" gorm:"primary_key"`
	CreatedAt   time.Time       `json:"created"`
	UpdatedAt   time.Time       `json:"updated"`
	Description string          `json:"description"`
	PlayoutMode string          `json:"playoutMode" gorm:"not null;default:'linear'"`
	ShowID      uint64          `json:"showId" gorm:"not null;index"`
	Show        Show            `json:"-" gorm:"association_foreignkey:ID"`
	Entries     []PlaylistEntry `json:"entries"`
}

func (*Playlist) AfterFind

func (p *Playlist) AfterFind() error

func (*Playlist) AfterSave

func (p *Playlist) AfterSave(tx *gorm.DB) error

func (*Playlist) BeforeSave

func (p *Playlist) BeforeSave(tx *gorm.DB) error

type PlaylistEntry

type PlaylistEntry struct {
	ID         uint64   `json:"-" gorm:"primary_key"`
	PlaylistID uint64   `json:"-" gorm:"not null;index;unique_index:unique_playlist_line_numbers"`
	LineNum    uint     `json:"-" gorm:"not null;unique_index:unique_playlist_line_numbers"`
	URI        string   `json:"uri" gorm:"size:1024"`
	Duration   *float64 `json:"duration,omitempty"`
	File       *File    `json:"file,omitempty" gorm:"association_autoupdate:false;association_autocreate:false"`
	FileID     *uint64  `json:"-" gorm:"index"`
}

type Show

type Show struct {
	ID        uint64    `json:"id" gorm:"primary_key"`
	CreatedAt time.Time `json:"created"`
	UpdatedAt time.Time `json:"updated"`
}

func (Show) String

func (g Show) String() uint64

type Store

type Store struct {
	Audio AudioConfig
	// contains filtered or unexported fields
}

func NewStore

func NewStore(cfg Config) (*Store, error)

func (*Store) AddImportLog

func (st *Store) AddImportLog(showID uint64, id uint64, importStep string, log *Log) (err error)

func (*Store) CloneShow

func (st *Store) CloneShow(name, from uint64) (show *Show, err error)

func (*Store) Close

func (st *Store) Close()

func (*Store) CreateFile

func (st *Store) CreateFile(showID uint64, file File) (*File, error)

func (*Store) CreatePlaylist

func (st *Store) CreatePlaylist(showID uint64, playlist Playlist) (*Playlist, error)

func (*Store) CreateShow

func (st *Store) CreateShow(name uint64) (show *Show, err error)

this will not fail if the show already exists

func (*Store) DeleteFile

func (st *Store) DeleteFile(showID uint64, id uint64) (err error)

func (*Store) DeletePlaylist

func (st *Store) DeletePlaylist(showID uint64, id uint64) (err error)

func (*Store) DeleteShow

func (st *Store) DeleteShow(showID uint64) (err error)

this will also remove all files and playlists belonging to the show!

func (*Store) GetFile

func (st *Store) GetFile(showID uint64, fileID uint64) (file *File, err error)

func (*Store) GetFilePath

func (st *Store) GetFilePath(showID uint64, fileID uint64) string

func (*Store) GetFileShowID

func (st *Store) GetFileShowID(id uint64) (uint64, error)

func (*Store) GetFileUsage

func (st *Store) GetFileUsage(showID uint64, id uint64) (playlists []Playlist, err error)

func (*Store) GetImportLogs

func (st *Store) GetImportLogs(showID uint64, id uint64) (logs ImportLogs, err error)

func (*Store) GetPlaylist

func (st *Store) GetPlaylist(showID uint64, id uint64) (playlist *Playlist, err error)

func (*Store) GetPlaylistAllShows

func (st *Store) GetPlaylistAllShows(id uint64) (playlist *Playlist, err error)

func (*Store) GetPlaylistShowID

func (st *Store) GetPlaylistShowID(id uint64) (uint64, error)

func (*Store) GetRevision

func (st *Store) GetRevision() string

func (*Store) Healthz

func (st *Store) Healthz(ctx context.Context) error

func (*Store) ListFiles

func (st *Store) ListFiles(showID uint64, offset, limit int) (files []File, err error)

func (*Store) ListPlaylists

func (st *Store) ListPlaylists(showID uint64, offset, limit int) (playlists []Playlist, err error)

func (*Store) ListPlaylistsAllShows

func (st *Store) ListPlaylistsAllShows(offset, limit int) (playlists []Playlist, err error)

func (*Store) ListShows

func (st *Store) ListShows() (shows []Show, err error)

func (*Store) SetFileImportStateAborted

func (st *Store) SetFileImportStateAborted(showID uint64, id uint64, error string) (file *File, err error)

func (*Store) SetFileImportStateDone

func (st *Store) SetFileImportStateDone(showID uint64, id uint64) (*File, error)

func (*Store) SetFileImportStateInitializing

func (st *Store) SetFileImportStateInitializing(showID uint64, id uint64) (file *File, err error)

func (*Store) SetFileImportStatePending

func (st *Store) SetFileImportStatePending(showID uint64, id uint64) (file *File, err error)

func (*Store) SetFileImportStateRunning

func (st *Store) SetFileImportStateRunning(showID uint64, id uint64) (file *File, err error)

func (*Store) UpdateFile

func (st *Store) UpdateFile(showID uint64, id uint64, file File) (out *File, err error)

func (*Store) UpdateFileMetadata

func (st *Store) UpdateFileMetadata(showID uint64, id uint64, metadata map[string]string) (file *File, err error)

func (*Store) UpdateFileSourceHash

func (st *Store) UpdateFileSourceHash(showID uint64, id uint64, hash string) (*File, error)

func (*Store) UpdatePlaylist

func (st *Store) UpdatePlaylist(showID uint64, id uint64, playlist Playlist) (out *Playlist, err error)

Jump to

Keyboard shortcuts

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