Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Added edit torrent view mod panel & fix

Cette révision appartient à :
akuma06 2017-05-10 23:53:25 +02:00
Parent ceb9e039f1
révision f94dc3103c
5 fichiers modifiés avec 112 ajouts et 26 suppressions

Voir le fichier

@ -9,19 +9,20 @@ import (
"net/http" "net/http"
"path/filepath" "path/filepath"
"strconv" "strconv"
"time"
"github.com/ewhal/nyaa/config"
"github.com/ewhal/nyaa/db"
"github.com/ewhal/nyaa/model" "github.com/ewhal/nyaa/model"
"github.com/ewhal/nyaa/service" "github.com/ewhal/nyaa/service"
"github.com/ewhal/nyaa/service/comment" "github.com/ewhal/nyaa/service/comment"
"github.com/ewhal/nyaa/service/report" "github.com/ewhal/nyaa/service/report"
"github.com/ewhal/nyaa/service/torrent" "github.com/ewhal/nyaa/service/torrent"
"github.com/ewhal/nyaa/service/torrent/form"
"github.com/ewhal/nyaa/service/user" "github.com/ewhal/nyaa/service/user"
form "github.com/ewhal/nyaa/service/user/form" form "github.com/ewhal/nyaa/service/user/form"
"github.com/ewhal/nyaa/service/user/permission" "github.com/ewhal/nyaa/service/user/permission"
"github.com/ewhal/nyaa/util/languages" "github.com/ewhal/nyaa/util/languages"
"github.com/ewhal/nyaa/util/log" "github.com/ewhal/nyaa/util/log"
"github.com/ewhal/nyaa/util/modelHelper"
"github.com/ewhal/nyaa/util/search" "github.com/ewhal/nyaa/util/search"
"github.com/gorilla/mux" "github.com/gorilla/mux"
) )
@ -191,9 +192,18 @@ func TorrentEditModPanel(w http.ResponseWriter, r *http.Request) {
id := r.URL.Query().Get("id") id := r.URL.Query().Get("id")
torrent, _ := torrentService.GetTorrentById(id) torrent, _ := torrentService.GetTorrentById(id)
languages.SetTranslationFromRequest(panelTorrentEd, r, "en-us") languages.SetTranslationFromRequest(panelTorrentEd, r, "en-us")
htv := PanelTorrentEdVbs{torrent, NewSearchForm(), currentUser}
torrentJson := torrent.ToJSON()
uploadForm := NewUploadForm()
uploadForm.Name = torrentJson.Name
uploadForm.Category = torrentJson.Category + "_" + torrentJson.SubCategory
uploadForm.Magnet = string(torrentJson.Magnet)
uploadForm.Status = torrentJson.Status
uploadForm.Description = string(torrentJson.Description)
htv := PanelTorrentEdVbs{uploadForm, NewSearchForm(), currentUser, form.NewErrors(), form.NewInfos()}
err := panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv) err := panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
log.CheckError(err) log.CheckError(err)
} else { } else {
http.Error(w, "admins only", http.StatusForbidden) http.Error(w, "admins only", http.StatusForbidden)
} }
@ -202,31 +212,42 @@ func TorrentEditModPanel(w http.ResponseWriter, r *http.Request) {
func TorrentPostEditModPanel(w http.ResponseWriter, r *http.Request) { func TorrentPostEditModPanel(w http.ResponseWriter, r *http.Request) {
currentUser := GetUser(r) currentUser := GetUser(r)
if userPermission.HasAdmin(currentUser) { if userPermission.HasAdmin(currentUser) {
b := torrentform.PanelPost{} if config.UploadsDisabled {
http.Error(w, "Error uploads are disabled", http.StatusInternalServerError)
return
}
var uploadForm UploadForm
id := r.URL.Query().Get("id")
err := form.NewErrors() err := form.NewErrors()
infos := form.NewInfos() infos := form.NewInfos()
modelHelper.BindValueForm(&b, r)
err = modelHelper.ValidateForm(&b, err)
id := r.URL.Query().Get("id")
torrent, _ := torrentService.GetTorrentById(id) torrent, _ := torrentService.GetTorrentById(id)
if torrent.ID > 0 { if (torrent.ID > 0) {
modelHelper.AssignValue(&torrent, &b) // validation is done in ExtractInfo()
if len(err) == 0 { errUp := uploadForm.ExtractInfo(r)
_, errorT := torrentService.UpdateTorrent(torrent) if errUp != nil {
if errorT != nil { err["errors"] = append(err["errors"], "Failed to upload!")
err["errors"] = append(err["errors"], errorT.Error())
}
if len(err) == 0 {
infos["infos"] = append(infos["infos"], "torrent_updated")
} }
if (len(err) > 0) {
//add to db and redirect depending on result
torrent.Name= uploadForm.Name
torrent.Category= uploadForm.CategoryID
torrent.SubCategory=uploadForm.SubCategoryID
torrent.Status= uploadForm.Status
torrent.Hash= uploadForm.Infohash
torrent.Date= time.Now()
torrent.Filesize= uploadForm.Filesize
torrent.Description= uploadForm.Description
db.ORM.Save(&torrent)
infos["infos"] = append(infos["infos"], "Torrent details updated!")
} }
} }
languages.SetTranslationFromRequest(panelTorrentEd, r, "en-us") languages.SetTranslationFromRequest(panelTorrentEd, r, "en-us")
htv := PanelTorrentEdVbs{torrent, NewSearchForm(), currentUser} htv := PanelTorrentEdVbs{uploadForm, NewSearchForm(), currentUser, err, infos}
_ = panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv) _ = panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
} else { } else {
http.Error(w, "admins only", http.StatusForbidden) http.Error(w, "admins only", http.StatusForbidden)
} }
} }
func CommentDeleteModPanel(w http.ResponseWriter, r *http.Request) { func CommentDeleteModPanel(w http.ResponseWriter, r *http.Request) {

Voir le fichier

@ -148,9 +148,11 @@ type PanelCommentListVbs struct {
URL *url.URL // For parsing Url in templates URL *url.URL // For parsing Url in templates
} }
type PanelTorrentEdVbs struct { type PanelTorrentEdVbs struct {
Torrent model.Torrent Upload UploadForm
Search SearchForm Search SearchForm
User *model.User User *model.User
FormInfos map[string][]string
FormErrors map[string][]string
} }
type PanelTorrentReportListVbs struct { type PanelTorrentReportListVbs struct {

Voir le fichier

@ -30,6 +30,7 @@ type UploadForm struct {
Category string Category string
Remake bool Remake bool
Description string Description string
Status int
captcha.Captcha captcha.Captcha
Infohash string Infohash string
@ -48,6 +49,7 @@ const UploadFormMagnet = "magnet"
const UploadFormCategory = "c" const UploadFormCategory = "c"
const UploadFormRemake = "remake" const UploadFormRemake = "remake"
const UploadFormDescription = "desc" const UploadFormDescription = "desc"
const UploadFormStatus = "status"
// error indicating that you can't send both a magnet link and torrent // 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") var ErrTorrentPlusMagnet = errors.New("upload either a torrent file or magnet link, not both")
@ -77,6 +79,7 @@ func (f *UploadForm) ExtractInfo(r *http.Request) error {
f.Name = r.FormValue(UploadFormName) f.Name = r.FormValue(UploadFormName)
f.Category = r.FormValue(UploadFormCategory) f.Category = r.FormValue(UploadFormCategory)
f.Description = r.FormValue(UploadFormDescription) f.Description = r.FormValue(UploadFormDescription)
f.Status, _ = strconv.Atoi(r.FormValue(UploadFormStatus))
f.Magnet = r.FormValue(UploadFormMagnet) f.Magnet = r.FormValue(UploadFormMagnet)
f.Remake = r.FormValue(UploadFormRemake) == "on" f.Remake = r.FormValue(UploadFormRemake) == "on"
f.Captcha = captcha.Extract(r) f.Captcha = captcha.Extract(r)

Voir le fichier

@ -1,5 +1,65 @@
{{define "content"}} {{define "content"}}
{{with .Upload}}
<h2>temporary not available</h2> <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">{{T "name"}}</label>
<input type="text" name="name" class="form-control" placeholder="File Name" value="{{.Name}}" required>
</div>
<div class="form-group">
<label for="torrent">{{T "torrent_file"}}</label>
<input type="file" name="torrent" id="torrent" accept=".torrent">
<p class="help-block">{{T "uploading_file_prefills_fields"}}</p>
</div>
<div class="form-group">
<label for="magnet">{{T "magnet_link"}}</label>
<input type="text" name="magnet" class="form-control"
style="width:60rem" placeholder="{{T "magnet_link"}}" value="{{.Magnet}}">
</div>
<div class="form-group">
<label for="c">{{T "category"}}</label>
<select name="c" class="form-control input-sm">
<option value="3_12" {{if eq .Category "3_12"}}selected{{end}}>{{T "anime_amv"}}</option>
<option value="3_5" {{if eq .Category "3_5"}}selected{{end}}>{{T "anime_english_translated"}}</option>
<option value="3_13" {{if eq .Category "3_13"}}selected{{end}}>{{T "anime_non_english_translated"}}</option>
<option value="3_6" {{if eq .Category "3_6"}}selected{{end}}>{{T "anime_raw"}}</option>
<option value="2_3" {{if eq .Category "2_3"}}selected{{end}}>{{T "audio_lossless"}}</option>
<option value="2_4" {{if eq .Category "2_4"}}selected{{end}}>{{T "audio_lossy"}}</option>
<option value="4_7" {{if eq .Category "4_7"}}selected{{end}}>{{T "literature_english_translated"}}</option>
<option value="4_8" {{if eq .Category "4_8"}}selected{{end}}>{{T "literature_raw"}}</option>
<option value="4_14" {{if eq .Category "4_14"}}selected{{end}}>{{T "literature_non_english_translated"}}</option>
<option value="5_9" {{if eq .Category "5_9"}}selected{{end}}>{{T "live_action_english_translated"}}</option>
<option value="5_10" {{if eq .Category "5_10"}}selected{{end}}>{{T "live_action_idol_pv"}}</option>
<option value="5_18" {{if eq .Category "5_18"}}selected{{end}}>{{T "live_action_non_english_translated"}}</option>
<option value="5_11" {{if eq .Category "5_11"}}selected{{end}}>{{T "live_action_raw"}}</option>
<option value="6_15" {{if eq .Category "6_15"}}selected{{end}}>{{T "pictures_graphics"}}</option>
<option value="6_16" {{if eq .Category "6_16"}}selected{{end}}>{{T "pictures_photos"}}</option>
<option value="1_1" {{if eq .Category "1_1"}}selected{{end}}>{{T "software_applications"}}</option>
<option value="1_2" {{if eq .Category "1_2"}}selected{{end}}>{{T "software_games"}}</option>
</select>
</div>
<div class="form-group">
<label for="Status">{{T "torrent_status"}}</label>
<select name="Status" class="form-control input-sm">
<option value="0" {{if eq .Status 0}}selected{{end}}>{{T "mark_as_hidden"}}</option>
<option value="1" {{if eq .Status 1}}selected{{end}}>{{T "mark_as_normal"}}</option>
<option value="2" {{if eq .Status 2}}selected{{end}}>{{T "mark_as_remake"}}</option>
<option value="3" {{if eq .Status 3}}selected{{end}}>{{T "mark_as_trusted"}}</option>
<option value="4" {{if eq .Status 4}}selected{{end}}>{{T "mark_as_aplus"}}</option>
</select>
</div>
<div class="form-group">
<label for="desc">{{T "torrent_description"}}</label>
<p class="help-block">{{T "description_markdown_notice"}}</p>
<textarea name="desc" class="form-control" rows="10">{{.Description}}</textarea>
</div>
<button type="submit" class="btn btn-success">{{T "save_changes"}}</button>
</form>
{{end}}
{{end}} {{end}}

Voir le fichier

@ -5,7 +5,7 @@
<tr> <tr>
<td><a href="{{ genRoute "user_profile" "id" (print .ID) "username" .Username }}?edit">{{ .Username }}</a></td> <td><a href="{{ genRoute "user_profile" "id" (print .ID) "username" .Username }}?edit">{{ .Username }}</a></td>
<td>{{if .ID > 0}}<a href="{{ genRoute "user_profile" "id" (print .ID) "username" .Username }}?delete" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>{{ T "delete" }}</a>{{end}}</td> <td>{{if gt .ID 0}}<a href="{{ genRoute "user_profile" "id" (print .ID) "username" .Username }}?delete" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>{{ T "delete" }}</a>{{end}}</td>
</tr> </tr>
{{end}} {{end}}
</table> </table>