Parent
48a9f7ebc2
révision
30d82f77bc
3 fichiers modifiés avec 78 ajouts et 77 suppressions
|
@ -3,22 +3,23 @@
|
||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/ewhal/nyaa/service/comment"
|
"github.com/ewhal/nyaa/service/comment"
|
||||||
"github.com/ewhal/nyaa/service/user"
|
|
||||||
"github.com/ewhal/nyaa/service/user/permission"
|
|
||||||
form "github.com/ewhal/nyaa/service/user/form"
|
|
||||||
"github.com/ewhal/nyaa/service/torrent"
|
"github.com/ewhal/nyaa/service/torrent"
|
||||||
"github.com/ewhal/nyaa/service/torrent/form"
|
"github.com/ewhal/nyaa/service/torrent/form"
|
||||||
|
"github.com/ewhal/nyaa/service/user"
|
||||||
|
form "github.com/ewhal/nyaa/service/user/form"
|
||||||
|
"github.com/ewhal/nyaa/service/user/permission"
|
||||||
"github.com/ewhal/nyaa/util/languages"
|
"github.com/ewhal/nyaa/util/languages"
|
||||||
"github.com/ewhal/nyaa/util/modelHelper"
|
"github.com/ewhal/nyaa/util/modelHelper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var panelIndex, panelTorrentList, panelUserList, panelCommentList, panelTorrentEd *template.Template
|
var panelIndex, panelTorrentList, panelUserList, panelCommentList, panelTorrentEd *template.Template
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
panelTorrentList = template.Must(template.New("torrentlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/torrentlist.html")))
|
panelTorrentList = template.Must(template.New("torrentlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/torrentlist.html")))
|
||||||
panelUserList = template.Must(template.New("userlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/userlist.html")))
|
panelUserList = template.Must(template.New("userlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/userlist.html")))
|
||||||
|
@ -29,100 +30,100 @@ func init() {
|
||||||
|
|
||||||
func IndexModPanel(w http.ResponseWriter, r *http.Request) {
|
func IndexModPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
currentUser := GetUser(r)
|
currentUser := GetUser(r)
|
||||||
if (userPermission.HasAdmin(currentUser)) {
|
if userPermission.HasAdmin(currentUser) {
|
||||||
offset := 10
|
offset := 10
|
||||||
|
|
||||||
torrents, _, _ := torrentService.GetAllTorrents(0, offset)
|
torrents, _, _ := torrentService.GetAllTorrents(0, offset)
|
||||||
users := userService.RetrieveUsersForAdmin(0, offset)
|
users := userService.RetrieveUsersForAdmin(0, offset)
|
||||||
comments := commentService.GetAllComments(0, offset)
|
comments := commentService.GetAllComments(0, offset)
|
||||||
languages.SetTranslationFromRequest(panelIndex, r, "en-us")
|
languages.SetTranslationFromRequest(panelIndex, r, "en-us")
|
||||||
htv := PanelIndexVbs{torrents, users, comments}
|
htv := PanelIndexVbs{torrents, users, comments}
|
||||||
_ = panelIndex.ExecuteTemplate(w, "admin_index.html", htv)
|
_ = panelIndex.ExecuteTemplate(w, "admin_index.html", htv)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
func TorrentsListPanel(w http.ResponseWriter, r *http.Request) {
|
func TorrentsListPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
currentUser := GetUser(r)
|
currentUser := GetUser(r)
|
||||||
if (userPermission.HasAdmin(currentUser)) {
|
if userPermission.HasAdmin(currentUser) {
|
||||||
page,_ := strconv.Atoi(r.URL.Query().Get("p"))
|
page, _ := strconv.Atoi(r.URL.Query().Get("p"))
|
||||||
offset := 100
|
offset := 100
|
||||||
|
|
||||||
torrents, _, _ := torrentService.GetAllTorrents(page*offset, offset)
|
torrents, _, _ := torrentService.GetAllTorrents(page*offset, offset)
|
||||||
languages.SetTranslationFromRequest(panelTorrentList, r, "en-us")
|
languages.SetTranslationFromRequest(panelTorrentList, r, "en-us")
|
||||||
htv := PanelTorrentListVbs{torrents}
|
htv := PanelTorrentListVbs{torrents}
|
||||||
_= panelTorrentList.ExecuteTemplate(w, "admin_index.html", htv)
|
_ = panelTorrentList.ExecuteTemplate(w, "admin_index.html", htv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func UsersListPanel(w http.ResponseWriter, r *http.Request) {
|
func UsersListPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
currentUser := GetUser(r)
|
currentUser := GetUser(r)
|
||||||
if (userPermission.HasAdmin(currentUser)) {
|
if userPermission.HasAdmin(currentUser) {
|
||||||
page,_ := strconv.Atoi(r.URL.Query().Get("p"))
|
page, _ := strconv.Atoi(r.URL.Query().Get("p"))
|
||||||
offset := 100
|
offset := 100
|
||||||
|
|
||||||
users := userService.RetrieveUsersForAdmin(page*offset, offset)
|
users := userService.RetrieveUsersForAdmin(page*offset, offset)
|
||||||
languages.SetTranslationFromRequest(panelUserList, r, "en-us")
|
languages.SetTranslationFromRequest(panelUserList, r, "en-us")
|
||||||
htv := PanelUserListVbs{users}
|
htv := PanelUserListVbs{users}
|
||||||
_ = panelUserList.ExecuteTemplate(w, "admin_index.html", htv)
|
_ = panelUserList.ExecuteTemplate(w, "admin_index.html", htv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func CommentsListPanel(w http.ResponseWriter, r *http.Request) {
|
func CommentsListPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
currentUser := GetUser(r)
|
currentUser := GetUser(r)
|
||||||
if (userPermission.HasAdmin(currentUser)) {
|
if userPermission.HasAdmin(currentUser) {
|
||||||
page,_ := strconv.Atoi(r.URL.Query().Get("p"))
|
page, _ := strconv.Atoi(r.URL.Query().Get("p"))
|
||||||
offset := 100
|
offset := 100
|
||||||
|
|
||||||
comments := commentService.GetAllComments(page*offset, offset)
|
comments := commentService.GetAllComments(page*offset, offset)
|
||||||
languages.SetTranslationFromRequest(panelCommentList, r, "en-us")
|
languages.SetTranslationFromRequest(panelCommentList, r, "en-us")
|
||||||
htv := PanelCommentListVbs{comments}
|
htv := PanelCommentListVbs{comments}
|
||||||
_= panelCommentList.ExecuteTemplate(w, "admin_index.html", htv)
|
_ = panelCommentList.ExecuteTemplate(w, "admin_index.html", htv)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
func TorrentEditModPanel(w http.ResponseWriter, r *http.Request) {
|
func TorrentEditModPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
currentUser := GetUser(r)
|
currentUser := GetUser(r)
|
||||||
if (userPermission.HasAdmin(currentUser)) {
|
if userPermission.HasAdmin(currentUser) {
|
||||||
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}
|
htv := PanelTorrentEdVbs{torrent}
|
||||||
_= panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
|
_ = panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
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{}
|
b := torrentform.PanelPost{}
|
||||||
err := form.NewErrors()
|
err := form.NewErrors()
|
||||||
infos := form.NewInfos()
|
infos := form.NewInfos()
|
||||||
modelHelper.BindValueForm(&b, r)
|
modelHelper.BindValueForm(&b, r)
|
||||||
err = modelHelper.ValidateForm(&b, err)
|
err = modelHelper.ValidateForm(&b, err)
|
||||||
id := r.URL.Query().Get("id")
|
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)
|
modelHelper.AssignValue(&torrent, &b)
|
||||||
if (len(err) == 0) {
|
if len(err) == 0 {
|
||||||
_, errorT := torrentService.UpdateTorrent(torrent)
|
_, errorT := torrentService.UpdateTorrent(torrent)
|
||||||
if (errorT != nil) {
|
if errorT != nil {
|
||||||
err["errors"] = append(err["errors"], errorT.Error())
|
err["errors"] = append(err["errors"], errorT.Error())
|
||||||
}
|
}
|
||||||
if (len(err) == 0) {
|
if len(err) == 0 {
|
||||||
infos["infos"] = append(infos["infos"], "torrent_updated")
|
infos["infos"] = append(infos["infos"], "torrent_updated")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
languages.SetTranslationFromRequest(panelTorrentEd, r, "en-us")
|
||||||
|
htv := PanelTorrentEdVbs{torrent}
|
||||||
|
_ = panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
|
||||||
}
|
}
|
||||||
languages.SetTranslationFromRequest(panelTorrentEd, r, "en-us")
|
|
||||||
htv := PanelTorrentEdVbs{torrent}
|
|
||||||
_ = panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CommentDeleteModPanel(w http.ResponseWriter, r *http.Request) {
|
func CommentDeleteModPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
currentUser := GetUser(r)
|
currentUser := GetUser(r)
|
||||||
id := r.URL.Query().Get("id")
|
id := r.URL.Query().Get("id")
|
||||||
|
|
||||||
if (userPermission.HasAdmin(currentUser)) {
|
if userPermission.HasAdmin(currentUser) {
|
||||||
_= form.NewErrors()
|
_ = form.NewErrors()
|
||||||
_, _ = userService.DeleteComment(id)
|
_, _ = userService.DeleteComment(id)
|
||||||
url, _ := Router.Get("mod_comment_list").URL()
|
url, _ := Router.Get("mod_comment_list").URL()
|
||||||
http.Redirect(w, r, url.String()+"?deleted", http.StatusSeeOther)
|
http.Redirect(w, r, url.String()+"?deleted", http.StatusSeeOther)
|
||||||
|
@ -131,8 +132,8 @@ func CommentDeleteModPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
func TorrentDeleteModPanel(w http.ResponseWriter, r *http.Request) {
|
func TorrentDeleteModPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
currentUser := GetUser(r)
|
currentUser := GetUser(r)
|
||||||
id := r.URL.Query().Get("id")
|
id := r.URL.Query().Get("id")
|
||||||
if (userPermission.HasAdmin(currentUser)) {
|
if userPermission.HasAdmin(currentUser) {
|
||||||
_= form.NewErrors()
|
_ = form.NewErrors()
|
||||||
_, _ = torrentService.DeleteTorrent(id)
|
_, _ = torrentService.DeleteTorrent(id)
|
||||||
url, _ := Router.Get("mod_torrent_list").URL()
|
url, _ := Router.Get("mod_torrent_list").URL()
|
||||||
http.Redirect(w, r, url.String()+"?deleted", http.StatusSeeOther)
|
http.Redirect(w, r, url.String()+"?deleted", http.StatusSeeOther)
|
||||||
|
|
|
@ -114,13 +114,13 @@ type UploadTemplateVariables struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type PanelIndexVbs struct {
|
type PanelIndexVbs struct {
|
||||||
Torrents []model.Torrents
|
Torrents []model.Torrent
|
||||||
Users []model.User
|
Users []model.User
|
||||||
Comments []model.Comment
|
Comments []model.Comment
|
||||||
}
|
}
|
||||||
|
|
||||||
type PanelTorrentListVbs struct {
|
type PanelTorrentListVbs struct {
|
||||||
Torrents []model.Torrents
|
Torrents []model.Torrent
|
||||||
}
|
}
|
||||||
type PanelUserListVbs struct {
|
type PanelUserListVbs struct {
|
||||||
Users []model.User
|
Users []model.User
|
||||||
|
@ -129,7 +129,7 @@ type PanelCommentListVbs struct {
|
||||||
Comments []model.Comment
|
Comments []model.Comment
|
||||||
}
|
}
|
||||||
type PanelTorrentEdVbs struct {
|
type PanelTorrentEdVbs struct {
|
||||||
Torrent model.Torrents
|
Torrent model.Torrent
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -174,7 +174,7 @@ func CreateWhereParams(conditions string, params ...string) WhereParams {
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteTorrent(id string) (int, error) {
|
func DeleteTorrent(id string) (int, error) {
|
||||||
var torrent model.Torrents
|
var torrent model.Torrent
|
||||||
if db.ORM.First(&torrent, id).RecordNotFound() {
|
if db.ORM.First(&torrent, id).RecordNotFound() {
|
||||||
return http.StatusNotFound, errors.New("Torrent is not found.")
|
return http.StatusNotFound, errors.New("Torrent is not found.")
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ func DeleteTorrent(id string) (int, error) {
|
||||||
return http.StatusOK, nil
|
return http.StatusOK, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateTorrent(torrent model.Torrents) (int, error) {
|
func UpdateTorrent(torrent model.Torrent) (int, error) {
|
||||||
if db.ORM.Save(torrent).Error != nil {
|
if db.ORM.Save(torrent).Error != nil {
|
||||||
return http.StatusInternalServerError, errors.New("Torrent is not updated.")
|
return http.StatusInternalServerError, errors.New("Torrent is not updated.")
|
||||||
}
|
}
|
||||||
|
|
Référencer dans un nouveau ticket