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"
|
2023-08-13 04:37:11 +00:00
|
|
|
"code.nonshy.com/nonshy/website/pkg/controller/api/barertc"
|
2022-08-26 04:21:46 +00:00
|
|
|
"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"
|
2024-04-25 03:36:37 +00:00
|
|
|
"code.nonshy.com/nonshy/website/pkg/controller/htmx"
|
2022-08-26 04:21:46 +00:00
|
|
|
"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"
|
2024-02-11 00:17:15 +00:00
|
|
|
nst "code.nonshy.com/nonshy/website/pkg/templates"
|
2024-07-21 02:44:22 +00:00
|
|
|
"code.nonshy.com/nonshy/website/pkg/webpush"
|
2022-08-10 05:10:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func New() http.Handler {
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
|
|
|
|
// Register controller endpoints.
|
|
|
|
mux.HandleFunc("/", index.Create())
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.HandleFunc("GET /favicon.ico", index.Favicon())
|
|
|
|
mux.HandleFunc("GET /manifest.json", index.Manifest())
|
2024-07-21 02:44:22 +00:00
|
|
|
mux.HandleFunc("GET /sw.js", index.ServiceWorker())
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.HandleFunc("GET /about", index.StaticTemplate("about.html")())
|
|
|
|
mux.HandleFunc("GET /features", index.StaticTemplate("features.html")())
|
2024-09-12 02:28:52 +00:00
|
|
|
mux.HandleFunc("GET /insights", index.Demographics())
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.HandleFunc("GET /faq", index.StaticTemplate("faq.html")())
|
|
|
|
mux.HandleFunc("GET /tos", index.StaticTemplate("tos.html")())
|
|
|
|
mux.HandleFunc("GET /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())
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.HandleFunc("GET /logout", account.Logout())
|
2023-06-24 22:39:45 +00:00
|
|
|
mux.Handle("/signup", middleware.GeoGate(account.Signup()))
|
2022-08-14 21:40:57 +00:00
|
|
|
mux.HandleFunc("/forgot-password", account.ForgotPassword())
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.HandleFunc("GET /settings/confirm-email", account.ConfirmEmailChange())
|
|
|
|
mux.HandleFunc("GET /markdown", index.StaticTemplate("markdown.html")())
|
|
|
|
mux.HandleFunc("GET /test/geo-gate", index.StaticTemplate("errors/geo_gate.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()))
|
2023-06-16 04:38:09 +00:00
|
|
|
mux.Handle("/settings/age-gate", middleware.LoginRequired(account.AgeGate()))
|
2023-09-19 00:22:50 +00:00
|
|
|
mux.Handle("/account/two-factor/setup", middleware.LoginRequired(account.Setup2FA()))
|
2022-08-14 21:40:57 +00:00
|
|
|
mux.Handle("/account/delete", middleware.LoginRequired(account.Delete()))
|
2023-10-22 22:02:24 +00:00
|
|
|
mux.Handle("/account/deactivate", middleware.LoginRequired(account.Deactivate()))
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.Handle("GET /account/reactivate", middleware.LoginRequired(account.Reactivate()))
|
|
|
|
mux.Handle("GET /u/{username}", account.Profile()) // public access OK
|
|
|
|
mux.Handle("GET /u/{username}/friends", middleware.CertRequired(account.UserFriends()))
|
|
|
|
mux.Handle("GET /u/{username}/photos", middleware.LoginRequired(photo.UserPhotos()))
|
|
|
|
mux.Handle("/u/{username}/notes", middleware.LoginRequired(account.UserNotes()))
|
2022-08-12 06:03:06 +00:00
|
|
|
mux.Handle("/photo/upload", middleware.LoginRequired(photo.Upload()))
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.Handle("GET /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()))
|
2024-10-05 04:17:20 +00:00
|
|
|
mux.Handle("/photo/batch-edit", middleware.LoginRequired(photo.BatchEdit()))
|
2022-08-13 22:39:31 +00:00
|
|
|
mux.Handle("/photo/certification", middleware.LoginRequired(photo.Certification()))
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.Handle("GET /photo/private", middleware.LoginRequired(photo.Private()))
|
2022-09-08 04:18:54 +00:00
|
|
|
mux.Handle("/photo/private/share", middleware.LoginRequired(photo.Share()))
|
2023-10-29 19:29:11 +00:00
|
|
|
mux.Handle("/notes/me", middleware.LoginRequired(account.MyNotes()))
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.Handle("GET /messages", middleware.LoginRequired(inbox.Inbox()))
|
|
|
|
mux.Handle("GET /messages/read/{id}", middleware.LoginRequired(inbox.Inbox()))
|
2022-08-14 00:42:42 +00:00
|
|
|
mux.Handle("/messages/compose", middleware.LoginRequired(inbox.Compose()))
|
2022-12-21 05:11:43 +00:00
|
|
|
mux.Handle("/messages/delete", middleware.LoginRequired(inbox.Delete()))
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.Handle("GET /friends", middleware.LoginRequired(friend.Friends()))
|
2022-08-14 05:44:57 +00:00
|
|
|
mux.Handle("/friends/add", middleware.LoginRequired(friend.AddFriend()))
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.Handle("POST /users/block", middleware.LoginRequired(block.BlockUser()))
|
|
|
|
mux.Handle("GET /users/blocked", middleware.LoginRequired(block.Blocked()))
|
|
|
|
mux.Handle("GET /users/blocklist/add", middleware.LoginRequired(block.AddUser()))
|
2022-08-27 02:50:33 +00:00
|
|
|
mux.Handle("/comments", middleware.LoginRequired(comment.PostComment()))
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.Handle("GET /comments/subscription", middleware.LoginRequired(comment.Subscription()))
|
|
|
|
mux.Handle("GET /admin/unimpersonate", middleware.LoginRequired(admin.Unimpersonate()))
|
2024-05-09 04:03:31 +00:00
|
|
|
mux.Handle("GET /admin/transparency/{username}", middleware.LoginRequired(admin.Transparency()))
|
2022-08-13 22:39:31 +00:00
|
|
|
|
|
|
|
// Certification Required. Pages that only full (verified) members can access.
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.Handle("GET /photo/gallery", middleware.CertRequired(photo.SiteGallery()))
|
|
|
|
mux.Handle("GET /members", middleware.CertRequired(account.Search()))
|
2023-02-06 04:26:36 +00:00
|
|
|
mux.Handle("/chat", middleware.CertRequired(chat.Landing()))
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.Handle("GET /forum", middleware.CertRequired(forum.Landing()))
|
2022-08-24 05:55:19 +00:00
|
|
|
mux.Handle("/forum/post", middleware.CertRequired(forum.NewPost()))
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.Handle("GET /forum/thread/{id}", middleware.CertRequired(forum.Thread()))
|
2024-08-24 05:24:38 +00:00
|
|
|
mux.Handle("POST /forum/thread/{id}/moderate", middleware.CertRequired(forum.ModerateThread()))
|
2024-08-22 04:53:35 +00:00
|
|
|
mux.Handle("GET /forum/explore", middleware.CertRequired(forum.Explore()))
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.Handle("GET /forum/newest", middleware.CertRequired(forum.Newest()))
|
|
|
|
mux.Handle("GET /forum/search", middleware.CertRequired(forum.Search()))
|
2024-08-21 04:26:53 +00:00
|
|
|
mux.Handle("POST /forum/subscribe", middleware.CertRequired(forum.Subscribe()))
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.Handle("GET /f/{fragment}", middleware.CertRequired(forum.Forum()))
|
|
|
|
mux.Handle("POST /poll/vote", middleware.CertRequired(poll.Vote()))
|
2024-08-22 04:53:35 +00:00
|
|
|
mux.Handle("/forum/admin", middleware.CertRequired(forum.Manage()))
|
|
|
|
mux.Handle("/forum/admin/edit", middleware.CertRequired(forum.AddEdit()))
|
|
|
|
mux.Handle("/forum/admin/moderator", middleware.CertRequired(forum.ManageModerators()))
|
2022-08-13 22:39:31 +00:00
|
|
|
|
|
|
|
// Admin endpoints.
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.Handle("GET /admin", middleware.AdminRequired("", admin.Dashboard()))
|
2023-08-02 03:39:48 +00:00
|
|
|
mux.Handle("/admin/scopes", middleware.AdminRequired("", admin.Scopes()))
|
|
|
|
mux.Handle("/admin/photo/certification", middleware.AdminRequired("", photo.AdminCertification()))
|
2024-05-09 04:03:31 +00:00
|
|
|
mux.Handle("/admin/feedback", middleware.AdminRequired(config.ScopeFeedbackAndReports, admin.Feedback()))
|
2023-08-02 03:39:48 +00:00
|
|
|
mux.Handle("/admin/user-action", middleware.AdminRequired("", admin.UserActions()))
|
2023-08-17 05:09:04 +00:00
|
|
|
mux.Handle("/admin/maintenance", middleware.AdminRequired(config.ScopeMaintenance, admin.Maintenance()))
|
2024-06-15 22:05:50 +00:00
|
|
|
mux.Handle("/admin/add-user", middleware.AdminRequired(config.ScopeUserCreate, admin.AddUser()))
|
2024-05-27 20:02:05 +00:00
|
|
|
mux.Handle("/admin/photo/mark-explicit", middleware.AdminRequired("", admin.MarkPhotoExplicit()))
|
2024-05-09 04:03:31 +00:00
|
|
|
mux.Handle("GET /admin/changelog", middleware.AdminRequired(config.ScopeChangeLog, admin.ChangeLog()))
|
2022-08-10 05:10:47 +00:00
|
|
|
|
|
|
|
// JSON API endpoints.
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.HandleFunc("GET /v1/version", api.Version())
|
2024-10-04 05:08:19 +00:00
|
|
|
mux.HandleFunc("GET /v1/auth/static", api.PhotoSignAuth())
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.HandleFunc("GET /v1/users/me", api.LoginOK())
|
|
|
|
mux.HandleFunc("POST /v1/users/check-username", api.UsernameCheck())
|
2024-07-21 02:44:22 +00:00
|
|
|
mux.HandleFunc("GET /v1/web-push/vapid-public-key", webpush.VAPIDPublicKey)
|
|
|
|
mux.Handle("POST /v1/web-push/register", middleware.LoginRequired(webpush.Register()))
|
|
|
|
mux.Handle("GET /v1/web-push/unregister", middleware.LoginRequired(webpush.UnregisterAll()))
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.Handle("POST /v1/likes", middleware.LoginRequired(api.Likes()))
|
|
|
|
mux.Handle("GET /v1/likes/users", middleware.LoginRequired(api.WhoLikes()))
|
2024-09-26 05:46:33 +00:00
|
|
|
mux.Handle("POST /v1/photo/{photo_id}/view", middleware.LoginRequired(api.ViewPhoto()))
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.Handle("POST /v1/notifications/read", middleware.LoginRequired(api.ReadNotification()))
|
|
|
|
mux.Handle("POST /v1/notifications/delete", middleware.LoginRequired(api.ClearNotification()))
|
2024-03-16 20:29:28 +00:00
|
|
|
mux.Handle("POST /v1/photos/mark-explicit", middleware.LoginRequired(api.MarkPhotoExplicit()))
|
2024-08-03 21:54:22 +00:00
|
|
|
mux.Handle("GET /v1/world-cities", middleware.LoginRequired(api.WorldCities()))
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.Handle("POST /v1/barertc/report", barertc.Report())
|
|
|
|
mux.Handle("POST /v1/barertc/profile", barertc.Profile())
|
2022-08-10 05:10:47 +00:00
|
|
|
|
2024-04-25 03:36:37 +00:00
|
|
|
// HTMX endpoints.
|
|
|
|
mux.Handle("GET /htmx/user/profile/activity", middleware.LoginRequired(htmx.UserProfileActivityCard()))
|
|
|
|
|
2024-01-06 06:14:42 +00:00
|
|
|
// Redirect endpoints.
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.Handle("GET /go/comment", middleware.LoginRequired(comment.GoToComment()))
|
2024-01-06 06:14:42 +00:00
|
|
|
|
2022-08-10 05:10:47 +00:00
|
|
|
// Static files.
|
2024-02-11 00:17:15 +00:00
|
|
|
mux.Handle("GET /static/", http.StripPrefix("/static/", http.FileServer(http.Dir(config.StaticPath))))
|
|
|
|
|
|
|
|
// Legacy route redirects (Go 1.22 path parameters update)
|
|
|
|
mux.Handle("GET /friends/u/{s}", nst.RedirectRoute("/u/%s/friends"))
|
|
|
|
mux.Handle("GET /photo/u/{s}", nst.RedirectRoute("/u/%s/photos"))
|
|
|
|
mux.Handle("GET /notes/u/{s}", nst.RedirectRoute("/u/%s/notes"))
|
2022-08-10 05:10:47 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|