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/router/router.go

117 lignes
6,6 Kio
Go
Brut Vue normale Historique

package router
import (
"net/http"
2017-05-07 10:25:09 +02:00
"github.com/ewhal/nyaa/service/captcha"
2017-05-11 22:21:06 +02:00
// "github.com/gorilla/handlers"
2017-05-07 10:25:09 +02:00
"github.com/gorilla/mux"
)
var Router *mux.Router
2017-05-06 00:37:59 +02:00
func init() {
2017-05-08 00:56:45 +02:00
// Static file handlers
2017-05-07 00:26:02 +02:00
cssHandler := http.FileServer(http.Dir("./public/css/"))
jsHandler := http.FileServer(http.Dir("./public/js/"))
imgHandler := http.FileServer(http.Dir("./public/img/"))
2017-05-11 22:21:06 +02:00
gzipHomeHandler := http.HandlerFunc(HomeHandler)
gzipAPIHandler := http.HandlerFunc(ApiHandler)
gzipAPIViewHandler := http.HandlerFunc(ApiViewHandler)
gzipViewHandler := http.HandlerFunc(ViewHandler)
gzipUserProfileHandler := http.HandlerFunc(UserProfileHandler)
gzipUserDetailsHandler := http.HandlerFunc(UserDetailsHandler)
gzipUserProfileFormHandler := http.HandlerFunc(UserProfileFormHandler)
/*
2017-05-08 00:56:45 +02:00
// Enable GZIP compression for all handlers except imgHandler and captcha
2017-05-11 22:21:06 +02:00
gzipCSSHandler := cssHandler)
gzipJSHandler:= jsHandler)
gzipSearchHandler:= http.HandlerFunc(SearchHandler)
gzipAPIUploadHandler := http.HandlerFunc(ApiUploadHandler)
gzipAPIUpdateHandler := http.HandlerFunc(ApiUpdateHandler)
gzipFaqHandler := http.HandlerFunc(FaqHandler)
gzipRSSHandler := http.HandlerFunc(RSSHandler)
gzipUploadHandler := http.HandlerFunc(UploadHandler)
gzipUserRegisterFormHandler := http.HandlerFunc(UserRegisterFormHandler)
gzipUserLoginFormHandler := http.HandlerFunc(UserLoginFormHandler)
gzipUserVerifyEmailHandler := http.HandlerFunc(UserVerifyEmailHandler)
gzipUserRegisterPostHandler := http.HandlerFunc(UserRegisterPostHandler)
gzipUserLoginPostHandler := http.HandlerFunc(UserLoginPostHandler)
gzipUserLogoutHandler := http.HandlerFunc(UserLogoutHandler)
gzipUserFollowHandler := http.HandlerFunc(UserFollowHandler)
2017-05-08 00:56:45 +02:00
2017-05-11 22:21:06 +02:00
gzipIndexModPanel := http.HandlerFunc(IndexModPanel)
gzipTorrentsListPanel := http.HandlerFunc(TorrentsListPanel)
gzipTorrentReportListPanel := http.HandlerFunc(TorrentReportListPanel)
gzipUsersListPanel := http.HandlerFunc(UsersListPanel)
gzipCommentsListPanel := http.HandlerFunc(CommentsListPanel)
gzipTorrentEditModPanel := http.HandlerFunc(TorrentEditModPanel)
gzipTorrentPostEditModPanel := http.HandlerFunc(TorrentPostEditModPanel)
gzipCommentDeleteModPanel := http.HandlerFunc(CommentDeleteModPanel)
gzipTorrentDeleteModPanel := http.HandlerFunc(TorrentDeleteModPanel)
gzipTorrentReportDeleteModPanel := http.HandlerFunc(TorrentReportDeleteModPanel)*/
2017-05-11 22:21:06 +02:00
//gzipTorrentReportCreateHandler := http.HandlerFunc(CreateTorrentReportHandler)
//gzipTorrentReportDeleteHandler := http.HandlerFunc(DeleteTorrentReportHandler)
//gzipTorrentDeleteHandler := http.HandlerFunc(DeleteTorrentHandler)
2017-05-08 00:56:45 +02:00
Router = mux.NewRouter()
// Routes
2017-05-11 22:21:06 +02:00
http.Handle("/css/", http.StripPrefix("/css/", cssHandler))
http.Handle("/js/", http.StripPrefix("/js/", jsHandler))
http.Handle("/img/", http.StripPrefix("/img/", imgHandler))
Router.Handle("/", wrapHandler(gzipHomeHandler)).Name("home")
Router.Handle("/page/{page:[0-9]+}", wrapHandler(gzipHomeHandler)).Name("home_page")
2017-05-11 22:21:06 +02:00
Router.HandleFunc("/search", SearchHandler).Name("search")
Router.HandleFunc("/search/{page}", SearchHandler).Name("search_page")
Router.Handle("/api", wrapHandler(gzipAPIHandler)).Methods("GET")
Router.Handle("/api/{page:[0-9]*}", wrapHandler(gzipAPIHandler)).Methods("GET")
Router.Handle("/api/view/{id}", wrapHandler(gzipAPIViewHandler)).Methods("GET")
2017-05-11 22:21:06 +02:00
Router.HandleFunc("/api/upload", ApiUploadHandler).Methods("POST")
Router.HandleFunc("/api/update", ApiUpdateHandler).Methods("PUT")
Router.HandleFunc("/faq", FaqHandler).Name("faq")
Router.HandleFunc("/feed", RSSHandler).Name("feed")
Router.Handle("/view/{id}", wrapHandler(gzipViewHandler)).Methods("GET").Name("view_torrent")
Router.HandleFunc("/view/{id}", PostCommentHandler).Methods("POST").Name("post_comment")
2017-05-11 22:21:06 +02:00
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")
Router.HandleFunc("/verify/email/{token}", UserVerifyEmailHandler).Name("user_verify").Methods("GET")
Router.HandleFunc("/user/register", UserRegisterPostHandler).Name("user_register").Methods("POST")
Router.HandleFunc("/user/login", UserLoginPostHandler).Name("user_login").Methods("POST")
Router.HandleFunc("/user/logout", UserLogoutHandler).Name("user_logout")
Router.Handle("/user/{id}/{username}", wrapHandler(gzipUserProfileHandler)).Name("user_profile").Methods("GET")
2017-05-11 22:21:06 +02:00
Router.HandleFunc("/user/{id}/{username}/follow", UserFollowHandler).Name("user_follow").Methods("GET")
Router.Handle("/user/{id}/{username}/edit", wrapHandler(gzipUserDetailsHandler)).Name("user_profile_details").Methods("GET")
Router.Handle("/user/{id}/{username}/edit", wrapHandler(gzipUserProfileFormHandler)).Name("user_profile_edit").Methods("POST")
2017-05-11 22:21:06 +02:00
Router.HandleFunc("/mod", IndexModPanel).Name("mod_index")
Router.HandleFunc("/mod/torrents", TorrentsListPanel).Name("mod_tlist")
Router.HandleFunc("/mod/torrents/{page}", TorrentsListPanel).Name("mod_tlist_page")
Router.HandleFunc("/mod/reports", TorrentReportListPanel).Name("mod_trlist")
Router.HandleFunc("/mod/reports/{page}", TorrentReportListPanel).Name("mod_trlist_page")
Router.HandleFunc("/mod/users", UsersListPanel).Name("mod_ulist")
Router.HandleFunc("/mod/users/{page}", UsersListPanel).Name("mod_ulist_page")
Router.HandleFunc("/mod/comments", CommentsListPanel).Name("mod_clist")
Router.HandleFunc("/mod/comments/{page}", CommentsListPanel).Name("mod_clist_page")
Router.HandleFunc("/mod/comment", CommentsListPanel).Name("mod_cedit") // TODO
Router.HandleFunc("/mod/torrent/", TorrentEditModPanel).Name("mod_tedit").Methods("GET")
Router.HandleFunc("/mod/torrent/", TorrentPostEditModPanel).Name("mod_ptedit").Methods("POST")
Router.HandleFunc("/mod/torrent/delete", TorrentDeleteModPanel).Name("mod_tdelete")
Router.HandleFunc("/mod/report/delete", TorrentReportDeleteModPanel).Name("mod_trdelete")
Router.HandleFunc("/mod/comment/delete", CommentDeleteModPanel).Name("mod_cdelete")
2017-05-10 10:17:21 +02:00
//reporting a torrent
Router.HandleFunc("/report/{id}", ReportTorrentHandler).Methods("POST").Name("post_comment")
2017-05-07 10:25:09 +02:00
Router.PathPrefix("/captcha").Methods("GET").HandlerFunc(captcha.ServeFiles)
2017-05-07 08:59:45 +02:00
2017-05-11 22:21:06 +02:00
//Router.HandleFunc("/report/create", gzipTorrentReportCreateHandler).Name("torrent_report_create").Methods("POST")
2017-05-10 06:20:45 +02:00
// TODO Allow only moderators to access /moderation/*
2017-05-11 22:21:06 +02:00
//Router.HandleFunc("/moderation/report/delete", gzipTorrentReportDeleteHandler).Name("torrent_report_delete").Methods("POST")
//Router.HandleFunc("/moderation/torrent/delete", gzipTorrentDeleteHandler).Name("torrent_delete").Methods("POST")
2017-05-10 06:20:45 +02:00
2017-05-07 09:05:31 +02:00
Router.NotFoundHandler = http.HandlerFunc(NotFoundHandler)
2017-05-06 00:37:59 +02:00
}