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.
58 lignes
2,1 Kio
Go
58 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)
|
|
}
|
|
}
|