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

121 lignes
8 Kio
Go
Brut Vue normale Historique

package router
import (
"net/http"
2017-05-07 10:25:09 +02:00
2017-05-17 07:58:40 +02:00
"github.com/NyaaPantsu/nyaa/service/captcha"
2017-05-18 03:09:23 +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 05:06:12 +02:00
// TODO Use config from cli
// TODO Make sure the directory exists
2017-05-24 09:11:13 +02:00
dumpsHandler := http.FileServer(http.Dir(DatabaseDumpPath))
2017-05-11 05:06:12 +02:00
// TODO Use config from cli
// TODO Make sure the directory exists
gpgKeyHandler := http.FileServer(http.Dir(GPGPublicKeyPath))
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)
2017-05-25 04:18:31 +02:00
gzipUserApiKeyResetHandler := http.HandlerFunc(UserApiKeyResetHandler)
2017-05-11 22:21:06 +02:00
gzipUserDetailsHandler := http.HandlerFunc(UserDetailsHandler)
gzipUserProfileFormHandler := http.HandlerFunc(UserProfileFormHandler)
2017-05-21 00:02:57 +02:00
gzipUserNotificationsHandler := http.HandlerFunc(UserNotificationsHandler)
2017-05-11 05:06:12 +02:00
gzipDumpsHandler := handlers.CompressHandler(dumpsHandler)
gzipGpgKeyHandler := handlers.CompressHandler(gpgKeyHandler)
gzipDatabaseDumpHandler := handlers.CompressHandler(http.HandlerFunc(DatabaseDumpHandler))
2017-05-08 00:56:45 +02:00
Router = mux.NewRouter()
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))
2017-05-11 05:06:12 +02:00
http.Handle("/dbdumps/", http.StripPrefix("/dbdumps/", wrapHandler(gzipDumpsHandler)))
http.Handle("/gpg/", http.StripPrefix("/gpg/", wrapHandler(gzipGpgKeyHandler)))
Router.Handle("/", 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")
Router.HandleFunc("/api/view/{id}", ApiViewHeadHandler).Methods("HEAD")
2017-05-11 22:21:06 +02:00
Router.HandleFunc("/api/upload", ApiUploadHandler).Methods("POST")
2017-05-25 02:42:35 +02:00
Router.HandleFunc("/api/search", ApiSearchHandler)
Router.HandleFunc("/api/search/{page}", ApiSearchHandler)
2017-05-11 22:21:06 +02:00
Router.HandleFunc("/api/update", ApiUpdateHandler).Methods("PUT")
Router.HandleFunc("/faq", FaqHandler).Name("faq")
Router.HandleFunc("/feed", RSSHandler).Name("feed")
Router.HandleFunc("/feed/{page}", RSSHandler).Name("feed_page")
Router.Handle("/view/{id}", wrapHandler(gzipViewHandler)).Methods("GET").Name("view_torrent")
Router.HandleFunc("/view/{id}", ViewHeadHandler).Methods("HEAD")
Router.HandleFunc("/view/{id}", PostCommentHandler).Methods("POST").Name("post_comment")
2017-05-23 04:05:33 +02:00
Router.HandleFunc("/torrent/", TorrentEditUserPanel).Methods("GET").Name("user_torrent_edit")
Router.HandleFunc("/torrent/", TorrentPostEditUserPanel).Methods("POST").Name("user_torrent_edit")
Router.HandleFunc("/torrent/delete", TorrentDeleteUserPanel).Methods("GET").Name("user_torrent_delete")
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-25 04:18:31 +02:00
Router.Handle("/user/{id}/{username}/edit/apireset", wrapHandler(gzipUserApiKeyResetHandler)).Name("user_profile_edit").Methods("POST")
2017-05-21 00:02:57 +02:00
Router.Handle("/user/notifications", wrapHandler(gzipUserNotificationsHandler)).Name("user_notifications")
Router.HandleFunc("/user/{id}/{username}/feed", RSSHandler).Name("feed_user")
Router.HandleFunc("/user/{id}/{username}/feed/{page}", RSSHandler).Name("feed_user_page")
// INFO Everything under /mod should be wrapped by WrapModHandler. This make
// sure the page is only accessible by moderators
// TODO Find a native mux way to add a 'prehook' for route /mod
2017-05-24 09:11:13 +02:00
Router.HandleFunc("/mod", WrapModHandler(IndexModPanel)).Name("mod_index")
Router.HandleFunc("/mod/torrents", WrapModHandler(TorrentsListPanel)).Name("mod_tlist").Methods("GET")
Deleted torrents mod done (#732) * Torrent Mass Edit Api (WIP) * Torrents can be deleted in mass from frontend with api post request * Torrents status can be edited from frontend with api post request -- Look to function doc for more info on how to use it It is a WIP so it might not work =D * Finished Mass mod Api As per suggestion of @yiiTT in #720, I added: * Changing torrents category * Deletion of reports with deletion of a torrent * Changing owner of multiple torrents Commit also add some new translation strings. * Make some changes * Reports can now be cleared for the torrents selected without having to delete them * Users with no admin rights can't delete reports * Fix moveto to status moveto deprecated in api * Tested and works! Changes: * Updates only the colomns of torrent table * Moved categories config in config/torrents.go * Forgot this file in last commit * Less useless queries The use of Save makes it that users are created and updates also all the associatiated models. Better to just update the colomns needed (less useless queries) * Some Updates * Added a new status of 5 for locking torrents * Modifying the list torrents view for using it in deleted torrents view * Added function to get deleted torrents * Torrents (and reports) can be definitely deleted * Some new translation string * Fixing * fix 2 * Added upload check for locked torrents If a user owns a torrent, has deleted it and try to repload it. As long as it has not been locked, he can. * Fixing wrong condition in isdeleted * Finished * Info messages on success when deletes or lock * Fixed double deleted_at is Null * Added Link to view of deleted torrents * Added new translation string
2017-05-25 02:19:05 +02:00
Router.HandleFunc("/mod/torrents/{page:[0-9]+}", WrapModHandler(TorrentsListPanel)).Name("mod_tlist_page").Methods("GET")
Router.HandleFunc("/mod/torrents", WrapModHandler(TorrentsPostListPanel)).Methods("POST")
Deleted torrents mod done (#732) * Torrent Mass Edit Api (WIP) * Torrents can be deleted in mass from frontend with api post request * Torrents status can be edited from frontend with api post request -- Look to function doc for more info on how to use it It is a WIP so it might not work =D * Finished Mass mod Api As per suggestion of @yiiTT in #720, I added: * Changing torrents category * Deletion of reports with deletion of a torrent * Changing owner of multiple torrents Commit also add some new translation strings. * Make some changes * Reports can now be cleared for the torrents selected without having to delete them * Users with no admin rights can't delete reports * Fix moveto to status moveto deprecated in api * Tested and works! Changes: * Updates only the colomns of torrent table * Moved categories config in config/torrents.go * Forgot this file in last commit * Less useless queries The use of Save makes it that users are created and updates also all the associatiated models. Better to just update the colomns needed (less useless queries) * Some Updates * Added a new status of 5 for locking torrents * Modifying the list torrents view for using it in deleted torrents view * Added function to get deleted torrents * Torrents (and reports) can be definitely deleted * Some new translation string * Fixing * fix 2 * Added upload check for locked torrents If a user owns a torrent, has deleted it and try to repload it. As long as it has not been locked, he can. * Fixing wrong condition in isdeleted * Finished * Info messages on success when deletes or lock * Fixed double deleted_at is Null * Added Link to view of deleted torrents * Added new translation string
2017-05-25 02:19:05 +02:00
Router.HandleFunc("/mod/torrents/{page:[0-9]+}", WrapModHandler(TorrentsPostListPanel)).Methods("POST")
Router.HandleFunc("/mod/torrents/deleted", WrapModHandler(DeletedTorrentsModPanel)).Name("mod_tlist_deleted").Methods("GET")
Router.HandleFunc("/mod/torrents/deleted/{page:[0-9]+}", WrapModHandler(DeletedTorrentsModPanel)).Name("mod_tlist_deleted_page").Methods("GET")
Router.HandleFunc("/mod/torrents/deleted", WrapModHandler(DeletedTorrentsPostPanel)).Name("mod_tlist_deleted").Methods("POST")
Router.HandleFunc("/mod/torrents/deleted/{page:[0-9]+}", WrapModHandler(DeletedTorrentsPostPanel)).Name("mod_tlist_deleted_page").Methods("POST")
2017-05-24 09:11:13 +02:00
Router.HandleFunc("/mod/reports", WrapModHandler(TorrentReportListPanel)).Name("mod_trlist")
Router.HandleFunc("/mod/reports/{page}", WrapModHandler(TorrentReportListPanel)).Name("mod_trlist_page")
Router.HandleFunc("/mod/users", WrapModHandler(UsersListPanel)).Name("mod_ulist")
Router.HandleFunc("/mod/users/{page}", WrapModHandler(UsersListPanel)).Name("mod_ulist_page")
Router.HandleFunc("/mod/comments", WrapModHandler(CommentsListPanel)).Name("mod_clist")
Router.HandleFunc("/mod/comments/{page}", WrapModHandler(CommentsListPanel)).Name("mod_clist_page")
2017-05-24 09:11:13 +02:00
Router.HandleFunc("/mod/comment", WrapModHandler(CommentsListPanel)).Name("mod_cedit") // TODO
Router.HandleFunc("/mod/torrent/", WrapModHandler(TorrentEditModPanel)).Name("mod_tedit").Methods("GET")
Router.HandleFunc("/mod/torrent/", WrapModHandler(TorrentPostEditModPanel)).Name("mod_ptedit").Methods("POST")
Router.HandleFunc("/mod/torrent/delete", WrapModHandler(TorrentDeleteModPanel)).Name("mod_tdelete")
Deleted torrents mod done (#732) * Torrent Mass Edit Api (WIP) * Torrents can be deleted in mass from frontend with api post request * Torrents status can be edited from frontend with api post request -- Look to function doc for more info on how to use it It is a WIP so it might not work =D * Finished Mass mod Api As per suggestion of @yiiTT in #720, I added: * Changing torrents category * Deletion of reports with deletion of a torrent * Changing owner of multiple torrents Commit also add some new translation strings. * Make some changes * Reports can now be cleared for the torrents selected without having to delete them * Users with no admin rights can't delete reports * Fix moveto to status moveto deprecated in api * Tested and works! Changes: * Updates only the colomns of torrent table * Moved categories config in config/torrents.go * Forgot this file in last commit * Less useless queries The use of Save makes it that users are created and updates also all the associatiated models. Better to just update the colomns needed (less useless queries) * Some Updates * Added a new status of 5 for locking torrents * Modifying the list torrents view for using it in deleted torrents view * Added function to get deleted torrents * Torrents (and reports) can be definitely deleted * Some new translation string * Fixing * fix 2 * Added upload check for locked torrents If a user owns a torrent, has deleted it and try to repload it. As long as it has not been locked, he can. * Fixing wrong condition in isdeleted * Finished * Info messages on success when deletes or lock * Fixed double deleted_at is Null * Added Link to view of deleted torrents * Added new translation string
2017-05-25 02:19:05 +02:00
Router.HandleFunc("/mod/torrent/block", WrapModHandler(TorrentBlockModPanel)).Name("mod_tblock")
2017-05-24 09:11:13 +02:00
Router.HandleFunc("/mod/report/delete", WrapModHandler(TorrentReportDeleteModPanel)).Name("mod_trdelete")
Router.HandleFunc("/mod/comment/delete", WrapModHandler(CommentDeleteModPanel)).Name("mod_cdelete")
Router.HandleFunc("/mod/reassign", WrapModHandler(TorrentReassignModPanel)).Name("mod_treassign").Methods("GET")
Router.HandleFunc("/mod/reassign", WrapModHandler(TorrentPostReassignModPanel)).Name("mod_treassign").Methods("POST")
2017-05-25 02:42:35 +02:00
Router.HandleFunc("/mod/api/torrents", WrapModHandler(ApiMassMod)).Name("mod_tapi").Methods("POST")
2017-05-10 10:17:21 +02:00
//reporting a torrent
Router.HandleFunc("/report/{id}", ReportTorrentHandler).Methods("POST").Name("torrent_report")
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 05:06:12 +02:00
Router.Handle("/dumps", gzipDatabaseDumpHandler).Name("dump").Methods("GET")
2017-05-13 00:17:34 +02:00
Router.HandleFunc("/language", SeeLanguagesHandler).Methods("GET").Name("see_languages")
Router.HandleFunc("/language", ChangeLanguageHandler).Methods("POST").Name("change_language")
2017-05-07 09:05:31 +02:00
Router.NotFoundHandler = http.HandlerFunc(NotFoundHandler)
2017-05-06 00:37:59 +02:00
}