Merge pull request #698 from NyaaPantsu/revert-692-revert-690-user-torrent-edit
Allow users to edit & delete their torrents
Cette révision appartient à :
révision
07623e85ed
18 fichiers modifiés avec 284 ajouts et 116 suppressions
|
@ -11,12 +11,15 @@ import (
|
|||
"github.com/NyaaPantsu/nyaa/service/torrent"
|
||||
"github.com/NyaaPantsu/nyaa/util"
|
||||
"github.com/NyaaPantsu/nyaa/util/log"
|
||||
msg "github.com/NyaaPantsu/nyaa/util/messages"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func HomeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
page := vars["page"]
|
||||
messages := msg.GetMessages(r)
|
||||
deleteVar := r.URL.Query()["deleted"]
|
||||
|
||||
// db params url
|
||||
var err error
|
||||
|
@ -28,7 +31,9 @@ func HomeHandler(w http.ResponseWriter, r *http.Request) {
|
|||
maxPerPage = 50 // default Value maxPerPage
|
||||
}
|
||||
}
|
||||
|
||||
if (deleteVar != nil) {
|
||||
messages.AddInfoTf("infos", "torrent_deleted", "")
|
||||
}
|
||||
pagenum := 1
|
||||
if page != "" {
|
||||
pagenum, err = strconv.Atoi(html.EscapeString(page))
|
||||
|
@ -68,6 +73,7 @@ func HomeHandler(w http.ResponseWriter, r *http.Request) {
|
|||
htv := HomeTemplateVariables{
|
||||
CommonTemplateVariables: common,
|
||||
ListTorrents: torrentsJson,
|
||||
Infos: messages.GetAllInfos(),
|
||||
}
|
||||
|
||||
err = homeTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||
|
|
|
@ -256,7 +256,7 @@ func TorrentPostEditModPanel(w http.ResponseWriter, r *http.Request) {
|
|||
if torrent.ID > 0 {
|
||||
errUp := uploadForm.ExtractEditInfo(r)
|
||||
if errUp != nil {
|
||||
messages.AddError("errors", "Failed to update torrent!")
|
||||
messages.AddErrorT("errors", "fail_torrent_update")
|
||||
}
|
||||
if !messages.HasErrors() {
|
||||
// update some (but not all!) values
|
||||
|
@ -268,7 +268,7 @@ func TorrentPostEditModPanel(w http.ResponseWriter, r *http.Request) {
|
|||
torrent.Description = uploadForm.Description
|
||||
torrent.Uploader = nil // GORM will create a new user otherwise (wtf?!)
|
||||
db.ORM.Save(&torrent)
|
||||
messages.AddInfo("infos", "Torrent details updated.")
|
||||
messages.AddInfoT("infos", "torrent_updated")
|
||||
}
|
||||
}
|
||||
htv := PanelTorrentEdVbs{NewPanelCommonVariables(r), uploadForm, messages.GetAllErrors(), messages.GetAllInfos()}
|
||||
|
@ -325,9 +325,9 @@ func TorrentPostReassignModPanel(w http.ResponseWriter, r *http.Request) {
|
|||
} else {
|
||||
count, err2 := rForm.ExecuteAction()
|
||||
if err2 != nil {
|
||||
messages.AddError("errors", "Something went wrong")
|
||||
messages.AddErrorT("errors", "something_went_wrong")
|
||||
} else {
|
||||
messages.AddInfof("infos", "%d torrents updated.", count)
|
||||
messages.AddInfoTf("infos", "nb_torrents_updated", count)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -356,13 +356,13 @@ func torrentManyAction(r *http.Request) {
|
|||
messages := msg.GetMessages(r) // new util for errors and infos
|
||||
|
||||
if action == "" {
|
||||
messages.AddError("errors", "You have to tell what you want to do with your selection!")
|
||||
messages.AddErrorT("errors", "no_action_selected")
|
||||
}
|
||||
if action == "move" && r.FormValue("moveto") == "" { // We need to check the form value, not the int one because hidden is 0
|
||||
messages.AddError("errors", "Thou has't to telleth whither thee wanteth to moveth thy selection!")
|
||||
messages.AddErrorT("errors", "no_move_location_selected")
|
||||
}
|
||||
if len(torrentsSelected) == 0 {
|
||||
messages.AddError("errors", "You need to select at least 1 element!")
|
||||
messages.AddErrorT("errors", "select_one_element")
|
||||
}
|
||||
if !messages.HasErrors() {
|
||||
for _, torrent_id := range torrentsSelected {
|
||||
|
@ -373,22 +373,22 @@ func torrentManyAction(r *http.Request) {
|
|||
if config.TorrentStatus[moveTo] {
|
||||
torrent.Status = moveTo
|
||||
db.ORM.Save(&torrent)
|
||||
messages.AddInfof("infos", "Torrent %s moved!", torrent.Name)
|
||||
messages.AddInfoTf("infos", "torrent_moved", torrent.Name)
|
||||
} else {
|
||||
messages.AddErrorf("errors", "No such status %d exist!", moveTo)
|
||||
messages.AddErrorTf("errors", "no_status_exist", moveTo)
|
||||
}
|
||||
case "delete":
|
||||
_, err := torrentService.DeleteTorrent(torrent_id)
|
||||
if err != nil {
|
||||
messages.ImportFromError("errors", err)
|
||||
} else {
|
||||
messages.AddInfof("infos", "Torrent %s deleted!", torrent.Name)
|
||||
messages.AddInfoTf("infos", "torrent_deleted", torrent.Name)
|
||||
}
|
||||
default:
|
||||
messages.AddErrorf("errors", "No such action %s exist!", action)
|
||||
messages.AddErrorTf("errors", "no_action_exist", action)
|
||||
}
|
||||
} else {
|
||||
messages.AddErrorf("errors", "Torrent with ID %s doesn't exist!", torrent_id)
|
||||
messages.AddErrorTf("errors", "torrent_not_exist", torrent_id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,9 @@ func init() {
|
|||
Router.Handle("/view/{id}", wrapHandler(gzipViewHandler)).Methods("GET").Name("view_torrent")
|
||||
Router.HandleFunc("/view/{id}", ViewHeadHandler).Methods("HEAD")
|
||||
Router.HandleFunc("/view/{id}", PostCommentHandler).Methods("POST").Name("post_comment")
|
||||
Router.HandleFunc("/torrent/", TorrentEditUserPanel).Methods("GET").Name("user_torrent_edit")
|
||||
Router.HandleFunc("/torrent/", TorrentPostEditUserPanel).Methods("POST").Name("user_torrent_edit")
|
||||
Router.HandleFunc("/torrent/delete", TorrentDeleteUserPanel).Methods("GET").Name("user_torrent_delete")
|
||||
Router.HandleFunc("/upload", UploadHandler).Name("upload")
|
||||
Router.HandleFunc("/user/register", UserRegisterFormHandler).Name("user_register").Methods("GET")
|
||||
Router.HandleFunc("/user/login", UserLoginFormHandler).Name("user_login").Methods("GET")
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"github.com/NyaaPantsu/nyaa/model"
|
||||
"github.com/NyaaPantsu/nyaa/util"
|
||||
"github.com/NyaaPantsu/nyaa/util/log"
|
||||
msg "github.com/NyaaPantsu/nyaa/util/messages"
|
||||
"github.com/NyaaPantsu/nyaa/util/search"
|
||||
"github.com/gorilla/mux"
|
||||
"html"
|
||||
|
@ -14,6 +15,7 @@ import (
|
|||
func SearchHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
page := vars["page"]
|
||||
messages := msg.GetMessages(r)
|
||||
|
||||
// db params url
|
||||
var err error
|
||||
|
@ -30,6 +32,7 @@ func SearchHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
searchParam, torrents, nbTorrents, err := search.SearchByQuery(r, pagenum)
|
||||
if err != nil {
|
||||
util.SendError(w, err, 400)
|
||||
|
@ -46,7 +49,7 @@ func SearchHandler(w http.ResponseWriter, r *http.Request) {
|
|||
Category: searchParam.Category.String(),
|
||||
ShowItemsPerPage: true,
|
||||
}
|
||||
htv := HomeTemplateVariables{common, b}
|
||||
htv := HomeTemplateVariables{common, b, messages.GetAllInfos()}
|
||||
|
||||
err = searchTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||
if err != nil {
|
||||
|
|
|
@ -23,6 +23,7 @@ var homeTemplate,
|
|||
viewProfileNotifTemplate,
|
||||
viewProfileEditTemplate,
|
||||
viewUserDeleteTemplate,
|
||||
userTorrentEd,
|
||||
notFoundTemplate,
|
||||
changeLanguageTemplate,
|
||||
databaseDumpTemplate *template.Template
|
||||
|
@ -115,6 +116,11 @@ func ReloadTemplates() {
|
|||
name: "user_delete",
|
||||
file: filepath.Join("user", "delete_success.html"),
|
||||
},
|
||||
templateLoader{
|
||||
templ: &userTorrentEd,
|
||||
name: "user_torrent_edit",
|
||||
file: filepath.Join("user", "torrent_edit.html"),
|
||||
},
|
||||
templateLoader{
|
||||
templ: ¬FoundTemplate,
|
||||
name: "404",
|
||||
|
|
|
@ -162,6 +162,9 @@ var FuncMap = template.FuncMap{
|
|||
// because time.* isn't available in templates...
|
||||
return t.Format(time.RFC3339)
|
||||
},
|
||||
"GetCategories": func(keepParent bool) map[string]string {
|
||||
return categories.GetCategoriesSelect(keepParent)
|
||||
},
|
||||
"CategoryName": func(category string, sub_category string) string {
|
||||
s := category + "_" + sub_category
|
||||
|
||||
|
|
|
@ -71,9 +71,17 @@ type UserProfileNotifVariables struct {
|
|||
Infos map[string][]string
|
||||
}
|
||||
|
||||
type UserTorrentEdVbs struct {
|
||||
CommonTemplateVariables
|
||||
Upload UploadForm
|
||||
FormErrors map[string][]string
|
||||
FormInfos map[string][]string
|
||||
}
|
||||
|
||||
type HomeTemplateVariables struct {
|
||||
CommonTemplateVariables
|
||||
ListTorrents []model.TorrentJSON
|
||||
Infos map[string][]string
|
||||
}
|
||||
|
||||
type DatabaseDumpTemplateVariables struct {
|
||||
|
|
|
@ -255,6 +255,10 @@ func (f *UploadForm) ExtractEditInfo(r *http.Request) error {
|
|||
return ErrInvalidTorrentCategory
|
||||
}
|
||||
|
||||
if !categories.CategoryExists(f.Category) {
|
||||
return ErrInvalidTorrentCategory
|
||||
}
|
||||
|
||||
f.CategoryID = CatID
|
||||
f.SubCategoryID = SubCatID
|
||||
} else {
|
||||
|
@ -289,4 +293,4 @@ func NewUploadForm(params ...string) (uploadForm UploadForm) {
|
|||
uploadForm.Description = "Description"
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
|
@ -9,8 +9,10 @@ import (
|
|||
|
||||
"github.com/NyaaPantsu/nyaa/db"
|
||||
"github.com/NyaaPantsu/nyaa/model"
|
||||
"github.com/NyaaPantsu/nyaa/service"
|
||||
"github.com/NyaaPantsu/nyaa/service/captcha"
|
||||
"github.com/NyaaPantsu/nyaa/service/notifier"
|
||||
"github.com/NyaaPantsu/nyaa/service/report"
|
||||
"github.com/NyaaPantsu/nyaa/service/torrent"
|
||||
"github.com/NyaaPantsu/nyaa/service/user/permission"
|
||||
"github.com/NyaaPantsu/nyaa/util/languages"
|
||||
|
@ -85,13 +87,13 @@ func PostCommentHandler(w http.ResponseWriter, r *http.Request) {
|
|||
if userPermission.NeedsCaptcha(currentUser) {
|
||||
userCaptcha := captcha.Extract(r)
|
||||
if !captcha.Authenticate(userCaptcha) {
|
||||
messages.AddError("errors", "Bad captcha!")
|
||||
messages.AddErrorT("errors", "bad_captcha")
|
||||
}
|
||||
}
|
||||
content := p.Sanitize(r.FormValue("comment"))
|
||||
|
||||
if strings.TrimSpace(content) == "" {
|
||||
messages.AddError("errors", "Comment empty!")
|
||||
messages.AddErrorT("errors", "comment_empty")
|
||||
}
|
||||
if !messages.HasErrors() {
|
||||
userID := currentUser.ID
|
||||
|
@ -121,7 +123,7 @@ func ReportTorrentHandler(w http.ResponseWriter, r *http.Request) {
|
|||
if userPermission.NeedsCaptcha(currentUser) {
|
||||
userCaptcha := captcha.Extract(r)
|
||||
if !captcha.Authenticate(userCaptcha) {
|
||||
messages.AddError("errors", "Bad captcha!")
|
||||
messages.AddErrorT("errors", "bad_captcha")
|
||||
}
|
||||
}
|
||||
if !messages.HasErrors() {
|
||||
|
@ -142,3 +144,82 @@ func ReportTorrentHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
ViewHandler(w, r)
|
||||
}
|
||||
|
||||
func TorrentEditUserPanel(w http.ResponseWriter, r *http.Request) {
|
||||
id := r.URL.Query().Get("id")
|
||||
torrent, _ := torrentService.GetTorrentById(id)
|
||||
messages:= msg.GetMessages(r)
|
||||
currentUser := GetUser(r)
|
||||
if userPermission.CurrentOrAdmin(currentUser, torrent.UploaderID) {
|
||||
uploadForm := NewUploadForm()
|
||||
uploadForm.Name = torrent.Name
|
||||
uploadForm.Category = strconv.Itoa(torrent.Category) + "_" + strconv.Itoa(torrent.SubCategory)
|
||||
uploadForm.Remake = torrent.Status == model.TorrentStatusRemake
|
||||
uploadForm.WebsiteLink = string(torrent.WebsiteLink)
|
||||
uploadForm.Description = string(torrent.Description)
|
||||
htv := UserTorrentEdVbs{NewCommonVariables(r), uploadForm, messages.GetAllErrors(), messages.GetAllInfos()}
|
||||
err := userTorrentEd.ExecuteTemplate(w, "index.html", htv)
|
||||
log.CheckError(err)
|
||||
} else {
|
||||
NotFoundHandler(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func TorrentPostEditUserPanel(w http.ResponseWriter, r *http.Request) {
|
||||
var uploadForm UploadForm
|
||||
id := r.URL.Query().Get("id")
|
||||
messages := msg.GetMessages(r)
|
||||
torrent, _ := torrentService.GetTorrentById(id)
|
||||
currentUser := GetUser(r)
|
||||
if torrent.ID > 0 && userPermission.CurrentOrAdmin(currentUser, torrent.UploaderID) {
|
||||
errUp := uploadForm.ExtractEditInfo(r)
|
||||
if errUp != nil {
|
||||
messages.AddErrorT("errors", "fail_torrent_update")
|
||||
}
|
||||
if !messages.HasErrors() {
|
||||
status := model.TorrentStatusNormal
|
||||
uploadForm.Remake = r.FormValue(UploadFormRemake) == "on"
|
||||
if uploadForm.Remake { // overrides trusted
|
||||
status = model.TorrentStatusRemake
|
||||
} else if currentUser.IsTrusted() {
|
||||
status = model.TorrentStatusTrusted
|
||||
}
|
||||
// update some (but not all!) values
|
||||
torrent.Name = uploadForm.Name
|
||||
torrent.Category = uploadForm.CategoryID
|
||||
torrent.SubCategory = uploadForm.SubCategoryID
|
||||
torrent.Status = status
|
||||
torrent.WebsiteLink = uploadForm.WebsiteLink
|
||||
torrent.Description = uploadForm.Description
|
||||
torrent.Uploader = nil // GORM will create a new user otherwise (wtf?!)
|
||||
db.ORM.Save(&torrent)
|
||||
messages.AddInfoT("infos", "torrent_updated")
|
||||
}
|
||||
htv := UserTorrentEdVbs{NewCommonVariables(r), uploadForm, messages.GetAllErrors(), messages.GetAllInfos()}
|
||||
err_ := userTorrentEd.ExecuteTemplate(w, "index.html", htv)
|
||||
log.CheckError(err_)
|
||||
} else {
|
||||
NotFoundHandler(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func TorrentDeleteUserPanel(w http.ResponseWriter, r *http.Request) {
|
||||
id := r.URL.Query().Get("id")
|
||||
currentUser := GetUser(r)
|
||||
torrent, _ := torrentService.GetTorrentById(id)
|
||||
if userPermission.CurrentOrAdmin(currentUser, torrent.UploaderID) {
|
||||
_, err := torrentService.DeleteTorrent(id)
|
||||
if (err == nil) {
|
||||
//delete reports of torrent
|
||||
whereParams := serviceBase.CreateWhereParams("torrent_id = ?", id)
|
||||
reports, _, _ := reportService.GetTorrentReportsOrderBy(&whereParams, "", 0, 0)
|
||||
for _, report := range reports {
|
||||
reportService.DeleteTorrentReport(report.ID)
|
||||
}
|
||||
}
|
||||
url, _ := Router.Get("home").URL()
|
||||
http.Redirect(w, r, url.String()+"?deleted", http.StatusSeeOther)
|
||||
} else {
|
||||
NotFoundHandler(w, r)
|
||||
}
|
||||
}
|
|
@ -1,41 +1,9 @@
|
|||
{{define "search_common"}}
|
||||
<select name="c" class="form-control input-sm" value>
|
||||
<option value="_">{{call $.T "all_categories"}}</option>
|
||||
{{ if Sukebei }}
|
||||
<option value="1_" {{if eq .Search.Category "1_"}}selected{{end}}>{{call $.T "art"}}</option>
|
||||
<option value="1_1" {{if eq .Search.Category "1_1"}}selected{{end}}>{{call $.T "art_anime"}}</option>
|
||||
<option value="1_2" {{if eq .Search.Category "1_2"}}selected{{end}}>{{call $.T "art_doujinshi"}}</option>
|
||||
<option value="1_3" {{if eq .Search.Category "1_3"}}selected{{end}}>{{call $.T "art_games"}}</option>
|
||||
<option value="1_4" {{if eq .Search.Category "1_4"}}selected{{end}}>{{call $.T "art_manga"}}</option>
|
||||
<option value="1_5" {{if eq .Search.Category "1_5"}}selected{{end}}>{{call $.T "art_pictures"}}</option>
|
||||
<option value="2_" {{if eq .Search.Category "2_"}}selected{{end}}>{{call $.T "real_life"}}</option>
|
||||
<option value="2_1" {{if eq .Search.Category "2_1"}}selected{{end}}>{{call $.T "real_life_photobooks_and_pictures"}}</option>
|
||||
<option value="2_2" {{if eq .Search.Category "2_2"}}selected{{end}}>{{call $.T "real_life_videos"}}</option>
|
||||
{{ else }}
|
||||
<option value="3_" {{if eq .Search.Category "3_"}}selected{{end}}>{{call $.T "anime"}}</option>
|
||||
<option value="3_12" {{if eq .Search.Category "3_12"}}selected{{end}}>{{call $.T "anime_amv"}}</option>
|
||||
<option value="3_5" {{if eq .Search.Category "3_5"}}selected{{end}}>{{call $.T "anime_english_translated"}}</option>
|
||||
<option value="3_13" {{if eq .Search.Category "3_13"}}selected{{end}}>{{call $.T "anime_non_english_translated"}}</option>
|
||||
<option value="3_6" {{if eq .Search.Category "3_6"}}selected{{end}}>{{call $.T "anime_raw"}}</option>
|
||||
<option value="2_" {{if eq .Search.Category "2_"}}selected{{end}}>{{call $.T "audio"}}</option>
|
||||
<option value="2_3" {{if eq .Search.Category "2_3"}}selected{{end}}>{{call $.T "audio_lossless"}}</option>
|
||||
<option value="2_4" {{if eq .Search.Category "2_4"}}selected{{end}}>{{call $.T "audio_lossy"}}</option>
|
||||
<option value="4_" {{if eq .Search.Category "4_"}}selected{{end}}>{{call $.T "literature"}}</option>
|
||||
<option value="4_7" {{if eq .Search.Category "4_7"}}selected{{end}}>{{call $.T "literature_english_translated"}}</option>
|
||||
<option value="4_8" {{if eq .Search.Category "4_8"}}selected{{end}}>{{call $.T "literature_raw"}}</option>
|
||||
<option value="4_14" {{if eq .Search.Category "4_14"}}selected{{end}}>{{call $.T "literature_non_english_translated"}}</option>
|
||||
<option value="5_" {{if eq .Search.Category "5_"}}selected{{end}}>{{call $.T "live_action"}}</option>
|
||||
<option value="5_9" {{if eq .Search.Category "5_9"}}selected{{end}}>{{call $.T "live_action_english_translated"}}</option>
|
||||
<option value="5_10" {{if eq .Search.Category "5_10"}}selected{{end}}>{{call $.T "live_action_idol_pv"}}</option>
|
||||
<option value="5_18" {{if eq .Search.Category "5_18"}}selected{{end}}>{{call $.T "live_action_non_english_translated"}}</option>
|
||||
<option value="5_11" {{if eq .Search.Category "5_11"}}selected{{end}}>{{call $.T "live_action_raw"}}</option>
|
||||
<option value="6_" {{if eq .Search.Category "6_"}}selected{{end}}>{{call $.T "pictures"}}</option>
|
||||
<option value="6_15" {{if eq .Search.Category "6_15"}}selected{{end}}>{{call $.T "pictures_graphics"}}</option>
|
||||
<option value="6_16" {{if eq .Search.Category "6_16"}}selected{{end}}>{{call $.T "pictures_photos"}}</option>
|
||||
<option value="1_" {{if eq .Search.Category "1_"}}selected{{end}}>{{call $.T "software"}}</option>
|
||||
<option value="1_1" {{if eq .Search.Category "1_1"}}selected{{end}}>{{call $.T "software_applications"}}</option>
|
||||
<option value="1_2" {{if eq .Search.Category "1_2"}}selected{{end}}>{{call $.T "software_games"}}</option>
|
||||
{{ end }}
|
||||
{{ range $name_cat, $id_cat := (GetCategories true) }}
|
||||
<option value="{{ $id_cat }}" {{if eq $.Search.Category $id_cat }}selected{{end}}>{{call $.T $name_cat }}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
<select name="s" class="form-control input-sm">
|
||||
<option value="0">{{call $.T "show_all"}}</option>
|
||||
|
|
|
@ -16,40 +16,8 @@
|
|||
<label for="c">{{call $.T "category"}}</label>
|
||||
<select name="c" class="form-control input-sm">
|
||||
<option value="">{{call $.T "select_a_torrent_category"}}</option>
|
||||
{{ if Sukebei }}
|
||||
<option value="1_" {{if eq .Category "1_"}}selected{{end}}>{{call $.T "art"}}</option>
|
||||
<option value="1_1" {{if eq .Category "1_1"}}selected{{end}}>{{call $.T "art_anime"}}</option>
|
||||
<option value="1_2" {{if eq .Category "1_2"}}selected{{end}}>{{call $.T "art_doujinshi"}}</option>
|
||||
<option value="1_3" {{if eq .Category "1_3"}}selected{{end}}>{{call $.T "art_games"}}</option>
|
||||
<option value="1_4" {{if eq .Category "1_4"}}selected{{end}}>{{call $.T "art_manga"}}</option>
|
||||
<option value="1_5" {{if eq .Category "1_5"}}selected{{end}}>{{call $.T "art_pictures"}}</option>
|
||||
<option value="2_" {{if eq .Category "2_"}}selected{{end}}>{{call $.T "real_life"}}</option>
|
||||
<option value="2_1" {{if eq .Category "2_1"}}selected{{end}}>{{call $.T "real_life_photobooks_and_Pictures"}}</option>
|
||||
<option value="2_2" {{if eq .Category "2_2"}}selected{{end}}>{{call $.T "real_life_videos"}}</option>
|
||||
{{ else }}
|
||||
<option value="3_" {{if eq .Category "3_"}}selected{{end}}>{{call $.T "anime"}}</option>
|
||||
<option value="3_12" {{if eq .Category "3_12"}}selected{{end}}>{{call $.T "anime_amv"}}</option>
|
||||
<option value="3_5" {{if eq .Category "3_5"}}selected{{end}}>{{call $.T "anime_english_translated"}}</option>
|
||||
<option value="3_13" {{if eq .Category "3_13"}}selected{{end}}>{{call $.T "anime_non_english_translated"}}</option>
|
||||
<option value="3_6" {{if eq .Category "3_6"}}selected{{end}}>{{call $.T "anime_raw"}}</option>
|
||||
<option value="2_" {{if eq .Category "2_"}}selected{{end}}>{{call $.T "audio"}}</option>
|
||||
<option value="2_3" {{if eq .Category "2_3"}}selected{{end}}>{{call $.T "audio_lossless"}}</option>
|
||||
<option value="2_4" {{if eq .Category "2_4"}}selected{{end}}>{{call $.T "audio_lossy"}}</option>
|
||||
<option value="4_" {{if eq .Category "4_"}}selected{{end}}>{{call $.T "literature"}}</option>
|
||||
<option value="4_7" {{if eq .Category "4_7"}}selected{{end}}>{{call $.T "literature_english_translated"}}</option>
|
||||
<option value="4_8" {{if eq .Category "4_8"}}selected{{end}}>{{call $.T "literature_raw"}}</option>
|
||||
<option value="4_14" {{if eq .Category "4_14"}}selected{{end}}>{{call $.T "literature_non_english_translated"}}</option>
|
||||
<option value="5_" {{if eq .Category "5_"}}selected{{end}}>{{call $.T "live_action"}}</option>
|
||||
<option value="5_9" {{if eq .Category "5_9"}}selected{{end}}>{{call $.T "live_action_english_translated"}}</option>
|
||||
<option value="5_10" {{if eq .Category "5_10"}}selected{{end}}>{{call $.T "live_action_idol_pv"}}</option>
|
||||
<option value="5_18" {{if eq .Category "5_18"}}selected{{end}}>{{call $.T "live_action_non_english_translated"}}</option>
|
||||
<option value="5_11" {{if eq .Category "5_11"}}selected{{end}}>{{call $.T "live_action_raw"}}</option>
|
||||
<option value="6_" {{if eq .Category "6_"}}selected{{end}}>{{call $.T "pictures"}}</option>
|
||||
<option value="6_15" {{if eq .Category "6_15"}}selected{{end}}>{{call $.T "pictures_graphics"}}</option>
|
||||
<option value="6_16" {{if eq .Category "6_16"}}selected{{end}}>{{call $.T "pictures_photos"}}</option>
|
||||
<option value="1_" {{if eq .Category "1_"}}selected{{end}}>{{call $.T "software"}}</option>
|
||||
<option value="1_1" {{if eq .Category "1_1"}}selected{{end}}>{{call $.T "software_applications"}}</option>
|
||||
<option value="1_2" {{if eq .Category "1_2"}}selected{{end}}>{{call $.T "software_games"}}</option>
|
||||
{{ range $name_cat, $id_cat := (GetCategories false) }}
|
||||
<option value="{{ $id_cat }}" {{if eq $.Upload.Category $id_cat }}selected{{end}}>{{call $.T $name_cat }}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
</div>
|
||||
|
|
|
@ -12,7 +12,9 @@ Your browser does not support the audio element.
|
|||
</audio>
|
||||
|
||||
<span id="mascot" class="visible-lg"></span>
|
||||
|
||||
{{ range (index $.Infos "infos")}}
|
||||
<div class="alert alert-info"><a class="panel-close close" data-dismiss="alert">×</a><i class="glyphicon glyphicon-info-sign"></i> {{ . }}</div>
|
||||
{{end}}
|
||||
<div class="blockBody">
|
||||
<nav>
|
||||
<ul class="list-inline text-center" aria-label="Page navigation">
|
||||
|
|
|
@ -23,34 +23,10 @@
|
|||
</div>
|
||||
<div class="form-group">
|
||||
<label for="c">{{call $.T "category"}}</label>
|
||||
<select name="c" id="c" class="form-control input-sm" required>
|
||||
<select name="c" class="form-control input-sm">
|
||||
<option value="">{{call $.T "select_a_torrent_category"}}</option>
|
||||
{{ if Sukebei }}
|
||||
<option value="1_1" {{if eq .Category "1_1"}}selected{{end}}>{{call $.T "art_anime"}}</option>
|
||||
<option value="1_2" {{if eq .Category "1_2"}}selected{{end}}>{{call $.T "art_doujinshi"}}</option>
|
||||
<option value="1_3" {{if eq .Category "1_3"}}selected{{end}}>{{call $.T "art_games"}}</option>
|
||||
<option value="1_4" {{if eq .Category "1_4"}}selected{{end}}>{{call $.T "art_manga"}}</option>
|
||||
<option value="1_5" {{if eq .Category "1_5"}}selected{{end}}>{{call $.T "art_pictures"}}</option>
|
||||
<option value="2_1" {{if eq .Category "2_1"}}selected{{end}}>{{call $.T "real_life_photobooks_and_Pictures"}}</option>
|
||||
<option value="2_2" {{if eq .Category "2_2"}}selected{{end}}>{{call $.T "real_life_videos"}}</option>
|
||||
{{ else }}
|
||||
<option value="3_12" {{if eq .Category "3_12"}}selected{{end}}>{{call $.T "anime_amv"}}</option>
|
||||
<option value="3_5" {{if eq .Category "3_5"}}selected{{end}}>{{call $.T "anime_english_translated"}}</option>
|
||||
<option value="3_13" {{if eq .Category "3_13"}}selected{{end}}>{{call $.T "anime_non_english_translated"}}</option>
|
||||
<option value="3_6" {{if eq .Category "3_6"}}selected{{end}}>{{call $.T "anime_raw"}}</option>
|
||||
<option value="2_3" {{if eq .Category "2_3"}}selected{{end}}>{{call $.T "audio_lossless"}}</option>
|
||||
<option value="2_4" {{if eq .Category "2_4"}}selected{{end}}>{{call $.T "audio_lossy"}}</option>
|
||||
<option value="4_7" {{if eq .Category "4_7"}}selected{{end}}>{{call $.T "literature_english_translated"}}</option>
|
||||
<option value="4_8" {{if eq .Category "4_8"}}selected{{end}}>{{call $.T "literature_raw"}}</option>
|
||||
<option value="4_14" {{if eq .Category "4_14"}}selected{{end}}>{{call $.T "literature_non_english_translated"}}</option>
|
||||
<option value="5_9" {{if eq .Category "5_9"}}selected{{end}}>{{call $.T "live_action_english_translated"}}</option>
|
||||
<option value="5_10" {{if eq .Category "5_10"}}selected{{end}}>{{call $.T "live_action_idol_pv"}}</option>
|
||||
<option value="5_18" {{if eq .Category "5_18"}}selected{{end}}>{{call $.T "live_action_non_english_translated"}}</option>
|
||||
<option value="5_11" {{if eq .Category "5_11"}}selected{{end}}>{{call $.T "live_action_raw"}}</option>
|
||||
<option value="6_15" {{if eq .Category "6_15"}}selected{{end}}>{{call $.T "pictures_graphics"}}</option>
|
||||
<option value="6_16" {{if eq .Category "6_16"}}selected{{end}}>{{call $.T "pictures_photos"}}</option>
|
||||
<option value="1_1" {{if eq .Category "1_1"}}selected{{end}}>{{call $.T "software_applications"}}</option>
|
||||
<option value="1_2" {{if eq .Category "1_2"}}selected{{end}}>{{call $.T "software_games"}}</option>
|
||||
{{ range $name_cat, $id_cat := (GetCategories false) }}
|
||||
<option value="{{ $id_cat }}" {{if eq $.Upload.Category $id_cat }}selected{{end}}>{{call $.T $name_cat }}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
<p class="help-block">{{ call $.T "please_include_our_tracker" }}</p>
|
||||
|
|
54
templates/user/torrent_edit.html
Fichier normal
54
templates/user/torrent_edit.html
Fichier normal
|
@ -0,0 +1,54 @@
|
|||
{{define "title"}}Torrent Edit{{end}}
|
||||
{{define "content"}}
|
||||
<div class="blockBody">
|
||||
{{with .Upload}}
|
||||
<form enctype="multipart/form-data" role="upload" method="POST">
|
||||
{{ range (index $.FormInfos "infos")}}
|
||||
<div class="alert alert-info"><a class="panel-close close" data-dismiss="alert">×</a><i class="glyphicon glyphicon-info-sign"></i> {{ . }}</div>
|
||||
{{end}}
|
||||
{{ range (index $.FormErrors "errors")}}
|
||||
<div class="alert alert-danger"><a class="panel-close close" data-dismiss="alert">×</a><i class="glyphicon glyphicon-exclamation-sign"></i> {{ . }}</div>
|
||||
{{end}}
|
||||
<div class="form-group">
|
||||
<label for="name">{{call $.T "name"}}</label>
|
||||
<input type="text" name="name" class="form-control" placeholder="{{call $.T "file_name"}}" value="{{.Name}}" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="c">{{call $.T "category"}}</label>
|
||||
<select name="c" class="form-control input-sm">
|
||||
<option value="">{{call $.T "select_a_torrent_category"}}</option>
|
||||
{{ range $name_cat, $id_cat := (GetCategories false) }}
|
||||
<option value="{{ $id_cat }}" {{if eq $.Upload.Category $id_cat }}selected{{end}}>{{call $.T $name_cat }}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="checkbox" name="remake" id="remake" {{ if .Remake }}checked{{end}}>
|
||||
<label for="remake">{{call $.T "mark_as_remake"}}</label>
|
||||
</div>
|
||||
|
||||
<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}}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="desc">{{call $.T "torrent_description"}}</label>
|
||||
<p class="help-block">{{call $.T "description_markdown_notice"}}</p>
|
||||
<textarea name="desc" class="form-control torrent-desc" rows="10">{{.Description}}</textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success">{{call $.T "save_changes"}}</button>
|
||||
<br>
|
||||
<br>
|
||||
</form>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
{{define "js_footer"}}
|
||||
<script type="text/javascript" charset="utf-8" src="{{.URL.Parse "/js/uploadPage.js"}}"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="https://cdnjs.cloudflare.com/ajax/libs/markdown.js/0.5.0/markdown.min.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="https://cdnjs.cloudflare.com/ajax/libs/to-markdown/3.0.4/to-markdown.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-markdown/2.10.0/js/bootstrap-markdown.js"></script>
|
||||
<script>
|
||||
$(".torrent-desc").markdown({resize: "both"})
|
||||
</script>
|
||||
{{end}}
|
|
@ -53,6 +53,9 @@
|
|||
{{ if HasAdmin $.User}}
|
||||
<a href="{{ genRoute "mod_tdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('{{ call $.T "are_you_sure" }}')) return false;"><i class="glyphicon glyphicon-trash"></i></a>
|
||||
<a href="{{ genRoute "mod_tedit" }}?id={{ .ID }}" class="btn btn-warning btn-lg"><i class="glyphicon glyphicon-pencil"></i></a>
|
||||
{{ else if CurrentUserIdentical $.User .UploaderID }}
|
||||
<a href="{{ genRoute "user_torrent_delete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('{{ call $.T "are_you_sure" }}')) return false;"><i class="glyphicon glyphicon-trash"></i></a>
|
||||
<a href="{{ genRoute "user_torrent_edit" }}?id={{ .ID }}" class="btn btn-warning btn-lg"><i class="glyphicon glyphicon-pencil"></i></a>
|
||||
{{end}}
|
||||
</div>
|
||||
<div style="clear: both;"></div>
|
||||
|
|
|
@ -838,5 +838,61 @@
|
|||
{
|
||||
"id": "new_comment_on_torrent",
|
||||
"translation": "New comment on torrent: \"%s\""
|
||||
},
|
||||
{
|
||||
"id": "no_action_selected",
|
||||
"translation": "You have to tell what you want to do with your selection!"
|
||||
},
|
||||
{
|
||||
"id": "no_move_location_selected",
|
||||
"translation": "Thou has't to telleth whither thee wanteth to moveth thy selection!"
|
||||
},
|
||||
{
|
||||
"id": "select_one_element",
|
||||
"translation": "You need to select at least 1 element!"
|
||||
},
|
||||
{
|
||||
"id": "torrent_moved",
|
||||
"translation": "Torrent %s moved!"
|
||||
},
|
||||
{
|
||||
"id": "no_status_exist",
|
||||
"translation": "No such status %d exist!"
|
||||
},
|
||||
{
|
||||
"id": "torrent_deleted",
|
||||
"translation": "Torrent %s deleted!"
|
||||
},
|
||||
{
|
||||
"id": "no_action_exist",
|
||||
"translation": "No such action %s exist!"
|
||||
},
|
||||
{
|
||||
"id": "torrent_not_exist",
|
||||
"translation": "Torrent with ID %s doesn't exist!"
|
||||
},
|
||||
{
|
||||
"id": "something_went_wrong",
|
||||
"translation": "Something went wrong"
|
||||
},
|
||||
{
|
||||
"id": "nb_torrents_updated",
|
||||
"translation": "%d torrents updated."
|
||||
},
|
||||
{
|
||||
"id": "torrent_updated",
|
||||
"translation": "Torrent details updated."
|
||||
},
|
||||
{
|
||||
"id": "fail_torrent_update",
|
||||
"translation": "Failed to update torrent!"
|
||||
},
|
||||
{
|
||||
"id": "bad_captcha",
|
||||
"translation": "Bad captcha!"
|
||||
},
|
||||
{
|
||||
"id": "comment_empty",
|
||||
"translation": "Comment empty!"
|
||||
}
|
||||
]
|
||||
|
|
|
@ -58,3 +58,14 @@ func CategoryExists(category string) bool {
|
|||
_, exists := GetCategories()[category]
|
||||
return exists
|
||||
}
|
||||
|
||||
func GetCategoriesSelect(keepParent bool) map[string]string {
|
||||
categories := GetCategories()
|
||||
catSelect := make(map[string]string, len(categories))
|
||||
for k, v := range categories {
|
||||
if len(k) > 2 || keepParent {
|
||||
catSelect[v] = k
|
||||
}
|
||||
}
|
||||
return catSelect
|
||||
}
|
|
@ -3,6 +3,8 @@ import (
|
|||
"github.com/gorilla/context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/nicksnyder/go-i18n/i18n"
|
||||
"github.com/NyaaPantsu/nyaa/util/languages"
|
||||
)
|
||||
|
||||
const MessagesKey = "messages"
|
||||
|
@ -11,6 +13,7 @@ type Messages struct {
|
|||
Errors map[string][]string
|
||||
Infos map[string][]string
|
||||
r *http.Request
|
||||
T i18n.TranslateFunc
|
||||
}
|
||||
|
||||
func GetMessages(r *http.Request) *Messages {
|
||||
|
@ -18,7 +21,8 @@ func GetMessages(r *http.Request) *Messages {
|
|||
return rv.(*Messages)
|
||||
} else {
|
||||
context.Set(r, MessagesKey, &Messages{})
|
||||
return &Messages{make(map[string][]string),make(map[string][]string), r}
|
||||
T, _ := languages.GetTfuncAndLanguageFromRequest(r)
|
||||
return &Messages{make(map[string][]string),make(map[string][]string), r, T}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,6 +36,12 @@ func (mes *Messages) AddError(name string, msg string) {
|
|||
func (mes *Messages) AddErrorf( name string, msg string, args ...interface{}) {
|
||||
mes.AddError(name, fmt.Sprintf(msg, args...))
|
||||
}
|
||||
func (mes *Messages) AddErrorTf( name string, id string, args ...interface{}) {
|
||||
mes.AddErrorf(name, mes.T(id), args...)
|
||||
}
|
||||
func (mes *Messages) AddErrorT( name string, id string) {
|
||||
mes.AddError(name, mes.T(id))
|
||||
}
|
||||
func (mes *Messages) ImportFromError(name string, err error) {
|
||||
mes.AddError(name, err.Error())
|
||||
}
|
||||
|
@ -46,6 +56,12 @@ func (mes *Messages) AddInfo(name string, msg string) {
|
|||
func (mes *Messages) AddInfof(name string, msg string, args ...interface{}) {
|
||||
mes.AddInfo(name, fmt.Sprintf(msg, args...))
|
||||
}
|
||||
func (mes *Messages) AddInfoTf(name string, id string, args ...interface{}) {
|
||||
mes.AddInfof(name, mes.T(id), args...)
|
||||
}
|
||||
func (mes *Messages) AddInfoT(name string, id string) {
|
||||
mes.AddInfo(name, mes.T(id))
|
||||
}
|
||||
|
||||
func (mes *Messages) ClearErrors() {
|
||||
mes.Infos = nil
|
||||
|
|
Référencer dans un nouveau ticket