models

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2017 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TorrentStatusNormal Int for Torrent status normal
	TorrentStatusNormal = 1
	// TorrentStatusRemake Int for Torrent status remake
	TorrentStatusRemake = 2
	// TorrentStatusTrusted Int for Torrent status trusted
	TorrentStatusTrusted = 3
	// TorrentStatusAPlus Int for Torrent status a+
	TorrentStatusAPlus = 4
	// TorrentStatusBlocked Int for Torrent status locked
	TorrentStatusBlocked = 5
)
View Source
const (
	// UserStatusBanned : Int for User status banned
	UserStatusBanned = -1
	// UserStatusMember : Int for User status member
	UserStatusMember = 0
	// UserStatusTrusted : Int for User status trusted
	UserStatusTrusted = 1
	// UserStatusModerator : Int for User status moderator
	UserStatusModerator = 2
	// UserStatusScraped : Int for User status scrapped
	UserStatusScraped = 3
)
View Source
const (
	// SqliteType : name of the sqlite type in gorm
	SqliteType = "sqlite3"
)

Variables

View Source
var ElasticSearchClient *elastic.Client

ElasticSearchClient : Client for Elastic search

View Source
var IsSqlite bool

IsSqlite : Variable to know if we are in sqlite or postgres

View Source
var ORM *gorm.DB

ORM : Variable for interacting with database

Functions

func ElasticSearchInit

func ElasticSearchInit() (*elastic.Client, error)

ElasticSearchInit : Initialization of ES client

func GormInit

func GormInit(conf *config.Config, logger Logger) (*gorm.DB, error)

GormInit init gorm ORM.

Types

type Activity

type Activity struct {
	ID         uint
	Content    string
	Identifier string
	Filter     string
	UserID     uint
	User       *User
}

Activity model

func NewActivity

func NewActivity(identifier string, filter string, c ...string) Activity

NewActivity : Create a new activity log

func (*Activity) TableName

func (a *Activity) TableName() string

TableName : Return the name of activity table

func (*Activity) ToLocale

func (a *Activity) ToLocale(T func(string, ...interface{}) template.HTML) template.HTML

ToLocale : Convert list of parameters to message in local language

type Comment

type Comment struct {
	ID        uint      `gorm:"column:comment_id;primary_key"`
	TorrentID uint      `gorm:"column:torrent_id"`
	UserID    uint      `gorm:"column:user_id"`
	Content   string    `gorm:"column:content"`
	CreatedAt time.Time `gorm:"column:created_at"`
	UpdatedAt time.Time `gorm:"column:updated_at"`
	DeletedAt *time.Time

	Torrent *Torrent `gorm:"AssociationForeignKey:TorrentID;ForeignKey:torrent_id"`
	User    *User    `gorm:"AssociationForeignKey:UserID;ForeignKey:user_id"`
}

Comment model

func (*Comment) Identifier

func (c *Comment) Identifier() string

Identifier : Return the identifier of the comment

func (Comment) Size

func (c Comment) Size() int

Size : Returns the total size of memory recursively allocated for this struct

func (Comment) TableName

func (c Comment) TableName() string

TableName : Return the name of comment table

type CommentJSON

type CommentJSON struct {
	Username   string        `json:"username"`
	UserID     int           `json:"user_id"`
	UserAvatar string        `json:"user_avatar"`
	Content    template.HTML `json:"content"`
	Date       time.Time     `json:"date"`
}

CommentJSON for comment model in json

type DatabaseDump

type DatabaseDump struct {
	Date        time.Time
	Filesize    int64
	Name        string
	TorrentLink string
}

DatabaseDump model

func (*DatabaseDump) ToJSON

func (dump *DatabaseDump) ToJSON() DatabaseDumpJSON

ToJSON : convert to JSON DatabaseDump model

type DatabaseDumpJSON

type DatabaseDumpJSON struct {
	Date     string `json:"date"`
	Filesize string `json:"filesize"`
	Name     string `json:"name"`
	//Magnet       template.URL  `json:"magnet"`
	TorrentLink template.URL `json:"torrent"`
}

DatabaseDumpJSON : Json format of DatabaseDump model

type File

