Fix categories on sukebei
Cette révision appartient à :
Parent
a69b0b4ead
révision
b797b7aacf
2 fichiers modifiés avec 17 ajouts et 5 suppressions
|
@ -3,6 +3,7 @@ package router
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/NyaaPantsu/nyaa/config"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,6 +13,9 @@ var once sync.Once
|
||||||
// Get return a router signleton
|
// Get return a router signleton
|
||||||
func Get() *gin.Engine {
|
func Get() *gin.Engine {
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
|
if config.Get().Environment == "PRODUCTION" {
|
||||||
|
gin.SetMode(gin.ReleaseMode)
|
||||||
|
}
|
||||||
router = gin.New()
|
router = gin.New()
|
||||||
router.Use(gin.Logger())
|
router.Use(gin.Logger())
|
||||||
router.Use(gin.Recovery())
|
router.Use(gin.Recovery())
|
||||||
|
|
|
@ -3,6 +3,8 @@ package categories
|
||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/NyaaPantsu/nyaa/config"
|
"github.com/NyaaPantsu/nyaa/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,7 +23,10 @@ var Index map[string]int
|
||||||
// InitCategories init the categories and index variables. Exported for tests
|
// InitCategories init the categories and index variables. Exported for tests
|
||||||
func InitCategories() {
|
func InitCategories() {
|
||||||
var cats map[string]string
|
var cats map[string]string
|
||||||
|
fmt.Println(config.Get().Models.TorrentsTableName)
|
||||||
|
fmt.Println(config.IsSukebei())
|
||||||
if config.IsSukebei() {
|
if config.IsSukebei() {
|
||||||
|
fmt.Println("works")
|
||||||
cats = config.Get().Torrents.SukebeiCategories
|
cats = config.Get().Torrents.SukebeiCategories
|
||||||
} else {
|
} else {
|
||||||
cats = config.Get().Torrents.CleanCategories
|
cats = config.Get().Torrents.CleanCategories
|
||||||
|
@ -44,24 +49,27 @@ func InitCategories() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
// All : function to get all categories depending on the actual website from config/categories.go
|
||||||
|
func All() Categories {
|
||||||
if len(categories) == 0 {
|
if len(categories) == 0 {
|
||||||
InitCategories()
|
InitCategories()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// All : function to get all categories depending on the actual website from config/categories.go
|
|
||||||
func All() Categories {
|
|
||||||
return categories
|
return categories
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get : function to get a category by the key in the index array
|
// Get : function to get a category by the key in the index array
|
||||||
func Get(key int) Category {
|
func Get(key int) Category {
|
||||||
|
if len(categories) == 0 {
|
||||||
|
InitCategories()
|
||||||
|
}
|
||||||
return All()[key]
|
return All()[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetByID : function to get a category by the id of the category from the database
|
// GetByID : function to get a category by the id of the category from the database
|
||||||
func GetByID(id string) (Category, bool) {
|
func GetByID(id string) (Category, bool) {
|
||||||
|
if len(categories) == 0 {
|
||||||
|
InitCategories()
|
||||||
|
}
|
||||||
if key, ok := Index[id]; ok {
|
if key, ok := Index[id]; ok {
|
||||||
return All()[key], true
|
return All()[key], true
|
||||||
}
|
}
|
||||||
|
|
Référencer dans un nouveau ticket