models

package
v0.0.0-...-f18cc39 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2013 License: BSD-3-Clause, MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	USERNAME_TAKEN        UserModelError = 1 << iota
	USERNAME_INVALID_CHAR                = 1 << iota
	FAIL_GEN_SECRET                      = 1 << iota
)
View Source
const (
	SESSIONS_TABLE string = "sessions"
)

Variables

This section is empty.

Functions

func CountUsers

func CountUsers(username string) int

Returns -1 if user count cannot be established. Returns 0 or 1 if user exists. Can return > 1 but schema would prevent it.

Types

type Attribute

type Attribute struct {
	TorrentId int //

	Name        string
	ArtistName  []string
	AlbumName   string
	ReleaseYear time.Time

	MusicFormat string
	DiscNumber  int
	Discs       int

	AlbumDescription   string
	ReleaseDescription string
	// contains filtered or unexported fields
}

An attribute record stores meta-data which can be attached to a torrent.

func (*Attribute) SelectTorrent

func (elem *Attribute) SelectTorrent(torrentId int) error

func (*Attribute) WriteFor

func (attributes *Attribute) WriteFor(torrentId int) error

type AttributesBundle

type AttributesBundle struct {
	ID       int
	ParentID int

	Category BundleType
	Bundle   hstore.Hstore
	Modified time.Time
}

This is my bundle There are many like it, but this one is mine.

type Bundle

type Bundle interface {
	ToBundle() map[string]string
	FromBundle(map[string]string) error
}

type BundleType

type BundleType string
const (
	BUNDLE_SERIES  BundleType = "series"
	BUNDLE_EPISODE            = "episode"
)

type EpisodeBundle

type EpisodeBundle struct {
	ID        int `json:"episodeId"`
	TorrentID int `json:"torrentId"`

	Number int    `json:"number"`
	Name   string `json:"name"`

	Format     string `json:"format"`
	Resolution string `json:"resolution"`
}

func LatestEpisodes

func LatestEpisodes() []*EpisodeBundle

TODO: Pagination Select the latest episodes, regardless of series.

func (*EpisodeBundle) FromBundle

func (eb *EpisodeBundle) FromBundle(bundleStore map[string]sql.NullString) error

Implements Bundle interface and loads an EpisodeBundle object from a deserialized postgresql hstore field.

func (*EpisodeBundle) PersistWithSeries

func (eb *EpisodeBundle) PersistWithSeries(series *SeriesBundle) error

func (*EpisodeBundle) ToBundle

func (eb *EpisodeBundle) ToBundle() map[string]sql.NullString

type SeriesBundle

type SeriesBundle struct {
	ID        int `json:"bundleId"`
	TorrentID int `json:"torrentId"`

	Name     string           `json:"name"`
	Episodes []*EpisodeBundle `json:"episodes"`
}

func LatestSeries

func LatestSeries() []*SeriesBundle

Selects the latest series' of television.

This will select 100 series at a time which have a torrent or episode(s) associated with them.

func (*SeriesBundle) FromBundle

func (sb *SeriesBundle) FromBundle(bundleStore map[string]sql.NullString) error

Implements Bundle interface and loads an SeriesBundle object from a deserialized postgresql hstore field.

func (*SeriesBundle) Head

func (sb *SeriesBundle) Head() *EpisodeBundle

func (*SeriesBundle) NumberOfEpisodes

func (sb *SeriesBundle) NumberOfEpisodes() int

func (*SeriesBundle) Persist

func (sb *SeriesBundle) Persist() error

func (*SeriesBundle) PersistWith

func (sb *SeriesBundle) PersistWith(tx *sql.Tx) error

TODO: Try update first.

func (*SeriesBundle) SelectByName

func (sb *SeriesBundle) SelectByName(seriesName string) error

Attempts to populate series bundle by name. Otherwise this series bundle will be inserted.

func (*SeriesBundle) Tail

func (sb *SeriesBundle) Tail() []*EpisodeBundle

func (*SeriesBundle) ToBundle

func (sb *SeriesBundle) ToBundle() map[string]sql.NullString

type Session

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

func (*Session) DeleteFor

func (s *Session) DeleteFor(user *User) error

func (*Session) WriteFor

func (s *Session) WriteFor(user *User, ipAddr string) error

type Torrent

type Torrent struct {
	ID       int    `field:"torrent_id"`
	Name     string `field:"name"`
	InfoHash string `field:"info_hash"`

	CreatedBy    string `field:"created_by"`
	CreationDate int    `field:"creation_date"`

	Encoding    string `field:"encoding"`
	EncodedInfo []byte `field:"info_bencoded"`

	Seeding  int
	Leeching int
	// contains filtered or unexported fields
}

Define record structure. Tags aren't used anywhere . . .

Mostly use them as references, might use them for some sort of ORM in the future.

func (*Torrent) Attributes

func (t *Torrent) Attributes() (*Attribute, error)

func (*Torrent) LoadTorrent

func (t *Torrent) LoadTorrent() (*torrent.TorrentFile, error)

func (*Torrent) Populate

func (t *Torrent) Populate(torrentFile *torrent.TorrentFile) error

func (*Torrent) SelectHash

func (t *Torrent) SelectHash(hash string) error

Looks up a torrent based on its info hash, this is a 20-byte SHA which is encoded as a string [2-chars per byte.]

func (*Torrent) SelectId

func (t *Torrent) SelectId(id int) error

func (*Torrent) SelectSummaryPage

func (t *Torrent) SelectSummaryPage() ([]*Torrent, error)

Selects an excerpt of torrents. Only fetches an ID, InfoHash, and CreatedBy

func (*Torrent) SetAttributes

func (t *Torrent) SetAttributes(attributes *Attribute)

func (*Torrent) Write

func (t *Torrent) Write() error

func (*Torrent) WriteFile

func (t *Torrent) WriteFile(secret, hash []byte) ([]byte, error)

type User

type User struct {
	UserId   int
	Username string
	IsAdmin  bool

	Email string

	Secret     []byte
	SecretHash []byte
	// contains filtered or unexported fields
}

`User` model for `users`

func AllUsers

func AllUsers() ([]*User, error)

func (*User) AnnounceURL

func (u *User) AnnounceURL() string

TODO: needs to use sites base url.

func (*User) CheckHash

func (u *User) CheckHash(password string) error

Must be performed on an initialized user-struct. Returns an error if the user's password cannot be validated.

func (*User) Delete

func (u *User) Delete() error

func (*User) SelectId

func (u *User) SelectId(id int) error

Select user by ID number and populate the current `user` struct with the record data. Returns an error if there was a problem. fetching the user information from the database.

func (*User) SelectSecret

func (u *User) SelectSecret(secret string) error

Selects a user by their secret key. This is used by the tracker to authorize a user.

The secret is expected to be a UTF8 string representing a byte array using 2-characters per byte. (As per the standard encoding/hex package.)

func (*User) SelectUsername

func (u *User) SelectUsername(username string) error

Select user by username and populate the current `user` struct with the record data. Returns an error if there was a problem. fetching the user information from the database.

type UserModelError

type UserModelError int

Error-codes returned from some methods that could be presented to the UI.

func NewUser

func NewUser(username, password string) (UserModelError, error)

Creates a new user record in the database. The first return parameter is an error-code that represents a non-fatal problem that could be presented to the user.

The second return parameter is a fatal error passed up from the database layer.

Jump to

Keyboard shortcuts

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