type File struct {
	ID        uint `gorm:"column:file_id;primary_key"`
	TorrentID uint `gorm:"column:torrent_id;unique_index:idx_tid_path"`
	// this path is bencode'd, call Path() to obtain
	BencodedPath string `gorm:"column:path;unique_index:idx_tid_path"`
	Filesize     int64  `gorm:"column:filesize"`
}

File model

func (*File) Filename

func (f *File) Filename() string

Filename : Returns the filename of the file

func (*File) Path

func (f *File) Path() (out []string)

Path : Returns the path to the file

func (*File) SetPath

func (f *File) SetPath(path []string) error

SetPath : Set the path of the file

func (File) Size

func (f File) Size() int

Size : Returns the total size of memory allocated for this struct

func (File) TableName

func (f File) TableName() string

TableName : Return the name of files table

type FileJSON

type FileJSON struct {
	Path     string `json:"path"`
	Filesize int64  `json:"filesize"`
}

FileJSON for file model in json

type Language

type Language struct {
	ID   uint   `json:"id"`
	Name string `json:"name"`
}

Language model Is it deprecated?

type Logger

type Logger interface {
	Print(v ...interface{})
}

Logger interface

var DefaultLogger Logger

DefaultLogger : use the default gorm logger that prints to stdout

type Notification

type Notification struct {
	ID         uint
	Content    string
	Read       bool
	Identifier string
	URL        string
	UserID     uint
}

Notification model

func NewNotification

func NewNotification(identifier string, c string, url string) Notification

NewNotification : Create a new notification

func (*Notification) TableName

func (n *Notification) TableName() string

TableName : Return the name of notification table

type OldComment

type OldComment struct {
	TorrentID uint      `gorm:"column:torrent_id"`
	Username  string    `gorm:"column:username"`
	Content   string    `gorm:"column:content"`
	Date      time.Time `gorm:"column:date"`

	Torrent *Torrent `gorm:"ForeignKey:torrent_id"`
}

OldComment model from old nyaa

func (OldComment) Size

func (c OldComment) Size() int

Size : Returns the total size of memory recursively allocated for this struct

func (OldComment) TableName

func (c OldComment) TableName() string

TableName : Return the name of OldComment table

type Scrape

type Scrape struct {
	TorrentID  uint      `gorm:"column:torrent_id;primary_key"`
	Seeders    uint32    `gorm:"column:seeders"`
	Leechers   uint32    `gorm:"column:leechers"`
	Completed  uint32    `gorm:"column:completed"`
	LastScrape time.Time `gorm:"column:last_scrape"`
}

Scrape model

func (Scrape) TableName

func (t Scrape) TableName() string

TableName : return the table name of the scrape table

type Torrent

type Torrent struct {
	ID          uint      `gorm:"column:torrent_id;primary_key"`
	Name        string    `gorm:"column:torrent_name"`
	Hash        string    `gorm:"column:torrent_hash;unique"`
	Category    int       `gorm:"column:category"`
	SubCategory int       `gorm:"column:sub_category"`
	Status      int       `gorm:"column:status"`
	Hidden      bool      `gorm:"column:hidden"`
	Date        time.Time `gorm:"column:date"`
	UploaderID  uint      `gorm:"column:uploader"`
	Stardom     int       `gorm:"column:stardom"`
	Filesize    int64     `gorm:"column:filesize"`
	Description string    `gorm:"column:description"`
	WebsiteLink string    `gorm:"column:website_link"`
	AnidbID     string    `gorm:"column:anidb_id"`
	Trackers    string    `gorm:"column:trackers"`
	// Indicates the language of the torrent's content (eg. subs, dubs, raws, manga TLs)
	Language  string `gorm:"column:language"`
	DeletedAt *time.Time

	Uploader    *User        `gorm:"AssociationForeignKey:UploaderID;ForeignKey:user_id"`
	OldUploader string       `gorm:"-"` // ???????
	OldComments []OldComment `gorm:"ForeignKey:torrent_id"`
	Comments    []Comment    `gorm:"ForeignKey:torrent_id"`
	Scrape      *Scrape      `gorm:"AssociationForeignKey:ID;ForeignKey:torrent_id"`
	FileList    []File       `gorm:"ForeignKey:torrent_id"`
	Languages   []string     `gorm:"-"` // This is parsed when retrieved from db
}

