Documentation ¶
Index ¶
- Constants
- Variables
- func CustomMarshal(item interface{}) ([]byte, error)
- func HashPassword(pass, salt []byte) []byte
- func I64(v sql.NullInt64) *int64
- func IsSafe(s string, t StringType) bool
- func ItemToInterfaceSlice(slice []Item) []interface{}
- func MakePassword(pass []byte) []byte
- func NullI64(v *int64) sql.NullInt64
- func NullStr(v *string) sql.NullString
- func SqlStr(v string) sql.NullString
- func Str(v sql.NullString) *string
- func StrPtr(s *string) string
- func StrStr(v sql.NullString) string
- func TitleMagic(file, titleOld, artistOld string) (title, artist string)
- type DB
- func (db *DB) Authenticate(authtoken string) (core.AuthLevel, *int64, error)
- func (d *DB) AvgFilesPerFolder() float32
- func (d *DB) ChangeAuthToken(user *User) (string, error)
- func (d *DB) Close() error
- func (db *DB) CreateUser(name string, email string, authLevel core.AuthLevel, password string) (*User, error)
- func (d *DB) FoldersTotal() (num int64)
- func (db *DB) GetItem(args core.ArgMap) ([]Item, error)
- func (d *DB) GetUser(uid int64) (*User, error)
- func (d *DB) GetUserByName(name string) (*User, error)
- func (db *DB) ListAll() ([]Item, error)
- func (db *DB) ListQuery(query string) ([]Item, error)
- func (db *DB) Login(name string, password string) (success bool, authToken string, err error)
- func (d *DB) Open(c core.Core) error
- func (d *DB) TitlesTotal() (num int64)
- func (db *DB) TrackPlayed(ctx core.CommandContext) core.Result
- func (d *DB) Update()
- type Folder
- type Item
- type StringType
- type User
Constants ¶
View Source
const ( ParamString uint = iota ParamFloat ParamBool )
View Source
const ( // Settings for the stored hash, PBKDF2 SaltSize = 128 Iterations = 2000 KeySize = 512 // only characters easily typeable on a mobile AuthTokenChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" // also, not too many of them AuthTokenSize = 16 )
View Source
const ( ItemTable = "items" FolderTable = "folders" UserTable = "users" )
Variables ¶
View Source
var ErrorTerminate error = errors.New("Terminating")
View Source
var Types = []string{"mp3", "wav", "flac", "m4a", "aac"}
Functions ¶
func CustomMarshal ¶
func HashPassword ¶
func IsSafe ¶
func IsSafe(s string, t StringType) bool
func ItemToInterfaceSlice ¶
func ItemToInterfaceSlice(slice []Item) []interface{}
func NullStr ¶
func NullStr(v *string) sql.NullString
func SqlStr ¶
func SqlStr(v string) sql.NullString
func Str ¶
func Str(v sql.NullString) *string
func StrStr ¶
func StrStr(v sql.NullString) string
func TitleMagic ¶
Types ¶
type DB ¶
type DB dbstruct
func (*DB) Authenticate ¶
Checks a given authentication token agains the database. On success, returns the permission level of the user and their ID On failure, returns (AuthGuest, nil, error)
func (*DB) AvgFilesPerFolder ¶
func (*DB) ChangeAuthToken ¶
changes auth token and saves user returns: new auth token and/or error.
func (*DB) CreateUser ¶
func (*DB) FoldersTotal ¶
func (*DB) TitlesTotal ¶
func (*DB) TrackPlayed ¶
func (db *DB) TrackPlayed(ctx core.CommandContext) core.Result
type Folder ¶
type Folder struct { Id int64 Path string `sql:"size:511"` CreatedAt time.Time MusicbrainzId sql.NullString `sql:"size:36"` }
func (Folder) MarshalJSON ¶
type Item ¶
type Item struct { Id int64 Title string `sql:"size:255"` Artist string `sql:"size:255"` AlbumArtist sql.NullString `sql:"size:255"` Album sql.NullString `sql:"size:255" json:",string"` Genre sql.NullString `sql:"size:255"` //TODO more refined genres TrackNumber sql.NullString `sql:"size:16"` Filename sql.NullString `sql:"size:255"` MusicbrainzId sql.NullString `sql:"size:36"` Folder Folder FolderId sql.NullInt64 CreatedAt time.Time // Total play score of a track. // Gets incremented by up to 1 each time a user listens to a track, // depending on how far in he listened to the track. // The formula for the added value is: // x: amount of track listened to (0..1) // tl: listened lower threshold // tu: listened upper threshold // add(x) = min( 1, max( 0, (x - tl) / (tu - tl) ) ) PlayScore float32 // Total times a track was played (including skips) // Track Score := (PlayScore / PlayCount) PlayCount uint32 // Total times a track was played and scored as positive (x >= tl) ScoredCount uint32 // Number of plays that are registered at the local scrobbler. // // When a track is listened and scored positively, this is incremented // and a scrobble is sent to the service. ScrobbleCount uint32 }
when inserting an item, Folder has to be a pointer with only the Path set.
func InterfaceToItemSlice ¶
func InterfaceToItemSlice(slice []interface{}) []Item
func (Item) MarshalJSON ¶
type StringType ¶
type StringType uint
const ( TypePassword StringType = iota TypeUsername TypeEmail )
type User ¶
type User struct { Id int64 `json:"-"` // Login name for the user. Has to be unique. Name string `json:"name" sql:"size:255"` // E-mail address. Has to be unique. Email string `json:"email"` AuthLevel core.AuthLevel `json:"auth_level"` // salt + pbkdf2-hashed password Password []byte `json:"-"` // Authentication token, used for sending requests AuthToken string `json:"auth_token"` }
Click to show internal directories.
Click to hide internal directories.