Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Cette révision appartient à :
akuma06 2017-05-11 22:21:06 +02:00
Parent 4b810494f3
révision 61ba31b337

Voir le fichier

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