74e09efb63
Likes are now done over AJAX. Posts you have liked are now visually differentiated from those which you have not. Added support for OR to the where parser. || and && now get translated to OR and AND in the where parser. Added support for ( and ) in the where parser. Added an adapter and builder method for getting the database version. Multiple wheres can now be chained with the micro and accumulator builders. Added the In method to the accumulator select builder. Added the GetConn method to the builder. /uploads/ files should now get cached properly. Added more tooltips for topic titles and usernames. Fixed a bug in the runners where old stale templates would be served. Fixed a bug where liking topics didn't work. Began moving the database initialisation logic out of {adapter}.go and into querygen. Tweaked the alert direction to show the newest alerts rather than the oldest. Tweaked the WS JS to have it handle messages more efficiently. Partially fixed an issue where inline edited posts would lack newlines until the page is refreshed. Used arrow functions in a few places in global.js to save a few characters. Schema: Added the liked, oldestItemLikedCreatedAt and lastLiked columns to the users table. Added the createdAt column to the likes table. MySQL Update Queries: ALTER TABLE `users` ADD COLUMN `liked` INT NOT NULL DEFAULT '0' AFTER `topics`; ALTER TABLE `users` ADD COLUMN `oldestItemLikedCreatedAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `liked`; ALTER TABLE `users` ADD COLUMN `lastLiked` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `oldestItemLikedCreatedAt`; ALTER TABLE `likes` ADD COLUMN `createdAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `sentBy`; delete from `likes`; delete from `activity_stream` where `event` = 'like'; delete from `activity_stream_matches` where `asid` not in(select `asid` from `activity_stream`); update `topics` set `likeCount` = 0; update `replies` set `likeCount` = 0;
195 lines
9.4 KiB
Go
195 lines
9.4 KiB
Go
package main
|
|
|
|
// TODO: How should we handle headerLite and headerVar?
|
|
func routes() {
|
|
addRoute(View("routeAPI", "/api/"))
|
|
addRoute(View("routes.Overview", "/overview/"))
|
|
addRoute(View("routes.CustomPage", "/pages/", "extraData"))
|
|
addRoute(View("routes.ForumList", "/forums/" /*,"&forums"*/))
|
|
addRoute(View("routes.ViewForum", "/forum/", "extraData"))
|
|
addRoute(AnonAction("routeChangeTheme", "/theme/"))
|
|
addRoute(
|
|
View("routeShowAttachment", "/attachs/", "extraData").Before("ParseForm"),
|
|
)
|
|
|
|
// TODO: Reduce the number of Befores. With a new method, perhaps?
|
|
reportGroup := newRouteGroup("/report/",
|
|
Action("routeReportSubmit", "/report/submit/", "extraData"),
|
|
).Before("NoBanned")
|
|
addRouteGroup(reportGroup)
|
|
|
|
topicGroup := newRouteGroup("/topics/",
|
|
View("routes.TopicList", "/topics/"),
|
|
MemberView("routes.CreateTopic", "/topics/create/", "extraData"),
|
|
)
|
|
addRouteGroup(topicGroup)
|
|
|
|
buildPanelRoutes()
|
|
buildUserRoutes()
|
|
buildTopicRoutes()
|
|
buildReplyRoutes()
|
|
buildProfileReplyRoutes()
|
|
buildPollRoutes()
|
|
buildAccountRoutes()
|
|
|
|
addRoute(Special("common.RouteWebsockets", "/ws/"))
|
|
}
|
|
|
|
// TODO: Test the email token route
|
|
func buildUserRoutes() {
|
|
userGroup := newRouteGroup("/user/")
|
|
userGroup.Routes(
|
|
View("routes.ViewProfile", "/user/").LitBefore("req.URL.Path += extraData"),
|
|
MemberView("routes.AccountEditCritical", "/user/edit/critical/"),
|
|
Action("routeAccountEditCriticalSubmit", "/user/edit/critical/submit/"), // TODO: Full test this
|
|
MemberView("routeAccountEditAvatar", "/user/edit/avatar/"),
|
|
UploadAction("routeAccountEditAvatarSubmit", "/user/edit/avatar/submit/").MaxSizeVar("common.Config.MaxRequestSize"),
|
|
MemberView("routeAccountEditUsername", "/user/edit/username/"),
|
|
Action("routeAccountEditUsernameSubmit", "/user/edit/username/submit/"), // TODO: Full test this
|
|
MemberView("routeAccountEditEmail", "/user/edit/email/"),
|
|
Action("routeAccountEditEmailTokenSubmit", "/user/edit/token/", "extraData"),
|
|
)
|
|
addRouteGroup(userGroup)
|
|
|
|
// TODO: Auto test and manual test these routes
|
|
userGroup = newRouteGroup("/users/")
|
|
userGroup.Routes(
|
|
Action("routes.BanUserSubmit", "/users/ban/submit/", "extraData"),
|
|
Action("routes.UnbanUser", "/users/unban/", "extraData"),
|
|
Action("routes.ActivateUser", "/users/activate/", "extraData"),
|
|
MemberView("routes.IPSearch", "/users/ips/"), // TODO: .Perms("ViewIPs")?
|
|
)
|
|
addRouteGroup(userGroup)
|
|
}
|
|
|
|
func buildTopicRoutes() {
|
|
topicGroup := newRouteGroup("/topic/")
|
|
topicGroup.Routes(
|
|
View("routes.ViewTopic", "/topic/", "extraData"),
|
|
UploadAction("routes.CreateTopicSubmit", "/topic/create/submit/").MaxSizeVar("common.Config.MaxRequestSize"),
|
|
Action("routes.EditTopicSubmit", "/topic/edit/submit/", "extraData"),
|
|
Action("routes.DeleteTopicSubmit", "/topic/delete/submit/").LitBefore("req.URL.Path += extraData"),
|
|
Action("routes.StickTopicSubmit", "/topic/stick/submit/", "extraData"),
|
|
Action("routes.UnstickTopicSubmit", "/topic/unstick/submit/", "extraData"),
|
|
Action("routes.LockTopicSubmit", "/topic/lock/submit/").LitBefore("req.URL.Path += extraData"),
|
|
Action("routes.UnlockTopicSubmit", "/topic/unlock/submit/", "extraData"),
|
|
Action("routes.MoveTopicSubmit", "/topic/move/submit/", "extraData"),
|
|
Action("routeLikeTopicSubmit", "/topic/like/submit/", "extraData").Before("ParseForm"),
|
|
)
|
|
addRouteGroup(topicGroup)
|
|
}
|
|
|
|
func buildReplyRoutes() {
|
|
//router.HandleFunc("/reply/edit/", routeReplyEdit) // No js fallback
|
|
//router.HandleFunc("/reply/delete/", routeReplyDelete) // No js confirmation page? We could have a confirmation modal for the JS case
|
|
replyGroup := newRouteGroup("/reply/")
|
|
replyGroup.Routes(
|
|
// TODO: Reduce this to 1MB for attachments for each file?
|
|
UploadAction("routes.CreateReplySubmit", "/reply/create/").MaxSizeVar("common.Config.MaxRequestSize"), // TODO: Rename the route so it's /reply/create/submit/
|
|
Action("routes.ReplyEditSubmit", "/reply/edit/submit/", "extraData"),
|
|
Action("routes.ReplyDeleteSubmit", "/reply/delete/submit/", "extraData"),
|
|
Action("routeReplyLikeSubmit", "/reply/like/submit/", "extraData").Before("ParseForm"),
|
|
)
|
|
addRouteGroup(replyGroup)
|
|
}
|
|
|
|
// TODO: Move these into /user/?
|
|
func buildProfileReplyRoutes() {
|
|
//router.HandleFunc("/user/edit/submit/", routeLogout) // routeLogout? what on earth? o.o
|
|
pReplyGroup := newRouteGroup("/profile/")
|
|
pReplyGroup.Routes(
|
|
Action("routeProfileReplyCreateSubmit", "/profile/reply/create/"), // TODO: Add /submit/ to the end
|
|
Action("routes.ProfileReplyEditSubmit", "/profile/reply/edit/submit/", "extraData"),
|
|
Action("routes.ProfileReplyDeleteSubmit", "/profile/reply/delete/submit/", "extraData"),
|
|
)
|
|
addRouteGroup(pReplyGroup)
|
|
}
|
|
|
|
func buildPollRoutes() {
|
|
pollGroup := newRouteGroup("/poll/")
|
|
pollGroup.Routes(
|
|
Action("routes.PollVote", "/poll/vote/", "extraData"),
|
|
View("routes.PollResults", "/poll/results/", "extraData"),
|
|
)
|
|
addRouteGroup(pollGroup)
|
|
}
|
|
|
|
func buildAccountRoutes() {
|
|
//router.HandleFunc("/accounts/list/", routeLogin) // Redirect /accounts/ and /user/ to here.. // Get a list of all of the accounts on the forum
|
|
accReplyGroup := newRouteGroup("/accounts/")
|
|
accReplyGroup.Routes(
|
|
View("routes.AccountLogin", "/accounts/login/"),
|
|
View("routes.AccountRegister", "/accounts/create/"),
|
|
Action("routeLogout", "/accounts/logout/"),
|
|
AnonAction("routes.AccountLoginSubmit", "/accounts/login/submit/"), // TODO: Guard this with a token, maybe the IP hashed with a rotated key?
|
|
AnonAction("routes.AccountRegisterSubmit", "/accounts/create/submit/"),
|
|
)
|
|
addRouteGroup(accReplyGroup)
|
|
}
|
|
|
|
func buildPanelRoutes() {
|
|
panelGroup := newRouteGroup("/panel/").Before("SuperModOnly")
|
|
panelGroup.Routes(
|
|
View("routePanelDashboard", "/panel/"),
|
|
View("routePanelForums", "/panel/forums/"),
|
|
Action("routePanelForumsCreateSubmit", "/panel/forums/create/"),
|
|
Action("routePanelForumsDelete", "/panel/forums/delete/", "extraData"),
|
|
Action("routePanelForumsDeleteSubmit", "/panel/forums/delete/submit/", "extraData"),
|
|
View("routePanelForumsEdit", "/panel/forums/edit/", "extraData"),
|
|
Action("routePanelForumsEditSubmit", "/panel/forums/edit/submit/", "extraData"),
|
|
Action("routePanelForumsEditPermsSubmit", "/panel/forums/edit/perms/submit/", "extraData"),
|
|
View("routePanelForumsEditPermsAdvance", "/panel/forums/edit/perms/", "extraData"),
|
|
Action("routePanelForumsEditPermsAdvanceSubmit", "/panel/forums/edit/perms/adv/submit/", "extraData"),
|
|
|
|
View("routePanelSettings", "/panel/settings/"),
|
|
View("routePanelSettingEdit", "/panel/settings/edit/", "extraData"),
|
|
Action("routePanelSettingEditSubmit", "/panel/settings/edit/submit/", "extraData"),
|
|
|
|
View("routePanelWordFilters", "/panel/settings/word-filters/"),
|
|
Action("routePanelWordFiltersCreateSubmit", "/panel/settings/word-filters/create/"),
|
|
View("routePanelWordFiltersEdit", "/panel/settings/word-filters/edit/", "extraData"),
|
|
Action("routePanelWordFiltersEditSubmit", "/panel/settings/word-filters/edit/submit/", "extraData"),
|
|
Action("routePanelWordFiltersDeleteSubmit", "/panel/settings/word-filters/delete/submit/", "extraData"),
|
|
|
|
View("routePanelThemes", "/panel/themes/"),
|
|
Action("routePanelThemesSetDefault", "/panel/themes/default/", "extraData"),
|
|
|
|
View("routePanelPlugins", "/panel/plugins/"),
|
|
Action("routePanelPluginsActivate", "/panel/plugins/activate/", "extraData"),
|
|
Action("routePanelPluginsDeactivate", "/panel/plugins/deactivate/", "extraData"),
|
|
Action("routePanelPluginsInstall", "/panel/plugins/install/", "extraData"),
|
|
|
|
View("routePanelUsers", "/panel/users/"),
|
|
View("routePanelUsersEdit", "/panel/users/edit/", "extraData"),
|
|
Action("routePanelUsersEditSubmit", "/panel/users/edit/submit/", "extraData"),
|
|
|
|
View("routePanelAnalyticsViews", "/panel/analytics/views/").Before("ParseForm"),
|
|
View("routePanelAnalyticsRoutes", "/panel/analytics/routes/").Before("ParseForm"),
|
|
View("routePanelAnalyticsAgents", "/panel/analytics/agents/").Before("ParseForm"),
|
|
View("routePanelAnalyticsSystems", "/panel/analytics/systems/").Before("ParseForm"),
|
|
View("routePanelAnalyticsLanguages", "/panel/analytics/langs/").Before("ParseForm"),
|
|
View("routePanelAnalyticsReferrers", "/panel/analytics/referrers/").Before("ParseForm"),
|
|
View("routePanelAnalyticsRouteViews", "/panel/analytics/route/", "extraData"),
|
|
View("routePanelAnalyticsAgentViews", "/panel/analytics/agent/", "extraData"),
|
|
View("routePanelAnalyticsForumViews", "/panel/analytics/forum/", "extraData"),
|
|
View("routePanelAnalyticsSystemViews", "/panel/analytics/system/", "extraData"),
|
|
View("routePanelAnalyticsLanguageViews", "/panel/analytics/lang/", "extraData"),
|
|
View("routePanelAnalyticsReferrerViews", "/panel/analytics/referrer/", "extraData"),
|
|
View("routePanelAnalyticsPosts", "/panel/analytics/posts/").Before("ParseForm"),
|
|
View("routePanelAnalyticsTopics", "/panel/analytics/topics/").Before("ParseForm"),
|
|
View("routePanelAnalyticsForums", "/panel/analytics/forums/").Before("ParseForm"),
|
|
|
|
View("routePanelGroups", "/panel/groups/"),
|
|
View("routePanelGroupsEdit", "/panel/groups/edit/", "extraData"),
|
|
View("routePanelGroupsEditPerms", "/panel/groups/edit/perms/", "extraData"),
|
|
Action("routePanelGroupsEditSubmit", "/panel/groups/edit/submit/", "extraData"),
|
|
Action("routePanelGroupsEditPermsSubmit", "/panel/groups/edit/perms/submit/", "extraData"),
|
|
Action("routePanelGroupsCreateSubmit", "/panel/groups/create/"),
|
|
|
|
View("routePanelBackups", "/panel/backups/", "extraData").Before("SuperAdminOnly"), // TODO: Test
|
|
View("routePanelLogsMod", "/panel/logs/mod/"),
|
|
View("routePanelDebug", "/panel/debug/").Before("AdminOnly"),
|
|
)
|
|
addRouteGroup(panelGroup)
|
|
}
|