Documentation
¶
Index ¶
- Constants
- Variables
- func ElasticSearchInit() (*elastic.Client, error)
- func GormInit(conf *config.Config, logger Logger) (*gorm.DB, error)
- type Activity
- type Comment
- type CommentJSON
- type DatabaseDump
- type DatabaseDumpJSON
- type File
- type FileJSON
- type Language
- type Logger
- type Notification
- type OldComment
- type Scrape
- type Torrent
- func (t Torrent) AddToESIndex(client *elastic.Client) error
- func (t *Torrent) DefinitelyDelete() (*Torrent, int, error)
- func (t *Torrent) Delete(definitely bool) (*Torrent, int, error)
- func (t *Torrent) DeleteFromESIndex(client *elastic.Client) error
- func (t *Torrent) EncodeLanguages()
- func (t *Torrent) GetTrackersArray() (trackers []string)
- func (t *Torrent) Identifier() string
- func (t *Torrent) IsAPlus() bool
- func (t *Torrent) IsBlocked() bool
- func (t *Torrent) IsDeleted() bool
- func (t *Torrent) IsNormal() bool
- func (t *Torrent) IsRemake() bool
- func (t *Torrent) IsTrusted() bool
- func (t *Torrent) ParseLanguages()
- func (t *Torrent) ParseTrackers(trackers []string)
- func (t Torrent) Size() (s int)
- func (t Torrent) TableName() string
- func (t *Torrent) ToJSON() TorrentJSON
- func (t *Torrent) Update(unscope bool) (int, error)
- func (t *Torrent) UpdateUnscope() (int, error)
- type TorrentJSON
- type TorrentReport
- type TorrentReportJSON
- type User
- func (u *User) CanUpload() bool
- func (u *User) CurrentOrAdmin(userID uint) bool
- func (u *User) CurrentUserIdentical(userID uint) bool
- func (u *User) Delete(currentUser *User) (int, error)
- func (u *User) Filter() *User
- func (u *User) GetFollowers()
- func (u *User) GetLikings()
- func (u *User) GetRole() string
- func (u *User) GetUnreadNotifications() int
- func (u *User) HasAdmin() bool
- func (u *User) IsBanned() bool
- func (follower *User) IsFollower(u *User) bool
- func (u *User) IsMember() bool
- func (u *User) IsModerator() bool
- func (u *User) IsScraped() bool
- func (u *User) IsTrusted() bool
- func (u *User) NeedsCaptcha() bool
- func (u *User) ParseSettings()
- func (u *User) RemoveFollow(follower *User)
- func (u *User) SaveSettings()
- func (u *User) SetFollow(follower *User)
- func (u User) Size() (s int)
- func (u *User) Splice(start int, length int) *User
- func (u *User) ToJSON() UserJSON
- func (u *User) Update() (int, error)
- func (u *User) UpdateRaw() (int, error)
- type UserFollows
- type UserJSON
- type UserSettings
- type UserUploadsOld
Constants ¶
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 )
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 )
const (
// SqliteType : name of the sqlite type in gorm
SqliteType = "sqlite3"
)
Variables ¶
var ElasticSearchClient *elastic.Client
ElasticSearchClient : Client for Elastic search
var IsSqlite bool
IsSqlite : Variable to know if we are in sqlite or postgres
var ORM *gorm.DB
ORM : Variable for interacting with database
Functions ¶
func ElasticSearchInit ¶
ElasticSearchInit : Initialization of ES client
Types ¶
type Activity ¶
type Activity struct {
ID uint
Content string
Identifier string
Filter string
UserID uint
User *User
}
Activity model
func NewActivity ¶
NewActivity : Create a new activity log
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 ¶
Identifier : Return the identifier of the comment
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 ¶
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
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
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 ¶
AddToESIndex : Adds a torrent to Elastic Search
func (*Torrent) DefinitelyDelete ¶
DefinitelyDelete : deletes definitely a torrent based on id
func (*Torrent) DeleteFromESIndex ¶
DeleteFromESIndex : Removes a torrent from Elastic Search
func (*Torrent) EncodeLanguages ¶
func (t *Torrent) EncodeLanguages()
func (*Torrent) GetTrackersArray ¶
GetTrackersArray : Convert trackers string to Array
func (*Torrent) Identifier ¶
Identifier : Return the identifier of a torrent
func (*Torrent) ParseLanguages ¶
func (t *Torrent) ParseLanguages()
func (*Torrent) ParseTrackers ¶
ParseTrackers : Takes an array of trackers, adds needed trackers and parse it to url string
func (Torrent) Size ¶
Size : Returns the total size of memory recursively allocated for this struct FIXME: Is it deprecated?
func (*Torrent) ToJSON ¶
func (t *Torrent) ToJSON() TorrentJSON
ToJSON converts a models.Torrent to its equivalent JSON structure
func (*Torrent) UpdateUnscope ¶
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) CurrentOrAdmin ¶
CurrentOrAdmin check that user has admin permission or user is the current user.
func (*User) CurrentUserIdentical ¶
CurrentUserIdentical check that userID is same as current user's ID. TODO: Inline this (won't go do this for us?)
func (*User) GetFollowers ¶
func (u *User) GetFollowers()
GetFollowers : Gets who is following the user
func (*User) GetUnreadNotifications ¶
GetUnreadNotifications : Get unread notifications from a user
func (*User) IsFollower ¶
IsFollower : Check if a user is following another
func (*User) IsModerator ¶
IsModerator : Return true if user is moderator
func (*User) NeedsCaptcha ¶
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 ¶
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
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 ¶
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