2022-08-10 05:10:47 +00:00
|
|
|
// Package router configures web routes.
|
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2022-08-26 04:21:46 +00:00
|
|
|
"code.nonshy.com/nonshy/website/pkg/config"
|
|
|
|
"code.nonshy.com/nonshy/website/pkg/controller/account"
|
|
|
|
"code.nonshy.com/nonshy/website/pkg/controller/admin"
|
|
|
|
"code.nonshy.com/nonshy/website/pkg/controller/api"
|
|
|
|
"code.nonshy.com/nonshy/website/pkg/controller/block"
|
2023-02-06 04:26:36 +00:00
|
|
|
"code.nonshy.com/nonshy/website/pkg/controller/chat"
|
2022-08-27 02:50:33 +00:00
|
|
|
"code.nonshy.com/nonshy/website/pkg/controller/comment"
|
2022-08-26 04:21:46 +00:00
|
|
|
"code.nonshy.com/nonshy/website/pkg/controller/forum"
|
|
|
|
"code.nonshy.com/nonshy/website/pkg/controller/friend"
|
|
|
|
"code.nonshy.com/nonshy/website/pkg/controller/inbox"
|
|
|
|
"code.nonshy.com/nonshy/website/pkg/controller/index"
|
|
|
|
"code.nonshy.com/nonshy/website/pkg/controller/photo"
|
2022-12-21 03:15:45 +00:00
|
|
|
"code.nonshy.com/nonshy/website/pkg/controller/poll"
|
2022-08-26 04:21:46 +00:00
|
|
|
"code.nonshy.com/nonshy/website/pkg/middleware"
|
2022-08-10 05:10:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func New() http.Handler {
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
|
|
|
|
// Register controller endpoints.
|
|
|
|
mux.HandleFunc("/", index.Create())
|
2022-08-22 00:56:14 +00:00
|
|
|
mux.HandleFunc("/favicon.ico", index.Favicon())
|
2023-02-06 04:26:36 +00:00
|
|
|
mux.HandleFunc("/about", index.StaticTemplate("about.html")())
|
|
|
|
mux.HandleFunc("/faq", index.StaticTemplate("faq.html")())
|
|
|
|
mux.HandleFunc("/tos", index.StaticTemplate("tos.html")())
|
|
|
|
mux.HandleFunc("/privacy", index.StaticTemplate("privacy.html")())
|
2022-08-21 21:05:08 +00:00
|
|
|
mux.HandleFunc("/contact", index.Contact())
|
2022-08-10 05:10:47 +00:00
|
|
|
mux.HandleFunc("/login", account.Login())
|
|
|
|
mux.HandleFunc("/logout", account.Logout())
|
|
|
|
mux.HandleFunc("/signup", account.Signup())
|
2022-08-14 21:40:57 +00:00
|
|
|
mux.HandleFunc("/forgot-password", account.ForgotPassword())
|
|
|
|
mux.HandleFunc("/settings/confirm-email", account.ConfirmEmailChange())
|
2023-02-06 04:26:36 +00:00
|
|
|
mux.HandleFunc("/markdown", index.StaticTemplate("markdown.html")())
|
2022-08-10 05:10:47 +00:00
|
|
|
|
2022-08-13 22:39:31 +00:00
|
|
|
// Login Required. Pages that non-certified users can access.
|
2022-08-10 05:10:47 +00:00
|
|
|
mux.Handle("/me", middleware.LoginRequired(account.Dashboard()))
|
2022-08-11 03:59:59 +00:00
|
|
|
mux.Handle("/settings", middleware.LoginRequired(account.Settings()))
|
2022-08-14 21:40:57 +00:00
|
|
|
mux.Handle("/account/delete", middleware.LoginRequired(account.Delete()))
|
2022-08-27 04:32:26 +00:00
|
|
|
mux.Handle("/u/", account.Profile()) // public access OK
|
2022-08-12 06:03:06 +00:00
|
|
|
mux.Handle("/photo/upload", middleware.LoginRequired(photo.Upload()))
|
2022-08-13 06:11:36 +00:00
|
|
|
mux.Handle("/photo/u/", middleware.LoginRequired(photo.UserPhotos()))
|
2022-08-27 02:50:33 +00:00
|
|
|
mux.Handle("/photo/view", middleware.LoginRequired(photo.View()))
|
2022-08-13 06:11:36 +00:00
|
|
|
mux.Handle("/photo/edit", middleware.LoginRequired(photo.Edit()))
|
|
|
|
mux.Handle("/photo/delete", middleware.LoginRequired(photo.Delete()))
|
2022-08-13 22:39:31 +00:00
|
|
|
mux.Handle("/photo/certification", middleware.LoginRequired(photo.Certification()))
|
2022-09-08 04:18:54 +00:00
|
|
|
mux.Handle("/photo/private", middleware.LoginRequired(photo.Private()))
|
|
|
|
mux.Handle("/photo/private/share", middleware.LoginRequired(photo.Share()))
|
2022-08-14 00:42:42 +00:00
|
|
|
mux.Handle("/messages", middleware.LoginRequired(inbox.Inbox()))
|
|
|
|
mux.Handle("/messages/read/", middleware.LoginRequired(inbox.Inbox()))
|
|
|
|
mux.Handle("/messages/compose", middleware.LoginRequired(inbox.Compose()))
|
2022-12-21 05:11:43 +00:00
|
|
|
mux.Handle("/messages/delete", middleware.LoginRequired(inbox.Delete()))
|
2022-08-14 05:44:57 +00:00
|
|
|
mux.Handle("/friends", middleware.LoginRequired(friend.Friends()))
|
|
|
|
mux.Handle("/friends/add", middleware.LoginRequired(friend.AddFriend()))
|
2022-08-15 00:45:55 +00:00
|
|
|
mux.Handle("/users/block", middleware.LoginRequired(block.BlockUser()))
|
|
|
|
mux.Handle("/users/blocked", middleware.LoginRequired(block.Blocked()))
|
2022-08-27 02:50:33 +00:00
|
|
|
mux.Handle("/comments", middleware.LoginRequired(comment.PostComment()))
|
2022-08-27 18:42:48 +00:00
|
|
|
mux.Handle("/comments/subscription", middleware.LoginRequired(comment.Subscription()))
|
2022-08-14 23:27:57 +00:00
|
|
|
mux.Handle("/admin/unimpersonate", middleware.LoginRequired(admin.Unimpersonate()))
|
2022-08-13 22:39:31 +00:00
|
|
|
|
|
|
|
// Certification Required. Pages that only full (verified) members can access.
|
|
|
|
mux.Handle("/photo/gallery", middleware.CertRequired(photo.SiteGallery()))
|
2022-08-14 05:44:57 +00:00
|
|
|
mux.Handle("/members", middleware.CertRequired(account.Search()))
|
2023-02-06 04:26:36 +00:00
|
|
|
mux.Handle("/chat", middleware.CertRequired(chat.Landing()))
|
2022-08-24 05:55:19 +00:00
|
|
|
mux.Handle("/forum", middleware.CertRequired(forum.Landing()))
|
|
|
|
mux.Handle("/forum/post", middleware.CertRequired(forum.NewPost()))
|
|
|
|
mux.Handle("/forum/thread/", middleware.CertRequired(forum.Thread()))
|
2022-08-31 05:13:57 +00:00
|
|
|
mux.Handle("/forum/newest", middleware.CertRequired(forum.Newest()))
|
2022-08-24 05:55:19 +00:00
|
|
|
mux.Handle("/f/", middleware.CertRequired(forum.Forum()))
|
2022-12-21 03:15:45 +00:00
|
|
|
mux.Handle("/poll/vote", middleware.CertRequired(poll.Vote()))
|
2022-08-13 22:39:31 +00:00
|
|
|
|
|
|
|
// Admin endpoints.
|
|
|
|
mux.Handle("/admin", middleware.AdminRequired(admin.Dashboard()))
|
|
|
|
mux.Handle("/admin/photo/certification", middleware.AdminRequired(photo.AdminCertification()))
|
2022-08-21 21:05:08 +00:00
|
|
|
mux.Handle("/admin/feedback", middleware.AdminRequired(admin.Feedback()))
|
2022-08-14 23:27:57 +00:00
|
|
|
mux.Handle("/admin/user-action", middleware.AdminRequired(admin.UserActions()))
|
2022-08-24 05:55:19 +00:00
|
|
|
mux.Handle("/forum/admin", middleware.AdminRequired(forum.Manage()))
|
|
|
|
mux.Handle("/forum/admin/edit", middleware.AdminRequired(forum.AddEdit()))
|
2022-08-10 05:10:47 +00:00
|
|
|
|
|
|
|
// JSON API endpoints.
|
|
|
|
mux.HandleFunc("/v1/version", api.Version())
|
|
|
|
mux.HandleFunc("/v1/users/me", api.LoginOK())
|
2022-08-25 04:17:34 +00:00
|
|
|
mux.Handle("/v1/likes", middleware.LoginRequired(api.Likes()))
|
|
|
|
mux.Handle("/v1/notifications/read", middleware.LoginRequired(api.ReadNotification()))
|
2022-10-21 04:02:30 +00:00
|
|
|
mux.Handle("/v1/comment-photos/remove-orphaned", api.RemoveOrphanedCommentPhotos())
|
2022-08-10 05:10:47 +00:00
|
|
|
|
|
|
|
// Static files.
|
|
|
|
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(config.StaticPath))))
|
|
|
|
|
|
|
|
// Global middlewares.
|
2022-09-27 02:46:05 +00:00
|
|
|
withCSRF := middleware.CSRF(mux)
|
|
|
|
withSession := middleware.Session(withCSRF)
|
|
|
|
withRecovery := middleware.Recovery(withSession)
|
2022-08-10 05:10:47 +00:00
|
|
|
withLogger := middleware.Logging(withRecovery)
|
|
|
|
return withLogger
|
|
|
|
}
|