Albirew/nyaa-pantsu
Albirew
/
nyaa-pantsu
Archivé
1
0
Bifurcation 0

Verify torrent category on upload

Added a new package, "categories", with the valid categories for each
Nyaa and Sukebei. On upload, check if the category is present on
the valid ones. Also changed the template function Category_Nyaa and
Category_Sukebei to reflect this.
Cette révision appartient à :
ElegantMonkey 2017-05-22 13:25:04 -03:00
Parent 69b1a7f13e
révision 331143e094
6 fichiers modifiés avec 82 ajouts et 53 suppressions

Voir le fichier

@ -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) {

Voir le fichier

@ -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 {

Voir le fichier

@ -21,9 +21,9 @@
<td style="width:80px">
<a href="{{$.URL.Parse (printf "/search?c=%s_%s" .Category .SubCategory) }}">
{{ if Sukebei }}
<img src="{{$.URL.Parse (printf "/img/torrents/sukebei/%s%s.png" .Category .SubCategory) }}" title="{{ call $.T (Category_Sukebei .Category .SubCategory) }}">
<img src="{{$.URL.Parse (printf "/img/torrents/sukebei/%s%s.png" .Category .SubCategory) }}" title="{{ call $.T (CategoryID .Category .SubCategory) }}">
{{ else }}
<img src="{{$.URL.Parse (printf "/img/torrents/%s.png" .SubCategory) }}" title="{{ call $.T (Category_Nyaa .Category .SubCategory) }}">
<img src="{{$.URL.Parse (printf "/img/torrents/%s.png" .SubCategory) }}" title="{{ call $.T (CategoryID .Category .SubCategory) }}">
{{ end}}
</a>
</td>

Voir le fichier

@ -47,9 +47,9 @@ Your browser does not support the audio element.
<td class="hidden-xs" style="width:80px">
<a href="{{$.URL.Parse (printf "/search?c=%s_%s" .Category .SubCategory) }}">
{{ if Sukebei }}
<img src="{{$.URL.Parse (printf "/img/torrents/sukebei/%s%s.png" .Category .SubCategory) }}" title="{{ call $.T (Category_Sukebei .Category .SubCategory) }}">
<img src="{{$.URL.Parse (printf "/img/torrents/sukebei/%s%s.png" .Category .SubCategory) }}" title="{{ call $.T (CategoryID .Category .SubCategory) }}">
{{ else }}
<img src="{{$.URL.Parse (printf "/img/torrents/%s.png" .SubCategory) }}" title="{{ call $.T (Category_Nyaa .Category .SubCategory) }}">
<img src="{{$.URL.Parse (printf "/img/torrents/%s.png" .SubCategory) }}" title="{{ call $.T (CategoryID .Category .SubCategory) }}">
{{ end}}
</a>
</td>

Voir le fichier

@ -22,11 +22,11 @@
<div class="col-md-12">
<div style="float: left;">
{{ if Sukebei }}
<img style="float:left; margin-right: 1em;" src="{{$.URL.Parse (printf "/img/torrents/sukebei/%s%s.png" .Category .SubCategory) }}" title="{{ call $.T (Category_Sukebei .Category .SubCategory) }}">
<span style="vertical-align:middle;font-size:large;">{{ call $.T (Category_Sukebei .Category .SubCategory) }}</span>
<img style="float:left; margin-right: 1em;" src="{{$.URL.Parse (printf "/img/torrents/sukebei/%s%s.png" .Category .SubCategory) }}" title="{{ call $.T (CategoryID .Category .SubCategory) }}">
<span style="vertical-align:middle;font-size:large;">{{ call $.T (CategoryID .Category .SubCategory) }}</span>
{{ else }}
<img style="float:left; margin-right: 1em;" src="{{$.URL.Parse (printf "/img/torrents/%s.png" .SubCategory) }}" title="{{ call $.T (Category_Nyaa .Category .SubCategory) }}">
<span style="vertical-align:middle;font-size:large;">{{ call $.T (Category_Nyaa .Category .SubCategory) }}</span>
<img style="float:left; margin-right: 1em;" src="{{$.URL.Parse (printf "/img/torrents/%s.png" .SubCategory) }}" title="{{ call $.T (CategoryID .Category .SubCategory) }}">
<span style="vertical-align:middle;font-size:large;">{{ call $.T (CategoryID .Category .SubCategory) }}</span>
{{ end }}
<br />
<h4 style="display:inline-block">

60
util/categories/categories.go Fichier normal
Voir le fichier

@ -0,0 +1,60 @@
package categories
import (
"github.com/NyaaPantsu/nyaa/config"
)
var categories map[string]string
func GetCategories() map[string]string {
if categories != nil {
return categories
}
if config.IsSukebei() {
categories = map[string]string{
"1_": "art",
"1_1": "art_anime",
"1_2": "art_doujinshi",
"1_3": "art_games",
"1_4": "art_manga",
"1_5": "art_pictures",
"2_": "real_life",
"2_1": "real_life_photobooks_and_pictures",
"2_2": "real_life_videos",
}
} else {
categories = map[string]string{
"3_": "anime",
"3_12": "anime_amv",
"3_5": "anime_english_translated",
"3_13": "anime_non_english_translated",
"3_6": "anime_raw",
"2_": "audio",
"2_3": "audio_lossless",
"2_4": "audio_lossy",
"4_": "literature",
"4_7": "literature_english_translated",
"4_8": "literature_raw",
"4_14": "literature_non_english_translated",
"5_": "live_action",
"5_9": "live_action_english_translated",
"5_10": "live_action_idol_pv",
"5_18": "live_action_non_english_translated",
"5_11": "live_action_raw",
"6_": "pictures",
"6_15": "pictures_graphics",
"6_16": "pictures_photos",
"1_": "software",
"1_1": "software_applications",
"1_2": "software_games",
}
}
return categories
}
func CategoryExists(category string) bool {
_, exists := GetCategories()[category]
return exists
}