Torrent model

func (Torrent) AddToESIndex

func (t Torrent) AddToESIndex(client *elastic.Client) error

AddToESIndex : Adds a torrent to Elastic Search

func (*Torrent) DefinitelyDelete

func (t *Torrent) DefinitelyDelete() (*Torrent, int, error)

DefinitelyDelete : deletes definitely a torrent based on id

func (*Torrent) Delete

func (t *Torrent) Delete(definitely bool) (*Torrent, int, error)

DeleteTorrent : delete a torrent based on id

func (*Torrent) DeleteFromESIndex

func (t *Torrent) DeleteFromESIndex(client *elastic.Client) error

DeleteFromESIndex : Removes a torrent from Elastic Search

func (*Torrent) EncodeLanguages

func (t *Torrent) EncodeLanguages()

func (*Torrent) GetTrackersArray

func (t *Torrent) GetTrackersArray() (trackers []string)

GetTrackersArray : Convert trackers string to Array

func (*Torrent) Identifier

func (t *Torrent) Identifier() string

Identifier : Return the identifier of a torrent

func (*Torrent) IsAPlus

func (t *Torrent) IsAPlus() bool

IsAPlus : Return if a torrent status is a+

func (*Torrent) IsBlocked

func (t *Torrent) IsBlocked() bool

IsBlocked : Return if a torrent status is locked

func (*Torrent) IsDeleted

func (t *Torrent) IsDeleted() bool

IsDeleted : Return if a torrent status is deleted

func (*Torrent) IsNormal

func (t *Torrent) IsNormal() bool

IsNormal : Return if a torrent status is normal

func (*Torrent) IsRemake

func (t *Torrent) IsRemake() bool

IsRemake : Return if a torrent status is remake

func (*Torrent) IsTrusted

func (t *Torrent) IsTrusted() bool

IsTrusted : Return if a torrent status is trusted

func (*Torrent) ParseLanguages

func (t *Torrent) ParseLanguages()

func (*Torrent) ParseTrackers

func (t *Torrent) ParseTrackers(trackers []string)

ParseTrackers : Takes an array of trackers, adds needed trackers and parse it to url string

func (Torrent) Size

func (t Torrent) Size() (s int)

Size : Returns the total size of memory recursively allocated for this struct FIXME: Is it deprecated?

func (Torrent) TableName

func (t Torrent) TableName() string

TableName : Return the table name of torrents table

func (*Torrent) ToJSON

func (t *Torrent) ToJSON() TorrentJSON

ToJSON converts a models.Torrent to its equivalent JSON structure

func (*Torrent) Update

func (t *Torrent) Update(unscope bool) (int, error)

Update : Update a torrent based on model

func (*Torrent) UpdateUnscope

func (t *Torrent) UpdateUnscope() (int, error)

UpdateUnscope : Update a torrent based on model

type TorrentJSON

type TorrentJSON struct {
	ID           uint          `json:"id"`
	Name         string        `json:"name"`
	Status       int           `json:"status"`
	Hidden       bool          `json:"-"`
	Hash         string        `json:"hash"`
	Date         string        `json:"date"`
	Filesize     int64         `json:"filesize"`
	Description  template.HTML `json:"description"`
	Comments     []CommentJSON `json:"comments"`
	SubCategory  string        `json:"sub_category"`
	Category     string        `json:"category"`
	AnidbID      string        `json:"anidb_id"`
	UploaderID   uint          `json:"uploader_id"`
	UploaderName template.HTML `json:"uploader_name"`
	OldUploader  template.HTML `json:"uploader_old"`
	WebsiteLink  template.URL  `json:"website_link"`
	Languages    []string      `json:"languages"`
	Magnet       template.URL  `json:"magnet"`
	TorrentLink  template.URL  `json:"torrent"`
	Seeders      uint32        `json:"seeders"`
	Leechers     uint32        `json:"leechers"`
	Completed    uint32        `json:"completed"`
	LastScrape   time.Time     `json:"last_scrape"`
	FileList     []FileJSON    `json:"file_list"`
}

