Added html views + fix template test + View & JSON Controller
Cette révision appartient à :
Parent
62ea1aaf10
révision
51d7fe2ef7
8 fichiers modifiés avec 147 ajouts et 12 suppressions
|
@ -129,6 +129,11 @@ torrents:
|
||||||
tags:
|
tags:
|
||||||
# Torrent Tag Max weight for automatic system approval
|
# Torrent Tag Max weight for automatic system approval
|
||||||
max_weight: 100.00
|
max_weight: 100.00
|
||||||
|
# Array of tag types allowed for now
|
||||||
|
types:
|
||||||
|
- anidbid
|
||||||
|
- vndbid
|
||||||
|
- quality
|
||||||
users:
|
users:
|
||||||
default_notifications_settings: {"new_torrent": true, "new_torrent_email": false, "new_comment": true, "new_comment_email": false, "new_responses": false, "new_responses_email": false, "new_follower": false, "new_follower_email": false, "followed": false, "followed_email": false}
|
default_notifications_settings: {"new_torrent": true, "new_torrent_email": false, "new_comment": true, "new_comment_email": false, "new_responses": false, "new_responses_email": false, "new_follower": false, "new_follower_email": false, "followed": false, "followed_email": false}
|
||||||
navigation:
|
navigation:
|
||||||
|
|
|
@ -48,6 +48,7 @@ type Config struct {
|
||||||
|
|
||||||
type Tags struct {
|
type Tags struct {
|
||||||
MaxWeight float64 `yaml:"max_weight,omitempty"`
|
MaxWeight float64 `yaml:"max_weight,omitempty"`
|
||||||
|
Types ArrayString `yaml:"types,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebAddressConfig : Config struct for web addresses
|
// WebAddressConfig : Config struct for web addresses
|
||||||
|
@ -102,7 +103,7 @@ type ScraperConfig struct {
|
||||||
|
|
||||||
// TrackersConfig ; Config struct for Trackers
|
// TrackersConfig ; Config struct for Trackers
|
||||||
type TrackersConfig struct {
|
type TrackersConfig struct {
|
||||||
Default []string `yaml:"default,flow,omitempty"`
|
Default ArrayString `yaml:"default,flow,omitempty"`
|
||||||
NeededTrackers []int `yaml:"needed,flow,omitempty"`
|
NeededTrackers []int `yaml:"needed,flow,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,9 +112,9 @@ type TorrentsConfig struct {
|
||||||
Status []bool `yaml:"status,omitempty,omitempty"`
|
Status []bool `yaml:"status,omitempty,omitempty"`
|
||||||
SukebeiCategories map[string]string `yaml:"sukebei_categories,omitempty"`
|
SukebeiCategories map[string]string `yaml:"sukebei_categories,omitempty"`
|
||||||
CleanCategories map[string]string `yaml:"clean_categories,omitempty"`
|
CleanCategories map[string]string `yaml:"clean_categories,omitempty"`
|
||||||
EnglishOnlyCategories []string `yaml:"english_only_categories,omitempty"`
|
EnglishOnlyCategories ArrayString `yaml:"english_only_categories,omitempty"`
|
||||||
NonEnglishOnlyCategories []string `yaml:"non_english_only_categories,omitempty"`
|
NonEnglishOnlyCategories ArrayString `yaml:"non_english_only_categories,omitempty"`
|
||||||
AdditionalLanguages []string `yaml:"additional_languages,omitempty"`
|
AdditionalLanguages ArrayString `yaml:"additional_languages,omitempty"`
|
||||||
FileStorage string `yaml:"filestorage,omitempty"`
|
FileStorage string `yaml:"filestorage,omitempty"`
|
||||||
StorageLink string `yaml:"storage_link,omitempty"`
|
StorageLink string `yaml:"storage_link,omitempty"`
|
||||||
CacheLink string `yaml:"cache_link,omitempty"`
|
CacheLink string `yaml:"cache_link,omitempty"`
|
||||||
|
@ -198,3 +199,14 @@ type SearchConfig struct {
|
||||||
ElasticsearchIndex string `yaml:"es_index,omitempty"`
|
ElasticsearchIndex string `yaml:"es_index,omitempty"`
|
||||||
ElasticsearchType string `yaml:"es_type,omitempty"`
|
ElasticsearchType string `yaml:"es_type,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ArrayString []string
|
||||||
|
|
||||||
|
func (ar ArrayString) Contains(str string) bool {
|
||||||
|
for _, s := range ar {
|
||||||
|
if s == str {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ func init() {
|
||||||
{
|
{
|
||||||
torrentRoutes.GET("/", TorrentEditUserPanel)
|
torrentRoutes.GET("/", TorrentEditUserPanel)
|
||||||
torrentRoutes.POST("/", TorrentPostEditUserPanel)
|
torrentRoutes.POST("/", TorrentPostEditUserPanel)
|
||||||
|
torrentRoutes.GET("/tag", ViewFormTag)
|
||||||
|
torrentRoutes.POST("/tag", ViewFormTag)
|
||||||
torrentRoutes.GET("/delete", TorrentDeleteUserPanel)
|
torrentRoutes.GET("/delete", TorrentDeleteUserPanel)
|
||||||
}
|
}
|
||||||
torrentViewRoutes := router.Get().Group("/view")
|
torrentViewRoutes := router.Get().Group("/view")
|
||||||
|
|
|
@ -1,8 +1,17 @@
|
||||||
package torrentController
|
package torrentController
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/NyaaPantsu/nyaa/controllers/router"
|
||||||
"github.com/NyaaPantsu/nyaa/models"
|
"github.com/NyaaPantsu/nyaa/models"
|
||||||
"github.com/NyaaPantsu/nyaa/models/tags"
|
"github.com/NyaaPantsu/nyaa/models/tags"
|
||||||
|
"github.com/NyaaPantsu/nyaa/models/torrents"
|
||||||
|
"github.com/NyaaPantsu/nyaa/templates"
|
||||||
msg "github.com/NyaaPantsu/nyaa/utils/messages"
|
msg "github.com/NyaaPantsu/nyaa/utils/messages"
|
||||||
"github.com/NyaaPantsu/nyaa/utils/validator"
|
"github.com/NyaaPantsu/nyaa/utils/validator"
|
||||||
"github.com/NyaaPantsu/nyaa/utils/validator/tags"
|
"github.com/NyaaPantsu/nyaa/utils/validator/tags"
|
||||||
|
@ -16,6 +25,12 @@ func postTag(c *gin.Context, torrent *models.Torrent, user *models.User) {
|
||||||
c.Bind(tagForm)
|
c.Bind(tagForm)
|
||||||
validator.ValidateForm(tagForm, messages)
|
validator.ValidateForm(tagForm, messages)
|
||||||
|
|
||||||
|
// We check that the tag type sent is one enabled in config.yml
|
||||||
|
if !tagsValidator.CheckTagType(tagForm.Type) {
|
||||||
|
messages.ErrorT(errors.New("wrong_tag_type"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for _, tag := range user.Tags {
|
for _, tag := range user.Tags {
|
||||||
if tag.Tag == tagForm.Tag {
|
if tag.Tag == tagForm.Tag {
|
||||||
return // already a tag by the user, don't add one more
|
return // already a tag by the user, don't add one more
|
||||||
|
@ -25,3 +40,45 @@ func postTag(c *gin.Context, torrent *models.Torrent, user *models.User) {
|
||||||
tags.Create(tagForm.Tag, tagForm.Type, torrent, user) // Add a tag to the db
|
tags.Create(tagForm.Tag, tagForm.Type, torrent, user) // Add a tag to the db
|
||||||
tags.Filter(tagForm.Tag, tagForm.Type, torrent.ID) // Check if we have a tag reaching the maximum weight, if yes, deletes every tag and add only the one accepted
|
tags.Filter(tagForm.Tag, tagForm.Type, torrent.ID) // Check if we have a tag reaching the maximum weight, if yes, deletes every tag and add only the one accepted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ViewFormTag(c *gin.Context) {
|
||||||
|
messages := msg.GetMessages(c)
|
||||||
|
user := router.GetUser(c)
|
||||||
|
id, _ := strconv.ParseInt(c.Query("id"), 10, 32)
|
||||||
|
// Retrieve the torrent
|
||||||
|
torrent, err := torrents.FindByID(uint(id))
|
||||||
|
|
||||||
|
// If torrent not found, display 404
|
||||||
|
if err != nil {
|
||||||
|
c.Status(http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// We load tags for user and torrents
|
||||||
|
user.LoadTags(torrent)
|
||||||
|
torrent.LoadTags()
|
||||||
|
|
||||||
|
// We add a tag if posted
|
||||||
|
if c.PostForm("tag") != "" && user.ID > 0 {
|
||||||
|
postTag(c, torrent, user)
|
||||||
|
if !messages.HasErrors() {
|
||||||
|
if _, ok := c.GetQuery("json"); ok {
|
||||||
|
c.JSON(http.StatusOK, struct {
|
||||||
|
Ok bool
|
||||||
|
}{true})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Redirect(http.StatusSeeOther, fmt.Sprintf("/view/%d", id))
|
||||||
|
}
|
||||||
|
if _, ok := c.GetQuery("json"); ok {
|
||||||
|
c.JSON(http.StatusOK, struct {
|
||||||
|
Ok bool
|
||||||
|
}{false})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tagForm := &tagsValidator.CreateForm{}
|
||||||
|
c.Bind(tagForm)
|
||||||
|
|
||||||
|
templates.Form(c, "/site/torrents/tag.jet.html", tagForm)
|
||||||
|
}
|
||||||
|
|
|
@ -10,12 +10,12 @@
|
||||||
{{ yield csrf_field() }}
|
{{ yield csrf_field() }}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="input-label" for="name">{{ T("name")}}</label>
|
<label class="input-label" for="name">{{ T("name")}}</label>
|
||||||
<input type="text" name="name" class="form-input up-input" placeholder="{{ T("file_name")}}" value="{{Form.Name}}" required/>
|
<input type="text" name="name" id="name" class="form-input up-input" placeholder="{{ T("file_name")}}" value="{{Form.Name}}" required/>
|
||||||
{{ yield errors(name="name")}}
|
{{ yield errors(name="name")}}
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="input-label" for="c">{{ T("category")}}</label>
|
<label class="input-label" for="c">{{ T("category")}}</label>
|
||||||
<select name="c" class="form-input up-input">
|
<select name="c" id="c" class="form-input up-input">
|
||||||
<option value="">{{ T("select_a_torrent_category")}}</option>
|
<option value="">{{ T("select_a_torrent_category")}}</option>
|
||||||
{{ range _, cat := GetCategories(false, true) }}
|
{{ range _, cat := GetCategories(false, true) }}
|
||||||
<option value="{{ cat.ID }}" {{if Form.Category == cat.ID }}selected{{end}}>{{T(cat.Name) }}</option>
|
<option value="{{ cat.ID }}" {{if Form.Category == cat.ID }}selected{{end}}>{{T(cat.Name) }}</option>
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="input-label" for="language">{{ T("torrent_language") }}</label>
|
<label class="input-label" for="language">{{ T("torrent_language") }}</label>
|
||||||
<div name="language" class="form-input language">
|
<div name="language" id="language" class="form-input language">
|
||||||
{{ yield flagList(languages=GetTorrentLanguages(), selected=Form.Languages) }}
|
{{ yield flagList(languages=GetTorrentLanguages(), selected=Form.Languages) }}
|
||||||
</div>
|
</div>
|
||||||
{{ yield errors(name="language")}}
|
{{ yield errors(name="language")}}
|
||||||
|
|
29
templates/site/torrents/tag.jet.html
Fichier normal
29
templates/site/torrents/tag.jet.html
Fichier normal
|
@ -0,0 +1,29 @@
|
||||||
|
{{ extends "layouts/index_site" }}
|
||||||
|
{{ import "layouts/partials/helpers/csrf" }}
|
||||||
|
{{ import "layouts/partials/helpers/errors" }}
|
||||||
|
{{block title()}}{{T("add_tag")}}{{end}}
|
||||||
|
{{block content_body()}}
|
||||||
|
<div class="box results">
|
||||||
|
<h3 id="torrents">{{ T("add_tag") }}</h3>
|
||||||
|
<form style="text-align:left;padding-left:10px;padding-right:10px;" enctype="multipart/form-data" role="upload" method="POST">
|
||||||
|
{{ yield csrf_field() }}
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="input-label" for="tag">{{ T("tag")}}</label>
|
||||||
|
<input type="text" id="tag" name="tag" class="form-input up-input" placeholder="{{ T("file_name")}}" value="{{Form.Tag}}" required/>
|
||||||
|
{{ yield errors(name="Tag")}}
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="input-label" for="type">{{ T("tagtype")}}</label>
|
||||||
|
<select name="type" id="type" class="form-input up-input">
|
||||||
|
{{ range _, type := Config.Torrents.Tags.Types }}
|
||||||
|
<option value="{{ type }}" {{if Form.Type == type }}selected{{end}}>{{T("tagtype_" + type) }}</option>
|
||||||
|
{{ end }}
|
||||||
|
</select>
|
||||||
|
{{ yield errors(name="Type")}}
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="form-input up-input btn-green">{{ T("add")}}</button>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
|
@ -47,12 +47,14 @@ type ContextTest map[string]func(jet.VarMap) jet.VarMap
|
||||||
func walkDirTest(dir string, t *testing.T) {
|
func walkDirTest(dir string, t *testing.T) {
|
||||||
fu := "http://nyaa.cat"
|
fu := "http://nyaa.cat"
|
||||||
em := "cop@cat.fe"
|
em := "cop@cat.fe"
|
||||||
fakeUser := &models.User{1, "test", "test", "test", 1, time.Now(), time.Now(), "test", time.Now(), "en", "test", "test", "test", "test", []models.User{}, []models.User{}, "test", []models.Torrent{}, []models.Notification{}, 1, models.UserSettings{}}
|
|
||||||
|
fakeTag := &models.Tag{1, 1, "12345", "anidbid", 1, false, 0}
|
||||||
|
fakeUser := &models.User{1, "test", "test", "test", 1, time.Now(), time.Now(), "test", time.Now(), "en", "test", "test", "test", "test", 0, []models.User{}, []models.User{}, "test", []models.Torrent{}, []models.Notification{}, 1, models.UserSettings{}, []models.Tag{*fakeTag}}
|
||||||
fakeComment := &models.Comment{1, 1, 1, "test", time.Now(), time.Now(), nil, &models.Torrent{}, fakeUser}
|
fakeComment := &models.Comment{1, 1, 1, "test", time.Now(), time.Now(), nil, &models.Torrent{}, fakeUser}
|
||||||
fakeScrapeData := &models.Scrape{1, 0, 0, 10, time.Now()}
|
fakeScrapeData := &models.Scrape{1, 0, 0, 10, time.Now()}
|
||||||
fakeFile := &models.File{1, 1, "l12:somefile.mp4e", 3}
|
fakeFile := &models.File{1, 1, "l12:somefile.mp4e", 3}
|
||||||
fakeLanguages := []string{"fr", "en"}
|
fakeLanguages := []string{"fr", "en"}
|
||||||
fakeTorrent := &models.Torrent{1, "test", "test", 3, 12, 1, false, time.Now(), 1, 0, 3, "test", "test", "test", "test", "test", nil, fakeUser, "test", []models.OldComment{}, []models.Comment{*fakeComment, *fakeComment}, fakeScrapeData, []models.File{*fakeFile}, fakeLanguages}
|
fakeTorrent := &models.Torrent{1, "test", "test", 3, 12, 1, false, time.Now(), 1, 0, 3, "test", "test", "test", "test", "test", nil, fakeUser, "test", []models.OldComment{}, []models.Comment{*fakeComment, *fakeComment}, []models.Tag{*fakeTag, *fakeTag}, fakeScrapeData, []models.File{*fakeFile}, fakeLanguages}
|
||||||
fakeActivity := &models.Activity{1, "t", "e", "s", 1, fakeUser}
|
fakeActivity := &models.Activity{1, "t", "e", "s", 1, fakeUser}
|
||||||
fakeDB := &models.DatabaseDump{time.Now(), 3, "test", "test"}
|
fakeDB := &models.DatabaseDump{time.Now(), 3, "test", "test"}
|
||||||
fakeLanguage := &publicSettings.Language{"English", "en", "en-us"}
|
fakeLanguage := &publicSettings.Language{"English", "en", "en-us"}
|
||||||
|
@ -63,6 +65,7 @@ func walkDirTest(dir string, t *testing.T) {
|
||||||
fakeOauthForm := apiValidator.CreateForm{"", "f", []string{fu}, []string{}, []string{}, "", "fedr", fu, fu, fu, fu, []string{em}, ""}
|
fakeOauthForm := apiValidator.CreateForm{"", "f", []string{fu}, []string{}, []string{}, "", "fedr", fu, fu, fu, fu, []string{em}, ""}
|
||||||
fakeOauthModel := fakeOauthForm.Bind(&models.OauthClient{})
|
fakeOauthModel := fakeOauthForm.Bind(&models.OauthClient{})
|
||||||
fakeClient := client.Client{"", "", "", []string{""}, []string{""}, []string{""}, "", "", "", "", "", "", []string{""}, false}
|
fakeClient := client.Client{"", "", "", []string{""}, []string{""}, []string{""}, "", "", "", "", "", "", []string{""}, false}
|
||||||
|
|
||||||
contextvariables := ContextTest{
|
contextvariables := ContextTest{
|
||||||
"dumps.jet.html": func(variables jet.VarMap) jet.VarMap {
|
"dumps.jet.html": func(variables jet.VarMap) jet.VarMap {
|
||||||
variables.Set("GPGLink", "test")
|
variables.Set("GPGLink", "test")
|
||||||
|
@ -158,7 +161,6 @@ func walkDirTest(dir string, t *testing.T) {
|
||||||
return variables
|
return variables
|
||||||
},
|
},
|
||||||
"callback.jet.html": func(variables jet.VarMap) jet.VarMap {
|
"callback.jet.html": func(variables jet.VarMap) jet.VarMap {
|
||||||
|
|
||||||
variables.Set("Callback", true)
|
variables.Set("Callback", true)
|
||||||
variables.Set("AccessToken", "")
|
variables.Set("AccessToken", "")
|
||||||
variables.Set("RefreshToken", "")
|
variables.Set("RefreshToken", "")
|
||||||
|
@ -190,6 +192,10 @@ func walkDirTest(dir string, t *testing.T) {
|
||||||
variables.Set("Form", fakeOauthForm)
|
variables.Set("Form", fakeOauthForm)
|
||||||
return variables
|
return variables
|
||||||
},
|
},
|
||||||
|
"tag.jet.html": func(variables jet.VarMap) jet.VarMap {
|
||||||
|
variables.Set("Form", fakeTag)
|
||||||
|
return variables
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("\nTesting Folder: %s\n", dir)
|
fmt.Printf("\nTesting Folder: %s\n", dir)
|
||||||
|
|
|
@ -1926,5 +1926,29 @@
|
||||||
{
|
{
|
||||||
"id": "torrent_age",
|
"id": "torrent_age",
|
||||||
"translation": "{1} days {2} hours ago"
|
"translation": "{1} days {2} hours ago"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "wrong_tag_type",
|
||||||
|
"translation": "The tag type selected doesn't exist"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "add_tag",
|
||||||
|
"translation": "Add a Tag"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "tagtype",
|
||||||
|
"translation": "Tag Type"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "tagtype_anidbid",
|
||||||
|
"translation": "Anidb ID"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "tagtype_vndbid",
|
||||||
|
"translation": "VNdb ID"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "tagtype_quality",
|
||||||
|
"translation": "Quality tag"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
Référencer dans un nouveau ticket