Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Torrent Hidden Option (to test before merging)

* Added a check on username and userId when converting torrent to JSON
* Added a checkbox for hidden in modepanel, torrent user edit and upload
* Added a Hidden field bool in torrent model and upload form
Cette révision appartient à :
akuma06 2017-05-27 20:33:40 +02:00 révisé par kipukun
Parent ab2d4efead
révision 77d4c3c8a8
9 fichiers modifiés avec 36 ajouts et 12 suppressions

Voir le fichier

@ -49,6 +49,7 @@ type Torrent struct {
Category int `gorm:"column:category"`
SubCategory int `gorm:"column:sub_category"`
Status int `gorm:"column:status"`
Hidden bool `gorm:"column:hidden"`
Date time.Time `gorm:"column:date"`
UploaderID uint `gorm:"column:uploader"`
Downloads int `gorm:"column:downloads"`
@ -267,8 +268,10 @@ func (t *Torrent) ToJSON() TorrentJSON {
})
uploader := ""
if t.Uploader != nil {
var uploaderID uint
if t.Uploader != nil && !t.Hidden {
uploader = t.Uploader.Username
uploaderID = t.UploaderID
}
torrentlink := ""
if t.ID <= config.LastOldTorrentID && len(config.TorrentCacheLink) > 0 {
@ -292,7 +295,7 @@ func (t *Torrent) ToJSON() TorrentJSON {
SubCategory: strconv.Itoa(t.SubCategory),
Category: strconv.Itoa(t.Category),
Downloads: t.Downloads,
UploaderID: t.UploaderID,
UploaderID: uploaderID,
UploaderName: util.SafeText(uploader),
OldUploader: util.SafeText(t.OldUploader),
WebsiteLink: util.Safe(t.WebsiteLink),

Voir le fichier

@ -275,6 +275,7 @@ func TorrentEditModPanel(w http.ResponseWriter, r *http.Request) {
uploadForm.Name = torrentJSON.Name
uploadForm.Category = torrentJSON.Category + "_" + torrentJSON.SubCategory
uploadForm.Status = torrentJSON.Status
uploadForm.Hidden = torrent.Hidden
uploadForm.WebsiteLink = string(torrentJSON.WebsiteLink)
uploadForm.Description = string(torrentJSON.Description)
htv := formTemplateVariables{newPanelCommonVariables(r), uploadForm, messages.GetAllErrors(), messages.GetAllInfos()}
@ -300,6 +301,7 @@ func TorrentPostEditModPanel(w http.ResponseWriter, r *http.Request) {
torrent.Category = uploadForm.CategoryID
torrent.SubCategory = uploadForm.SubCategoryID
torrent.Status = uploadForm.Status
torrent.Hidden = uploadForm.Hidden
torrent.WebsiteLink = uploadForm.WebsiteLink
torrent.Description = uploadForm.Description
// torrent.Uploader = nil // GORM will create a new user otherwise (wtf?!)

Voir le fichier

@ -74,10 +74,6 @@ type changeLanguageVariables struct {
Languages map[string]string
}
type ChangeThemeVariables struct {
commonTemplateVariables
}
type publicSettingsVariables struct {
commonTemplateVariables
Language string

Voir le fichier

@ -38,6 +38,7 @@ type uploadForm struct {
Remake bool
Description string
Status int
Hidden bool
CaptchaID string
WebsiteLink string
@ -61,6 +62,7 @@ const uploadFormRemake = "remake"
const uploadFormDescription = "desc"
const uploadFormWebsiteLink = "website_link"
const uploadFormStatus = "status"
const uploadFormHidden = "hidden"
// error indicating that you can't send both a magnet link and torrent
var errTorrentPlusMagnet = errors.New("Upload either a torrent file or magnet link, not both")
@ -97,6 +99,7 @@ func (f *uploadForm) ExtractInfo(r *http.Request) error {
f.Status, _ = strconv.Atoi(r.FormValue(uploadFormStatus))
f.Magnet = r.FormValue(uploadFormMagnet)
f.Remake = r.FormValue(uploadFormRemake) == "on"
f.Hidden = r.FormValue(uploadFormHidden) == "on"
// trim whitespace
f.Name = util.TrimWhitespaces(f.Name)
@ -242,6 +245,7 @@ func (f *uploadForm) ExtractEditInfo(r *http.Request) error {
f.Category = r.FormValue(uploadFormCategory)
f.WebsiteLink = r.FormValue(uploadFormWebsiteLink)
f.Description = r.FormValue(uploadFormDescription)
f.Hidden = r.FormValue(uploadFormHidden) == "on"
f.Status, _ = strconv.Atoi(r.FormValue(uploadFormStatus))
// trim whitespace

Voir le fichier

@ -2,11 +2,12 @@ package router
import (
"fmt"
elastic "gopkg.in/olivere/elastic.v5"
"net/http"
"strconv"
"time"
elastic "gopkg.in/olivere/elastic.v5"
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/db"
"github.com/NyaaPantsu/nyaa/model"
@ -16,9 +17,9 @@ import (
"github.com/NyaaPantsu/nyaa/service/upload"
"github.com/NyaaPantsu/nyaa/service/user"
"github.com/NyaaPantsu/nyaa/service/user/permission"
"github.com/NyaaPantsu/nyaa/util/publicSettings"
"github.com/NyaaPantsu/nyaa/util/log"
msg "github.com/NyaaPantsu/nyaa/util/messages"
"github.com/NyaaPantsu/nyaa/util/publicSettings"
)
// UploadHandler : Main Controller for uploading a torrent
@ -80,6 +81,7 @@ func UploadPostHandler(w http.ResponseWriter, r *http.Request) {
Category: uploadForm.CategoryID,
SubCategory: uploadForm.SubCategoryID,
Status: status,
Hidden: uploadForm.Hidden,
Hash: uploadForm.Infohash,
Date: time.Now(),
Filesize: uploadForm.Filesize,

Voir le fichier

@ -17,9 +17,9 @@ import (
"github.com/NyaaPantsu/nyaa/service/user/permission"
"github.com/NyaaPantsu/nyaa/util"
"github.com/NyaaPantsu/nyaa/util/filelist"
"github.com/NyaaPantsu/nyaa/util/publicSettings"
"github.com/NyaaPantsu/nyaa/util/log"
msg "github.com/NyaaPantsu/nyaa/util/messages"
"github.com/NyaaPantsu/nyaa/util/publicSettings"
"github.com/gorilla/mux"
)
@ -170,6 +170,7 @@ func TorrentEditUserPanel(w http.ResponseWriter, r *http.Request) {
uploadForm.Remake = torrent.Status == model.TorrentStatusRemake
uploadForm.WebsiteLink = string(torrent.WebsiteLink)
uploadForm.Description = string(torrent.Description)
uploadForm.Hidden = torrent.Hidden
htv := formTemplateVariables{newCommonVariables(r), uploadForm, messages.GetAllErrors(), messages.GetAllInfos()}
err := userTorrentEd.ExecuteTemplate(w, "index.html", htv)
log.CheckError(err)
@ -204,6 +205,7 @@ func TorrentPostEditUserPanel(w http.ResponseWriter, r *http.Request) {
torrent.Category = uploadForm.CategoryID
torrent.SubCategory = uploadForm.SubCategoryID
torrent.Status = status
torrent.Hidden = uploadForm.Hidden
torrent.WebsiteLink = uploadForm.WebsiteLink
torrent.Description = uploadForm.Description
// torrent.Uploader = nil // GORM will create a new user otherwise (wtf?!)

Voir le fichier

@ -32,7 +32,12 @@
<option value="4" {{if eq .Status 4}}selected{{end}}>A+</option>
</select>
</div>
{{ if $.User }}
<p>
<input type="checkbox" name="hidden" id="hidden" {{ if .Hidden }}checked{{end}}>
<label for="hidden">{{call $.T "mark_as_hidden"}}</label>
</p>
{{ end }}
<div class="form-group">
<label for="website_link">{{call $.T "website_link"}}</label>
<input name="website_link" id="website_link" class="form-control" type="text" value="{{.WebsiteLink}}">

Voir le fichier

@ -29,7 +29,12 @@
<input type="checkbox" name="remake" id="remake" >
<label for="remake">{{call $.T "mark_as_remake"}}</label>
</p>
{{ if $.User }}
<p>
<input type="checkbox" name="hidden" id="hidden" >
<label for="hidden">{{call $.T "mark_as_hidden"}}</label>
</p>
{{ end }}
<h3>{{call $.T "website_link"}}</h3>
<input name="website_link" id="website_link" class="form-input up-input" type="text" value="{{.WebsiteLink}}">

Voir le fichier

@ -26,7 +26,12 @@
<input type="checkbox" name="remake" id="remake" {{ if .Remake }}checked{{end}}>
<label for="remake">{{call $.T "mark_as_remake"}}</label>
</div>
{{ if $.User }}
<p>
<input type="checkbox" name="hidden" id="hidden" {{ if .Hidden }}checked{{end}}>
<label for="hidden">{{call $.T "mark_as_hidden"}}</label>
</p>
{{ end }}
<div class="form-group">
<label for="website_link">{{call $.T "website_link"}}</label>
<input name="website_link" id="website_link" class="form-control" type="text" value="{{.WebsiteLink}}">