TorrentJSON for torrent model in json for api

func TorrentsToJSON

func TorrentsToJSON(t []Torrent) []TorrentJSON

TorrentsToJSON : Map Torrents to TorrentsToJSON without reallocations

func (*TorrentJSON) ToTorrent

func (t *TorrentJSON) ToTorrent() Torrent

ToTorrent : TODO: Need to get rid of TorrentJSON altogether and have only one true Torrent

model

type TorrentReport

type TorrentReport struct {
	ID          uint   `gorm:"column:torrent_report_id;primary_key"`
	Description string `gorm:"column:type"`
	TorrentID   uint   `gorm:"column:torrent_id"`
	UserID      uint   `gorm:"column:user_id"`

	CreatedAt time.Time `gorm:"column:created_at"`

	Torrent *Torrent `gorm:"AssociationForeignKey:TorrentID;ForeignKey:torrent_id"`
	User    *User    `gorm:"AssociationForeignKey:UserID;ForeignKey:user_id"`
}

TorrentReport model User can be null (anonymous reports) FIXME can't preload field Torrents for models.TorrentReport

func (*TorrentReport) Delete

func (report *TorrentReport) Delete(definitely bool) (int, error)

Delete : Delete torrent report

func (TorrentReport) TableName

func (report TorrentReport) TableName() string

TableName : Return the name of torrent report table

func (*TorrentReport) ToJSON

func (report *TorrentReport) ToJSON() TorrentReportJSON

ToJSON : conversion to json of a torrent report

type TorrentReportJSON

type TorrentReportJSON struct {
	ID          uint        `json:"id"`
	Description string      `json:"description"`
	Torrent     TorrentJSON `json:"torrent"`
	User        UserJSON    `json:"user"`
}

TorrentReportJSON : Json struct of torrent report model

func TorrentReportsToJSON

func TorrentReportsToJSON(reports []TorrentReport) []TorrentReportJSON

TorrentReportsToJSON : Conversion of multiple reports to json

type User

type User struct {
	ID             uint      `gorm:"column:user_id;primary_key"`
	Username       string    `gorm:"column:username;unique"`
	Password       string    `gorm:"column:password"`
	Email          string    `gorm:"column:email;unique"`
	Status         int       `gorm:"column:status"`
	CreatedAt      time.Time `gorm:"column:created_at"`
	UpdatedAt      time.Time `gorm:"column:updated_at"`
	APIToken       string    `gorm:"column:api_token"`
	APITokenExpiry time.Time `gorm:"column:api_token_expiry"`
	Language       string    `gorm:"column:language"`
	Theme          string    `gorm:"column:theme"`
	Mascot         string    `gorm:"column:mascot"`
	MascotURL      string    `gorm:"column:mascot_url"`
	UserSettings   string    `gorm:"column:settings"`

	// TODO: move this to PublicUser
	Followers []User // Don't work `gorm:"foreignkey:user_id;associationforeignkey:follower_id;many2many:user_follows"`
	Likings   []User // Don't work `gorm:"foreignkey:follower_id;associationforeignkey:user_id;many2many:user_follows"`

	MD5           string         `json:"md5" gorm:"column:md5"` // Hash of email address, used for Gravatar
	Torrents      []Torrent      `gorm:"ForeignKey:UploaderID"`
	Notifications []Notification `gorm:"ForeignKey:UserID"`

	UnreadNotifications int          `gorm:"-"` // We don't want to loop every notifications when accessing user unread notif
	Settings            UserSettings `gorm:"-"` // We don't want to load settings everytime, stock it as a string, parse it when needed
}

User model

func (*User) CanUpload

func (u *User) CanUpload() bool

CanUpload : Check if a user can upload or if upload is enabled in config

func (*User) CurrentOrAdmin

func (u *User) CurrentOrAdmin(userID uint) bool

CurrentOrAdmin check that user has admin permission or user is the current user.

func (*User) CurrentUserIdentical

func (u *User) CurrentUserIdentical(userID uint) bool

CurrentUserIdentical check that userID is same as current user's ID. TODO: Inline this (won't go do this for us?)

func (*User) Delete

