diff --git a/config/trackers.go b/config/trackers.go index 67ca8c98..d89b476f 100644 --- a/config/trackers.go +++ b/config/trackers.go @@ -1,5 +1,5 @@ package config const ( - Trackers = "&tr=udp://tracker.coppersurfer.tk:6969&tr=udp://zer0day.to:1337/announce&tr=udp://tracker.leechers-paradise.org:6969&tr=udp://explodie.org:6969&tr=udp://tracker.opentrackr.org:1337&tr=udp://tracker.pirateparty.gr:6969/announce&tr=udp://tracker.internetwarriors.net:1337/announce&tr=udp://eddie4.nl:6969/announce&tr=http://mgtracker.org:6969/announce&tr=http://tracker.baka-sub.cf/announce" + Trackers = "&tr=udp://tracker.coppersurfer.tk:6969&tr=udp://zer0day.to:1337/announce&tr=udp://tracker.leechers-paradise.org:6969&tr=udp://explodie.org:6969&tr=udp://tracker.opentrackr.org:1337&tr=udp://tracker.internetwarriors.net:1337/announce&tr=udp://eddie4.nl:6969/announce&tr=http://mgtracker.org:6969/announce&tr=http://tracker.baka-sub.cf/announce" ) diff --git a/db/gorm.go b/db/gorm.go index 93255109..9b2f5f4e 100644 --- a/db/gorm.go +++ b/db/gorm.go @@ -30,7 +30,7 @@ func GormInit(conf *config.Config) (*gorm.DB, error) { if config.Environment == "DEVELOPMENT" { db.LogMode(true) // db.DropTable(&model.User{}, "UserFollower") - db.AutoMigrate(&model.Torrents{}, &model.Categories{}, &model.Sub_Categories{}, &model.Statuses{}) + db.AutoMigrate(&model.Torrents{}) // db.AutoMigrate(&model.User{}, &model.Role{}, &model.Connection{}, &model.Language{}, &model.Article{}, &model.Location{}, &model.Comment{}, &model.File{}) // db.Model(&model.User{}).AddIndex("idx_user_token", "token") @@ -54,4 +54,4 @@ func GormInit(conf *config.Config) (*gorm.DB, error) { // handler.Setup(&relation, "users_followers", m1Type, m2Type) return db, err -} \ No newline at end of file +} diff --git a/model/torrent.go b/model/torrent.go index eedbefdb..4399758b 100644 --- a/model/torrent.go +++ b/model/torrent.go @@ -20,31 +20,11 @@ type Feed struct { Timestamp string } -type Categories struct { - Id int `gorm:"column:category_id"` - Name string `gorm:"column:category_name"` - Torrents []Torrents `gorm:"ForeignKey:category_id;AssociationForeignKey:category_id"` - Sub_Categories []Sub_Categories `gorm:"ForeignKey:parent_id;AssociationForeignKey:category_id"` -} - -type Sub_Categories struct { - Id int `gorm:"column:sub_category_id"` - Name string `gorm:"column:sub_category_name"` - Parent_id int `gorm:"column:parent_id"` - Torrents []Torrents `gorm:"ForeignKey:sub_category_id;AssociationForeignKey:sub_category_id"` -} - -type Statuses struct { - Status_id int - Status_name string - Torrents []Torrents `gorm:"ForeignKey:status_id;AssociationForeignKey:status_id"` -} - type Torrents struct { Id int `gorm:"column:torrent_id"` Name string `gorm:"column:torrent_name"` - Category_id int `gorm:"column:category_id"` - Sub_category_id int `gorm:"column:sub_category_id"` + Category int `gorm:"column:category_id"` + Sub_Category int `gorm:"column:sub_category_id"` Status int `gorm:"column:status_id"` Hash string `gorm:"column:torrent_hash"` Date int64 `gorm:"column:date"` @@ -52,9 +32,6 @@ type Torrents struct { Filesize int64 `gorm:"column:filesize"` Description []byte `gorm:"column:description"` Comments []byte `gorm:"column:comments"` - Statuses Statuses `gorm:"ForeignKey:status_id;AssociationForeignKey:status_id"` - Categories Categories `gorm:"ForeignKey:category_id;AssociationForeignKey:category_id"` - Sub_Categories Sub_Categories `gorm:"ForeignKey:sub_category_id;AssociationForeignKey:sub_category_id"` } /* We need JSON Object instead because of Magnet URL that is not in the database but generated dynamically @@ -63,17 +40,10 @@ JSON Models Oject -------------------------------------------------------------------------------------------------------------- */ -type CategoryJson struct { - Id string `json: "id"` - Name string `json: "category"` - Torrents []TorrentsJson `json: "torrents"` - QueryRecordCount int `json: "queryRecordCount"` - TotalRecordCount int `json: "totalRecordCount"` -} - -type SubCategoryJson struct { - Id string `json: "id"` - Name string `json: "category"` +type ApiResultJson struct { + Torrents []TorrentsJson `json:"torrents"` + QueryRecordCount int `json:"queryRecordCount"` + TotalRecordCount int `json:"totalRecordCount"` } type CommentsJson struct { @@ -87,17 +57,17 @@ type CommentsJson struct { } type TorrentsJson struct { - Id string `json: "id"` // Is there a need to put the ID? - Name string `json: "name"` - Status int `json: "status"` - Hash string `json: "hash"` - Date string `json: "date"` - Filesize string `json: "filesize"` - Description template.HTML `json: "description"` - Comments []CommentsJson `json: "comments"` - Sub_Category SubCategoryJson `json: "sub_category"` - Category CategoryJson `json: "category"` - Magnet template.URL `json: "magnet"` + Id string `json:"id"` + Name string `json:"name"` + Status int `json:"status"` + Hash string `json:"hash"` + Date string `json:"date"` + Filesize string `json:"filesize"` + Description template.HTML `json:"description"` + Comments []CommentsJson `json:"comments"` + Sub_Category string `json:"sub_category"` + Category string `json:"category"` + Magnet template.URL `json:"magnet"` } /* Model Conversion to Json */ @@ -115,23 +85,11 @@ func (t *Torrents) ToJson() TorrentsJson { Filesize: util.FormatFilesize(t.Filesize), Description: template.HTML(util.UnZlib(t.Description)), Comments: b, - Sub_Category: t.Sub_Categories.ToJson(), - Category: t.Categories.ToJson(), + Sub_Category: strconv.Itoa(t.Sub_Category), + Category: strconv.Itoa(t.Category), Magnet: util.Safe(magnet)} return res } -func (c *Sub_Categories) ToJson() SubCategoryJson { - return SubCategoryJson{ - Id: strconv.Itoa(c.Id), - Name: html.UnescapeString(c.Name)} -} - -func (c *Categories) ToJson() CategoryJson { - return CategoryJson{ - Id: strconv.Itoa(c.Id), - Name: html.UnescapeString(c.Name)} -} - /* Complete the functions when necessary... */ diff --git a/router/apiHandler.go b/router/apiHandler.go index 8f3ac90c..b80571ad 100644 --- a/router/apiHandler.go +++ b/router/apiHandler.go @@ -16,7 +16,7 @@ func ApiHandler(w http.ResponseWriter, r *http.Request) { page := vars["page"] pagenum, _ := strconv.Atoi(html.EscapeString(page)) - b := model.CategoryJson{Torrents: []model.TorrentsJson{}} + b := model.ApiResultJson{Torrents: []model.TorrentsJson{}} maxPerPage := 50 nbTorrents := 0 @@ -41,7 +41,7 @@ func ApiViewHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) id := vars["id"] - b := model.CategoryJson{Torrents: []model.TorrentsJson{}} + b := model.ApiResultJson{Torrents: []model.TorrentsJson{}} torrent, err := torrentService.GetTorrentById(id) res := torrent.ToJson() @@ -56,4 +56,4 @@ func ApiViewHandler(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusInternalServerError) return } -} \ No newline at end of file +} diff --git a/router/homeHandler.go b/router/homeHandler.go index e180d668..f897111d 100644 --- a/router/homeHandler.go +++ b/router/homeHandler.go @@ -39,7 +39,7 @@ func HomeHandler(w http.ResponseWriter, r *http.Request) { } navigationTorrents := templates.Navigation{nbTorrents, maxPerPage, pagenum, "search_page"} - htv := HomeTemplateVariables{b, torrentService.GetAllCategories(false), templates.NewSearchForm(), navigationTorrents, r.URL, mux.CurrentRoute(r)} + htv := HomeTemplateVariables{b, templates.NewSearchForm(), navigationTorrents, r.URL, mux.CurrentRoute(r)} err := homeTemplate.ExecuteTemplate(w, "index.html", htv) if err != nil { diff --git a/router/searchHandler.go b/router/searchHandler.go index 7a64dbf5..e0e08651 100644 --- a/router/searchHandler.go +++ b/router/searchHandler.go @@ -7,7 +7,6 @@ import ( "strconv" "github.com/ewhal/nyaa/model" - "github.com/ewhal/nyaa/service/torrent" "github.com/ewhal/nyaa/templates" "github.com/ewhal/nyaa/util/search" "github.com/gorilla/mux" @@ -43,7 +42,7 @@ func SearchHandler(w http.ResponseWriter, r *http.Request) { search_param.Order, false, } - htv := HomeTemplateVariables{b, torrentService.GetAllCategories(false), searchForm, navigationTorrents, r.URL, mux.CurrentRoute(r)} + htv := HomeTemplateVariables{b, searchForm, navigationTorrents, r.URL, mux.CurrentRoute(r)} err := searchTemplate.ExecuteTemplate(w, "index.html", htv) if err != nil { diff --git a/router/templateVariables.go b/router/templateVariables.go index c44a92cd..9b80e97c 100644 --- a/router/templateVariables.go +++ b/router/templateVariables.go @@ -40,7 +40,6 @@ type UserRegisterTemplateVariables struct { type HomeTemplateVariables struct { ListTorrents []model.TorrentsJson - ListCategories []model.Categories Search templates.SearchForm Navigation templates.Navigation URL *url.URL // For parsing Url in templates diff --git a/service/torrent/torrent.go b/service/torrent/torrent.go index 2e35123b..77444d51 100644 --- a/service/torrent/torrent.go +++ b/service/torrent/torrent.go @@ -43,7 +43,7 @@ func GetFeeds() []model.Feed { func GetTorrentById(id string) (model.Torrents, error) { var torrent model.Torrents - if db.ORM.Where("torrent_id = ?", id).Preload("Sub_Categories").Find(&torrent).RecordNotFound() { + if db.ORM.Where("torrent_id = ?", id).Find(&torrent).RecordNotFound() { return torrent, errors.New("Article is not found.") } @@ -69,7 +69,7 @@ func GetTorrentsOrderBy(parameters *WhereParams, orderBy string, limit int, offs if limit != 0 || offset != 0 { // if limits provided dbQuery = dbQuery.Limit(limit).Offset(offset) } - dbQuery.Order(orderBy).Preload("Categories").Preload("Sub_Categories").Find(&torrents) + dbQuery.Order(orderBy).Find(&torrents) return torrents, count } @@ -104,18 +104,6 @@ func GetAllTorrentsDB() ([]model.Torrents, int) { return GetTorrentsOrderBy(nil, "", 0, 0) } -/* Function to get all categories with/without torrents (bool) - */ -func GetAllCategories(populatedWithTorrents bool) []model.Categories { - var categories []model.Categories - if populatedWithTorrents { - db.ORM.Preload("Torrents").Preload("Sub_Categories").Find(&categories) - } else { - db.ORM.Preload("Sub_Categories").Find(&categories) - } - return categories -} - func CreateWhereParams(conditions string, params ...string) WhereParams { whereParams := WhereParams{} whereParams.Conditions = conditions diff --git a/templates/FAQ.html b/templates/FAQ.html index b2ab379c..9fd8ef66 100644 --- a/templates/FAQ.html +++ b/templates/FAQ.html @@ -53,6 +53,9 @@

Why is your shit written in Go?

It's the author's favorite programming language.

+
+ +

nyaa.pantsu.cat and sukebei.pantsu.cat do not host any files.

diff --git a/templates/home.html b/templates/home.html index 6f578b40..98c4a119 100644 --- a/templates/home.html +++ b/templates/home.html @@ -24,8 +24,8 @@ {{if eq .Status 4}}aplus{{end}}"> - - + + diff --git a/templates/view.html b/templates/view.html index 0a6bdd6b..7cef5efb 100644 --- a/templates/view.html +++ b/templates/view.html @@ -11,7 +11,7 @@ Name {{.Name}} - +