diff --git a/router/template_functions.go b/router/template_functions.go index 9c8e15c5..172ffaff 100644 --- a/router/template_functions.go +++ b/router/template_functions.go @@ -10,6 +10,7 @@ import ( "github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/service/user/permission" "github.com/NyaaPantsu/nyaa/util" + "github.com/NyaaPantsu/nyaa/util/categories" "github.com/NyaaPantsu/nyaa/util/languages" ) @@ -161,51 +162,14 @@ var FuncMap = template.FuncMap{ // because time.* isn't available in templates... return t.Format(time.RFC3339) }, - "Category_Sukebei": func(category string, sub_category string) string { - s := category + "_" + sub_category; e := "" - switch s { - default: e = "" - case "1_": e = "art" - case "1_1": e = "art_anime" - case "1_2": e = "art_doujinshi" - case "1_3": e = "art_games" - case "1_4": e = "art_manga" - case "1_5": e = "art_pictures" - case "2_": e = "real_life" - case "2_1": e = "real_life_photobooks_and_pictures" - case "2_2": e = "real_life_videos" - } - return e - }, - "Category_Nyaa": func(category string, sub_category string) string { - s := category + "_" + sub_category; e := "" - switch s { - default: e = "" - case "3_": e = "anime" - case "3_12": e = "anime_amv" - case "3_5": e = "anime_english_translated" - case "3_13": e = "anime_non_english_translated" - case "3_6": e = "anime_raw" - case "2_": e = "audio" - case "2_3": e = "audio_lossless" - case "2_4": e = "audio_lossy" - case "4_": e = "literature" - case "4_7": e = "literature_english_translated" - case "4_8": e = "literature_raw" - case "4_14": e = "literature_non_english_translated" - case "5_": e = "live_action" - case "5_9": e = "live_action_english_translated" - case "5_10": e = "live_action_idol_pv" - case "5_18": e = "live_action_non_english_translated" - case "5_11": e = "live_action_raw" - case "6_": e = "pictures" - case "6_15": e = "pictures_graphics" - case "6_16": e = "pictures_photos" - case "1_": e = "software" - case "1_1": e = "software_applications" - case "1_2": e = "software_games" - } - return e + "CategoryID": func(category string, sub_category string) string { + s := category + "_" + sub_category + + if category, ok := categories.GetCategories()[s]; ok { + return category + } else { + return "" + } }, "fileSize": func(filesize int64, T languages.TemplateTfunc) template.HTML { if (filesize == 0) { diff --git a/router/upload.go b/router/upload.go index 74ce5abc..9d880815 100644 --- a/router/upload.go +++ b/router/upload.go @@ -19,6 +19,7 @@ import ( "github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/service/upload" "github.com/NyaaPantsu/nyaa/util" + "github.com/NyaaPantsu/nyaa/util/categories" "github.com/NyaaPantsu/nyaa/util/metainfo" "github.com/microcosm-cc/bluemonday" "github.com/zeebo/bencode" @@ -117,6 +118,10 @@ func (f *UploadForm) ExtractInfo(r *http.Request) error { return ErrInvalidTorrentCategory } + if !categories.CategoryExists(f.Category) { + return ErrInvalidTorrentCategory + } + f.CategoryID = CatID f.SubCategoryID = SubCatID } else { diff --git a/templates/_user_list_torrents.html b/templates/_user_list_torrents.html index aff9cf43..2488df4b 100644 --- a/templates/_user_list_torrents.html +++ b/templates/_user_list_torrents.html @@ -21,9 +21,9 @@