func (u *User) Delete(currentUser *User) (int, error)

Delete deletes a user.

func (*User) Filter

func (u *User) Filter() *User

Filter : filter the hidden torrents

func (*User) GetFollowers

func (u *User) GetFollowers()

GetFollowers : Gets who is following the user

func (*User) GetLikings

func (u *User) GetLikings()

GetLikings : Gets who is followed by the user

func (*User) GetRole

func (u *User) GetRole() string

GetRole : Get the status/role of a user

func (*User) GetUnreadNotifications

func (u *User) GetUnreadNotifications() int

GetUnreadNotifications : Get unread notifications from a user

func (*User) HasAdmin

func (u *User) HasAdmin() bool

HasAdmin checks that user has an admin permission. Deprecated

func (*User) IsBanned

func (u *User) IsBanned() bool

IsBanned : Return true if user is banned

func (*User) IsFollower

func (follower *User) IsFollower(u *User) bool

IsFollower : Check if a user is following another

func (*User) IsMember

func (u *User) IsMember() bool

IsMember : Return true if user is member

func (*User) IsModerator

func (u *User) IsModerator() bool

IsModerator : Return true if user is moderator

func (*User) IsScraped

func (u *User) IsScraped() bool

IsScraped : Return true if user is a scrapped user

func (*User) IsTrusted

func (u *User) IsTrusted() bool

IsTrusted : Return true if user is tusted

func (*User) NeedsCaptcha

func (u *User) NeedsCaptcha() bool

NeedsCaptcha : Check if a user needs captcha

func (*User) ParseSettings

func (u *User) ParseSettings()

ParseSettings : Function to parse json string into usersettings struct, only parse if necessary

func (*User) RemoveFollow

func (u *User) RemoveFollow(follower *User)

RemoveFollow : Remove a user following another

func (*User) SaveSettings

func (u *User) SaveSettings()

SaveSettings : Format settings into a json string for preparing before user insertion

func (*User) SetFollow

func (u *User) SetFollow(follower *User)

SetFollow : Makes a user follow another

func (User) Size

func (u User) Size() (s int)

Size : Returns the total size of memory recursively allocated for this struct

func (*User) Splice

func (u *User) Splice(start int, length int) *User

Splice : get a subset of torrents

func (*User) ToJSON

func (u *User) ToJSON() UserJSON

ToJSON : Conversion of a user model to json

func (*User) Update

func (u *User) Update() (int, error)

Update updates a user. (Applying the modifed data of user).

func (*User) UpdateRaw

func (u *User) UpdateRaw() (int, error)

UpdateRaw : Function to update a user without updating his associations model

type UserFollows

type UserFollows struct {
	UserID     uint `gorm:"column:user_id"`
	FollowerID uint `gorm:"column:following"`
}

UserFollows association table : different users following eachother

type UserJSON

type UserJSON struct {
	ID          uint   `json:"user_id"`
	Username    string `json:"username"`
	Status      int    `json:"status"`
	APIToken    string `json:"token,omitempty"`
	MD5         string `json:"md5"`
	CreatedAt   string `json:"created_at"`
	LikingCount int    `json:"liking_count"`
	LikedCount  int    `json:"liked_count"`
}

UserJSON : User model conversion in JSON

type UserSettings

type UserSettings struct {
	Settings map[string]bool `json:"settings"`
}

UserSettings : Struct for user settings, not a model

func (*UserSettings) Get

func (s *UserSettings) Get(key string) bool

Get a user setting by keyname

func (*UserSettings) GetSettings

func (s *UserSettings) GetSettings() map[string]bool

GetSettings : get all user settings

func (*UserSettings) Set

func (s *UserSettings) Set(key string, val bool)

Set a user setting by keyname

func (*UserSettings) ToDefault

func (s *UserSettings) ToDefault()

ToDefault : Set user settings to default

type UserUploadsOld

type UserUploadsOld struct {
	Username  string `gorm:"column:username"`
	TorrentID uint   `gorm:"column:torrent_id"`
}

UserUploadsOld model : Is it deprecated?

func (UserUploadsOld) TableName

func (c UserUploadsOld) TableName() string

TableName : Return the name of OldComment table

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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