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

112 lignes
7 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-08 00:56:45 +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-08 00:56:45 +02:00
// Enable GZIP compression for all handlers except imgHandler and captcha
gzipCSSHandler := handlers.CompressHandler(cssHandler)
gzipJSHandler := handlers.CompressHandler(jsHandler)
gzipHomeHandler := handlers.CompressHandler(http.HandlerFunc(HomeHandler))
gzipSearchHandler := handlers.CompressHandler(http.HandlerFunc(SearchHandler))
gzipAPIHandler := handlers.CompressHandler(http.HandlerFunc(ApiHandler))
gzipAPIViewHandler := handlers.CompressHandler(http.HandlerFunc(ApiViewHandler))
2017-05-08 11:18:49 +02:00
gzipAPIUploadHandler := handlers.CompressHandler(http.HandlerFunc(ApiUploadHandler))
2017-05-09 20:54:50 +02:00
gzipAPIUpdateHandler := handlers.CompressHandler(http.HandlerFunc(ApiUpdateHandler))
2017-05-08 00:56:45 +02:00
gzipFaqHandler := handlers.CompressHandler(http.HandlerFunc(FaqHandler))
gzipRSSHandler := handlers.CompressHandler(http.HandlerFunc(RSSHandler))
2017-05-08 00:56:45 +02:00
gzipViewHandler := handlers.CompressHandler(http.HandlerFunc(ViewHandler))
gzipUploadHandler := handlers.CompressHandler(http.HandlerFunc(UploadHandler))
gzipUserRegisterFormHandler := handlers.CompressHandler(http.HandlerFunc(UserRegisterFormHandler))
gzipUserLoginFormHandler := handlers.CompressHandler(http.HandlerFunc(UserLoginFormHandler))
gzipUserVerifyEmailHandler := handlers.CompressHandler(http.HandlerFunc(UserVerifyEmailHandler))
gzipUserRegisterPostHandler := handlers.CompressHandler(http.HandlerFunc(UserRegisterPostHandler))
2017-05-08 13:29:17 +02:00
gzipUserLoginPostHandler := handlers.CompressHandler(http.HandlerFunc(UserLoginPostHandler))
gzipUserLogoutHandler := handlers.CompressHandler(http.HandlerFunc(UserLogoutHandler))
2017-05-08 13:37:56 +02:00
gzipUserProfileHandler := handlers.CompressHandler(http.HandlerFunc(UserProfileHandler))
2017-05-10 03:15:29 +02:00
gzipUserFollowHandler := handlers.CompressHandler(http.HandlerFunc(UserFollowHandler))
2017-05-09 17:47:06 +02:00
gzipUserProfileFormHandler := handlers.CompressHandler(http.HandlerFunc(UserProfileFormHandler))
2017-05-08 00:56:45 +02:00
gzipIndexModPanel := handlers.CompressHandler(http.HandlerFunc(IndexModPanel))
gzipTorrentsListPanel := handlers.CompressHandler(http.HandlerFunc(TorrentsListPanel))
gzipUsersListPanel := handlers.CompressHandler(http.HandlerFunc(UsersListPanel))
gzipCommentsListPanel := handlers.CompressHandler(http.HandlerFunc(CommentsListPanel))
gzipTorrentEditModPanel := handlers.CompressHandler(http.HandlerFunc(TorrentEditModPanel))
gzipTorrentPostEditModPanel := handlers.CompressHandler(http.HandlerFunc(TorrentPostEditModPanel))
gzipCommentDeleteModPanel := handlers.CompressHandler(http.HandlerFunc(CommentDeleteModPanel))
gzipTorrentDeleteModPanel := handlers.CompressHandler(http.HandlerFunc(TorrentDeleteModPanel))
2017-05-10 06:20:45 +02:00
gzipGetTorrentReportHandler := handlers.CompressHandler(http.HandlerFunc(GetTorrentReportHandler))
2017-05-10 09:57:55 +02:00
//gzipTorrentReportCreateHandler := handlers.CompressHandler(http.HandlerFunc(CreateTorrentReportHandler))
//gzipTorrentReportDeleteHandler := handlers.CompressHandler(http.HandlerFunc(DeleteTorrentReportHandler))
//gzipTorrentDeleteHandler := handlers.CompressHandler(http.HandlerFunc(DeleteTorrentHandler))
2017-05-08 00:56:45 +02:00
Router = mux.NewRouter()
// Routes
http.Handle("/css/", http.StripPrefix("/css/", wrapHandler(gzipCSSHandler)))
http.Handle("/js/", http.StripPrefix("/js/", wrapHandler(gzipJSHandler)))
http.Handle("/img/", http.StripPrefix("/img/", wrapHandler(imgHandler)))
2017-05-08 00:56:45 +02:00
Router.Handle("/", gzipHomeHandler).Name("home")
Router.Handle("/page/{page:[0-9]+}", wrapHandler(gzipHomeHandler)).Name("home_page")
2017-05-08 00:56:45 +02:00
Router.Handle("/search", gzipSearchHandler).Name("search")
Router.Handle("/search/{page}", gzipSearchHandler).Name("search_page")
2017-05-09 18:54:12 +02:00
Router.Handle("/api", gzipAPIHandler).Methods("GET")
Router.Handle("/api/{page:[0-9]*}", wrapHandler(gzipAPIHandler)).Methods("GET")
Router.Handle("/api/view/{id}", wrapHandler(gzipAPIViewHandler)).Methods("GET")
2017-05-09 18:54:12 +02:00
Router.Handle("/api/upload", gzipAPIUploadHandler).Methods("POST")
2017-05-09 20:54:50 +02:00
Router.Handle("/api/update", gzipAPIUpdateHandler).Methods("PUT")
2017-05-08 00:56:45 +02:00
Router.Handle("/faq", gzipFaqHandler).Name("faq")
Router.Handle("/feed", gzipRSSHandler).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-08 00:56:45 +02:00
Router.Handle("/upload", gzipUploadHandler).Name("upload")
Router.Handle("/user/register", gzipUserRegisterFormHandler).Name("user_register").Methods("GET")
Router.Handle("/user/login", gzipUserLoginFormHandler).Name("user_login").Methods("GET")
Router.Handle("/verify/email/{token}", gzipUserVerifyEmailHandler).Name("user_verify").Methods("GET")
Router.Handle("/user/register", gzipUserRegisterPostHandler).Name("user_register").Methods("POST")
2017-05-08 13:29:17 +02:00
Router.Handle("/user/login", gzipUserLoginPostHandler).Name("user_login").Methods("POST")
Router.Handle("/user/logout", gzipUserLogoutHandler).Name("user_logout")
Router.Handle("/user/{id}/{username}", wrapHandler(gzipUserProfileHandler)).Name("user_profile").Methods("GET")
2017-05-10 03:15:29 +02:00
Router.Handle("/user/{id}/{username}/follow", gzipUserFollowHandler).Name("user_follow").Methods("GET")
Router.Handle("/user/{id}/{username}", wrapHandler(gzipUserProfileFormHandler)).Name("user_profile").Methods("POST")
2017-05-10 14:09:12 +02:00
Router.Handle("/mod", gzipIndexModPanel).Name("mod_index")
Router.Handle("/mod/torrents", gzipTorrentsListPanel).Name("mod_tlist")
2017-05-10 15:08:38 +02:00
Router.Handle("/mod/torrents/{page}", gzipTorrentsListPanel).Name("mod_tlist_page")
Router.Handle("/mod/users", gzipUsersListPanel).Name("mod_ulist")
2017-05-10 15:08:38 +02:00
Router.Handle("/mod/users/{page}", gzipUsersListPanel).Name("mod_ulist")
Router.Handle("/mod/comments", gzipCommentsListPanel).Name("mod_clist")
2017-05-10 15:08:38 +02:00
Router.Handle("/mod/comments/{page}", gzipCommentsListPanel).Name("mod_clist_page")
Router.Handle("/mod/comment", gzipCommentsListPanel).Name("mod_cedit") // TODO
Router.Handle("/mod/torrent/", gzipTorrentEditModPanel).Name("mod_tedit")
Router.Handle("/mod/torrent/", gzipTorrentPostEditModPanel).Name("mod_ptedit")
2017-05-10 08:20:17 +02:00
Router.Handle("/mod/torrent/delete", gzipTorrentDeleteModPanel).Name("mod_tdelete")
Router.Handle("/mod/comment/delete", gzipCommentDeleteModPanel).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-10 09:57:55 +02:00
//Router.Handle("/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-10 09:57:55 +02:00
//Router.Handle("/moderation/report/delete", gzipTorrentReportDeleteHandler).Name("torrent_report_delete").Methods("POST")
//Router.Handle("/moderation/torrent/delete", gzipTorrentDeleteHandler).Name("torrent_delete").Methods("POST")
2017-05-10 14:09:12 +02:00
Router.Handle("/mod/reports", gzipGetTorrentReportHandler).Name("torrent_report").Methods("GET")
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
}