Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/controllers/torrent/edit.go
akuma06 2c8344faf9 Controllers are now separated
They are in different folders and all loaded in controllers/router.go.
This means that you only have to create a folder with a router.go file and import this folder in main router.go to add a handler.
2017-07-16 17:14:21 +02:00

59 lignes
2,1 Kio
Go

package torrentController
import (
"net/http"
"strconv"
"github.com/NyaaPantsu/nyaa/controllers/router"
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/models/torrents"
"github.com/NyaaPantsu/nyaa/templates"
msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/NyaaPantsu/nyaa/utils/upload"
"github.com/NyaaPantsu/nyaa/utils/validator/torrent"
"github.com/gin-gonic/gin"
)
// TorrentEditUserPanel : Controller for editing a user torrent by a user, after GET request
func TorrentEditUserPanel(c *gin.Context) {
id, _ := strconv.ParseInt(c.Query("id"), 10, 32)
torrent, _ := torrents.FindByID(uint(id))
currentUser := router.GetUser(c)
if currentUser.CurrentOrAdmin(torrent.UploaderID) {
uploadForm := torrentValidator.TorrentRequest{}
uploadForm.Name = torrent.Name
uploadForm.Category = strconv.Itoa(torrent.Category) + "_" + strconv.Itoa(torrent.SubCategory)
uploadForm.Remake = torrent.Status == models.TorrentStatusRemake
uploadForm.WebsiteLink = string(torrent.WebsiteLink)
uploadForm.Description = string(torrent.Description)
uploadForm.Hidden = torrent.Hidden
uploadForm.Languages = torrent.Languages
templates.Form(c, "site/torrents/edit.jet.html", uploadForm)
} else {
c.AbortWithStatus(http.StatusNotFound)
}
}
// TorrentPostEditUserPanel : Controller for editing a user torrent by a user, after post request
func TorrentPostEditUserPanel(c *gin.Context) {
var uploadForm torrentValidator.UpdateRequest
id, _ := strconv.ParseInt(c.Query("id"), 10, 32)
uploadForm.ID = uint(id)
messages := msg.GetMessages(c)
torrent, _ := torrents.FindByID(uint(id))
currentUser := router.GetUser(c)
if torrent.ID > 0 && currentUser.CurrentOrAdmin(torrent.UploaderID) {
errUp := upload.ExtractEditInfo(c, &uploadForm.Update)
if errUp != nil {
messages.AddErrorT("errors", "fail_torrent_update")
}
if !messages.HasErrors() {
upload.UpdateTorrent(&uploadForm, torrent, currentUser).Update(currentUser.HasAdmin())
messages.AddInfoT("infos", "torrent_updated")
}
templates.Form(c, "site/torrents/edit.jet.html", uploadForm.Update)
} else {
c.AbortWithStatus(http.StatusNotFound)
}
}