db

package
v0.0.0-...-f265c88 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2015 License: BSD-2-Clause Imports: 25 Imported by: 0

Documentation

Index

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 CustomMarshal(item interface{}) ([]byte, error)

func HashPassword

func HashPassword(pass, salt []byte) []byte

func I64

func I64(v sql.NullInt64) *int64

func IsSafe

func IsSafe(s string, t StringType) bool

func ItemToInterfaceSlice

func ItemToInterfaceSlice(slice []Item) []interface{}

func MakePassword

func MakePassword(pass []byte) []byte

TODO test MakePassword

func NullI64

func NullI64(v *int64) sql.NullInt64

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 StrPtr

func StrPtr(s *string) string

func StrStr

func StrStr(v sql.NullString) string

func TitleMagic

func TitleMagic(file, titleOld, artistOld string) (title, artist string)

Types

type DB

type DB dbstruct

func (*DB) Authenticate

func (db *DB) Authenticate(authtoken string) (core.AuthLevel, *int64, error)

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 (d *DB) AvgFilesPerFolder() float32

func (*DB) ChangeAuthToken

func (d *DB) ChangeAuthToken(user *User) (string, error)

changes auth token and saves user returns: new auth token and/or error.

func (*DB) Close

func (d *DB) Close() error

func (*DB) CreateUser

func (db *DB) CreateUser(name string, email string, authLevel core.AuthLevel,
	password string) (*User, error)

func (*DB) FoldersTotal

func (d *DB) FoldersTotal() (num int64)

func (*DB) GetItem

func (db *DB) GetItem(args core.ArgMap) ([]Item, error)

func (*DB) GetUser

func (d *DB) GetUser(uid int64) (*User, error)

func (*DB) GetUserByName

func (d *DB) GetUserByName(name string) (*User, error)

func (*DB) ListAll

func (db *DB) ListAll() ([]Item, error)

func (*DB) ListQuery

func (db *DB) ListQuery(query string) ([]Item, error)

func (*DB) Login

func (db *DB) Login(name string, password string) (success bool,
	authToken string, err error)

func (*DB) Open

func (d *DB) Open(c core.Core) error

func (*DB) TitlesTotal

func (d *DB) TitlesTotal() (num int64)

func (*DB) TrackPlayed

func (db *DB) TrackPlayed(ctx core.CommandContext) core.Result

func (*DB) Update

func (d *DB) Update()

type Folder

type Folder struct {
	Id   int64
	Path string `sql:"size:511"`

	CreatedAt     time.Time
	MusicbrainzId sql.NullString `sql:"size:36"`
}

func (Folder) MarshalJSON

func (folder Folder) MarshalJSON() ([]byte, error)

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

func (item Item) MarshalJSON() ([]byte, error)

func (*Item) Path

func (i *Item) Path() *string

func (*Item) Rating

func (i *Item) Rating() (rating, accuracy float32)

Returns a rating of the song and an indication of how accurate the score might be. Both values are in the range of 0 to 1. The computation uses a combination of PlayScore, PlayCount and ScrobbledCount.

func (*Item) Skipped

func (i *Item) Skipped() uint32

func (*Item) String

func (i *Item) String() string

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"`
}

Jump to

Keyboard shortcuts

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