hoist runnables shared among all routes in a route group to the route group to reduce code duplication
rewrite router gen to make indentation maintenance easier
This commit is contained in:
parent
75561508c8
commit
b9d94d0888
344
gen_router.go
344
gen_router.go
@ -1489,24 +1489,24 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
err = routes.ViewForum(w,req,user,h,extraData)
|
||||
co.RouteViewCounter.Bump3(4, cn)
|
||||
case "/theme":
|
||||
err = c.ParseForm(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = c.ParseForm(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = routes.ChangeTheme(w,req,user)
|
||||
co.RouteViewCounter.Bump3(5, cn)
|
||||
case "/attachs":
|
||||
err = c.ParseForm(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = c.ParseForm(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w = r.responseWriter(w)
|
||||
w = r.responseWriter(w)
|
||||
err = routes.ShowAttachment(w,req,user,extraData)
|
||||
co.RouteViewCounter.Bump3(6, cn)
|
||||
case "/ws":
|
||||
req.URL.Path += extraData
|
||||
req.URL.Path += extraData
|
||||
err = c.RouteWebsockets(w,req,user)
|
||||
case "/api":
|
||||
switch(req.URL.Path) {
|
||||
@ -1521,7 +1521,7 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
co.RouteViewCounter.Bump3(10, cn)
|
||||
default:
|
||||
err = routeAPI(w,req,user)
|
||||
co.RouteViewCounter.Bump3(11, cn)
|
||||
co.RouteViewCounter.Bump3(11, cn)
|
||||
}
|
||||
case "/report":
|
||||
err = c.NoBanned(w,req,user)
|
||||
@ -1529,35 +1529,35 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.NoSessionMismatch(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.MemberOnly(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch(req.URL.Path) {
|
||||
case "/report/submit/":
|
||||
err = c.NoSessionMismatch(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.MemberOnly(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = routes.ReportSubmit(w,req,user,extraData)
|
||||
co.RouteViewCounter.Bump3(12, cn)
|
||||
}
|
||||
case "/topics":
|
||||
switch(req.URL.Path) {
|
||||
case "/topics/most-viewed/":
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.TopicListMostViewed(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(13, cn)
|
||||
case "/topics/week-views/":
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.TopicListWeekViews(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(14, cn)
|
||||
case "/topics/create/":
|
||||
@ -1566,10 +1566,10 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.CreateTopic(w,req,user,h,extraData)
|
||||
co.RouteViewCounter.Bump3(15, cn)
|
||||
default:
|
||||
@ -1577,8 +1577,8 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.TopicList(w,req,user, h)
|
||||
co.RouteViewCounter.Bump3(16, cn)
|
||||
err = routes.TopicList(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(16, cn)
|
||||
}
|
||||
case "/panel":
|
||||
err = c.SuperModOnly(w,req,user)
|
||||
@ -2101,7 +2101,7 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
co.RouteViewCounter.Bump3(95, cn)
|
||||
default:
|
||||
err = panel.Dashboard(w,req,user)
|
||||
co.RouteViewCounter.Bump3(96, cn)
|
||||
co.RouteViewCounter.Bump3(96, cn)
|
||||
}
|
||||
case "/user":
|
||||
switch(req.URL.Path) {
|
||||
@ -2111,10 +2111,10 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.AccountEdit(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(97, cn)
|
||||
case "/user/edit/password/":
|
||||
@ -2123,10 +2123,10 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.AccountEditPassword(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(98, cn)
|
||||
case "/user/edit/password/submit/":
|
||||
@ -2191,10 +2191,10 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.AccountEditPrivacy(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(103, cn)
|
||||
case "/user/edit/privacy/submit/":
|
||||
@ -2216,10 +2216,10 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.AccountEditMFA(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(105, cn)
|
||||
case "/user/edit/mfa/setup/":
|
||||
@ -2228,10 +2228,10 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.AccountEditMFASetup(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(106, cn)
|
||||
case "/user/edit/mfa/setup/submit/":
|
||||
@ -2266,10 +2266,10 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.AccountEditEmail(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(109, cn)
|
||||
case "/user/edit/token/":
|
||||
@ -2281,10 +2281,10 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.AccountLogins(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(111, cn)
|
||||
case "/user/edit/blocked/":
|
||||
@ -2293,10 +2293,10 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.AccountBlocked(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(112, cn)
|
||||
case "/user/levels/":
|
||||
@ -2305,10 +2305,10 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.LevelList(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(113, cn)
|
||||
case "/user/convos/":
|
||||
@ -2317,10 +2317,10 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.Convos(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(114, cn)
|
||||
case "/user/convos/create/":
|
||||
@ -2329,10 +2329,10 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.ConvosCreate(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(115, cn)
|
||||
case "/user/convo/":
|
||||
@ -2341,10 +2341,10 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.Convo(w,req,user,h,extraData)
|
||||
co.RouteViewCounter.Bump3(116, cn)
|
||||
case "/user/convos/create/submit/":
|
||||
@ -2405,10 +2405,10 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.RelationsBlockCreate(w,req,user,h,extraData)
|
||||
co.RouteViewCounter.Bump3(121, cn)
|
||||
case "/user/block/create/submit/":
|
||||
@ -2430,10 +2430,10 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.RelationsBlockRemove(w,req,user,h,extraData)
|
||||
co.RouteViewCounter.Bump3(123, cn)
|
||||
case "/user/block/remove/submit/":
|
||||
@ -2455,10 +2455,15 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.ViewProfile(w,req,user, h)
|
||||
co.RouteViewCounter.Bump3(125, cn)
|
||||
err = routes.ViewProfile(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(125, cn)
|
||||
}
|
||||
case "/users":
|
||||
err = c.MemberOnly(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch(req.URL.Path) {
|
||||
case "/users/ban/submit/":
|
||||
err = c.NoSessionMismatch(w,req,user)
|
||||
@ -2466,11 +2471,6 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.MemberOnly(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = routes.BanUserSubmit(w,req,user,extraData)
|
||||
co.RouteViewCounter.Bump3(126, cn)
|
||||
case "/users/unban/":
|
||||
@ -2479,11 +2479,6 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.MemberOnly(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = routes.UnbanUser(w,req,user,extraData)
|
||||
co.RouteViewCounter.Bump3(127, cn)
|
||||
case "/users/activate/":
|
||||
@ -2492,23 +2487,13 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.MemberOnly(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = routes.ActivateUser(w,req,user,extraData)
|
||||
co.RouteViewCounter.Bump3(128, cn)
|
||||
case "/users/ips/":
|
||||
err = c.MemberOnly(w,req,user)
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.IPSearch(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(129, cn)
|
||||
case "/users/delete-posts/submit/":
|
||||
@ -2517,11 +2502,6 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.MemberOnly(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = routes.DeletePostsSubmit(w,req,user,extraData)
|
||||
co.RouteViewCounter.Bump3(130, cn)
|
||||
}
|
||||
@ -2698,17 +2678,17 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.ViewTopic(w,req,user, h, extraData)
|
||||
co.RouteViewCounter.Bump3(143, cn)
|
||||
err = routes.ViewTopic(w,req,user,h,extraData)
|
||||
co.RouteViewCounter.Bump3(143, cn)
|
||||
}
|
||||
case "/reply":
|
||||
err = c.MemberOnly(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch(req.URL.Path) {
|
||||
case "/reply/create/":
|
||||
err = c.MemberOnly(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.HandleUploadRoute(w,req,user,int(c.Config.MaxRequestSize))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -2726,11 +2706,6 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.MemberOnly(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = routes.ReplyEditSubmit(w,req,user,extraData)
|
||||
co.RouteViewCounter.Bump3(145, cn)
|
||||
case "/reply/delete/submit/":
|
||||
@ -2739,11 +2714,6 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.MemberOnly(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = routes.ReplyDeleteSubmit(w,req,user,extraData)
|
||||
co.RouteViewCounter.Bump3(146, cn)
|
||||
case "/reply/like/submit/":
|
||||
@ -2752,11 +2722,6 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.MemberOnly(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = routes.ReplyLikeSubmit(w,req,user,extraData)
|
||||
co.RouteViewCounter.Bump3(147, cn)
|
||||
case "/reply/unlike/submit/":
|
||||
@ -2765,19 +2730,9 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.MemberOnly(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = routes.ReplyUnlikeSubmit(w,req,user,extraData)
|
||||
co.RouteViewCounter.Bump3(148, cn)
|
||||
case "/reply/attach/add/submit/":
|
||||
err = c.MemberOnly(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.HandleUploadRoute(w,req,user,int(c.Config.MaxRequestSize))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -2795,53 +2750,28 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.MemberOnly(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = routes.RemoveAttachFromReplySubmit(w,req,user,extraData)
|
||||
co.RouteViewCounter.Bump3(150, cn)
|
||||
}
|
||||
case "/profile":
|
||||
err = c.NoSessionMismatch(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.MemberOnly(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch(req.URL.Path) {
|
||||
case "/profile/reply/create/":
|
||||
err = c.NoSessionMismatch(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.MemberOnly(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = routes.ProfileReplyCreateSubmit(w,req,user)
|
||||
co.RouteViewCounter.Bump3(151, cn)
|
||||
case "/profile/reply/edit/submit/":
|
||||
err = c.NoSessionMismatch(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.MemberOnly(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = routes.ProfileReplyEditSubmit(w,req,user,extraData)
|
||||
co.RouteViewCounter.Bump3(152, cn)
|
||||
case "/profile/reply/delete/submit/":
|
||||
err = c.NoSessionMismatch(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.MemberOnly(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = routes.ProfileReplyDeleteSubmit(w,req,user,extraData)
|
||||
co.RouteViewCounter.Bump3(153, cn)
|
||||
}
|
||||
@ -2867,17 +2797,17 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
case "/accounts":
|
||||
switch(req.URL.Path) {
|
||||
case "/accounts/login/":
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.AccountLogin(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(156, cn)
|
||||
case "/accounts/create/":
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.AccountRegister(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(157, cn)
|
||||
case "/accounts/logout/":
|
||||
@ -2902,10 +2832,10 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
err = routes.AccountLoginSubmit(w,req,user)
|
||||
co.RouteViewCounter.Bump3(159, cn)
|
||||
case "/accounts/mfa_verify/":
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.AccountLoginMFAVerify(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(160, cn)
|
||||
case "/accounts/mfa_verify/submit/":
|
||||
@ -2925,10 +2855,10 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
err = routes.AccountRegisterSubmit(w,req,user)
|
||||
co.RouteViewCounter.Bump3(162, cn)
|
||||
case "/accounts/password-reset/":
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.AccountPasswordReset(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(163, cn)
|
||||
case "/accounts/password-reset/submit/":
|
||||
@ -2940,10 +2870,10 @@ func (r *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, user *
|
||||
err = routes.AccountPasswordResetSubmit(w,req,user)
|
||||
co.RouteViewCounter.Bump3(164, cn)
|
||||
case "/accounts/password-reset/token/":
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, err := c.UserCheckNano(w,req,user,cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = routes.AccountPasswordResetToken(w,req,user,h)
|
||||
co.RouteViewCounter.Bump3(165, cn)
|
||||
case "/accounts/password-reset/token/submit/":
|
||||
|
@ -49,65 +49,119 @@ func main() {
|
||||
allRouteMap[name] = len(allRouteNames) - 1
|
||||
}
|
||||
mapIt("routes.Error")
|
||||
countToIndents := func(indent int) (indentor string) {
|
||||
for i := 0; i < indent; i++ {
|
||||
indentor += "\t"
|
||||
|
||||
var indentCache [20]string
|
||||
countToIndents := func(ind int) string {
|
||||
out := indentCache[ind]
|
||||
if out != "" {
|
||||
return out
|
||||
}
|
||||
return indentor
|
||||
for i := 0; i < ind; i++ {
|
||||
out += "\t"
|
||||
}
|
||||
if ind < 20 {
|
||||
indentCache[ind] = out
|
||||
}
|
||||
return out
|
||||
}
|
||||
/*o := func(indent int, str string) {
|
||||
out += countToIndents(indent) + str
|
||||
}*/
|
||||
on := func(indent int, str string) {
|
||||
out += "\n" + countToIndents(indent) + str
|
||||
}
|
||||
iferrn := func(indent int) {
|
||||
ind := countToIndents(indent)
|
||||
ind2 := countToIndents(indent + 1)
|
||||
out += "\n" + ind + "if err != nil {"
|
||||
out += "\n" + ind2 + "return err\n" + ind + "}"
|
||||
}
|
||||
|
||||
runBefore := func(runnables []Runnable, indentCount int) (out string) {
|
||||
indent := countToIndents(indentCount)
|
||||
ind := countToIndents(indentCount)
|
||||
if len(runnables) > 0 {
|
||||
for _, runnable := range runnables {
|
||||
if runnable.Literal {
|
||||
out += "\n\t" + indent + runnable.Contents
|
||||
out += "\n\t" + ind + runnable.Contents
|
||||
} else {
|
||||
out += "\n" + indent + "err = c." + runnable.Contents + "(w,req,user)\n" +
|
||||
indent + "if err != nil {\n" +
|
||||
indent + "\treturn err\n" +
|
||||
indent + "}\n" + indent
|
||||
out += "\n" + ind + "err = c." + runnable.Contents + "(w,req,user)\n" +
|
||||
ind + "if err != nil {\n" +
|
||||
ind + "\treturn err\n" +
|
||||
ind + "}\n" + ind
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
userCheckNano := func(indent int, route *RouteImpl) {
|
||||
on(indent, "h, err := c.UserCheckNano(w,req,user,cn)")
|
||||
iferrn(indent)
|
||||
vcpy := route.Vars
|
||||
route.Vars = []string{"h"}
|
||||
route.Vars = append(route.Vars, vcpy...)
|
||||
}
|
||||
writeRoute := func(indent int, r *RouteImpl) {
|
||||
on(indent, "err = "+strings.Replace(r.Name, "common.", "c.", -1)+"(w,req,user")
|
||||
for _, item := range r.Vars {
|
||||
out += "," + item
|
||||
}
|
||||
out += `)`
|
||||
}
|
||||
|
||||
for _, route := range r.routeList {
|
||||
mapIt(route.Name)
|
||||
end := len(route.Path) - 1
|
||||
out += "\n\t\tcase \"" + route.Path[0:end] + "\":"
|
||||
//out += "\n\t\t\tid = " + strconv.Itoa(allRouteMap[route.Name])
|
||||
out += runBefore(route.RunBefore, 4)
|
||||
on(2, "case \""+route.Path[0:end]+"\":")
|
||||
//on(3,"id = " + strconv.Itoa(allRouteMap[route.Name]))
|
||||
out += runBefore(route.RunBefore, 3)
|
||||
if !route.Action && !route.NoHead {
|
||||
//out += "\n\t\t\th, err := c.UserCheck(w,req,user)"
|
||||
out += "\n\t\t\th, err := c.UserCheckNano(w,req,user,cn)"
|
||||
out += "\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}"
|
||||
vcpy := route.Vars
|
||||
route.Vars = []string{"h"}
|
||||
route.Vars = append(route.Vars, vcpy...)
|
||||
//on(3,"h, err := c.UserCheck(w,req,user)")
|
||||
userCheckNano(3, route)
|
||||
} /* else if route.Name != "common.RouteWebsockets" {
|
||||
//out += "\n\t\t\tsa := time.Now()"
|
||||
//out += "\n\t\t\tcn := uutils.Nanotime()"
|
||||
//on(3,"sa := time.Now()")
|
||||
//on(3,"cn := uutils.Nanotime()")
|
||||
}*/
|
||||
out += "\n\t\t\terr = " + strings.Replace(route.Name, "common.", "c.", -1) + "(w,req,user"
|
||||
for _, item := range route.Vars {
|
||||
out += "," + item
|
||||
}
|
||||
out += `)`
|
||||
writeRoute(3, route)
|
||||
/*if !route.Action && !route.NoHead {
|
||||
out += "\n\t\t\tco.RouteViewCounter.Bump2(" + strconv.Itoa(allRouteMap[route.Name]) + ", h.StartedAt)"
|
||||
on(3,"co.RouteViewCounter.Bump2(" + strconv.Itoa(allRouteMap[route.Name]) + ", h.StartedAt)")
|
||||
} else */if route.Name != "common.RouteWebsockets" {
|
||||
//out += "\n\t\t\tco.RouteViewCounter.Bump(" + strconv.Itoa(allRouteMap[route.Name]) + ")"
|
||||
//out += "\n\t\t\tco.RouteViewCounter.Bump2(" + strconv.Itoa(allRouteMap[route.Name]) + ", sa)"
|
||||
out += "\n\t\t\tco.RouteViewCounter.Bump3(" + strconv.Itoa(allRouteMap[route.Name]) + ", cn)"
|
||||
//on(3,"co.RouteViewCounter.Bump(" + strconv.Itoa(allRouteMap[route.Name]) + ")")
|
||||
//on(3,"co.RouteViewCounter.Bump2(" + strconv.Itoa(allRouteMap[route.Name]) + ", sa)")
|
||||
on(3, "co.RouteViewCounter.Bump3("+strconv.Itoa(allRouteMap[route.Name])+", cn)")
|
||||
}
|
||||
}
|
||||
|
||||
// Hoist runnables which appear on every route to the route group to avoid code duplication
|
||||
skipRunnableAntiDupe:
|
||||
for _, g := range r.routeGroups {
|
||||
dupeMap := make(map[string]int)
|
||||
for _, route := range g.RouteList {
|
||||
if len(route.RunBefore) == 0 {
|
||||
continue skipRunnableAntiDupe
|
||||
}
|
||||
// TODO: What if there are duplicates of the same runnable on this route?
|
||||
for _, runnable := range route.RunBefore {
|
||||
dupeMap[runnable.Contents] += 1
|
||||
}
|
||||
}
|
||||
|
||||
// Unset entries which are already set on the route group
|
||||
for _, gRunnable := range g.RunBefore {
|
||||
delete(dupeMap, gRunnable.Contents)
|
||||
}
|
||||
|
||||
for runnable, count := range dupeMap {
|
||||
if count == len(g.RouteList) {
|
||||
g.Before(runnable)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, group := range r.routeGroups {
|
||||
end := len(group.Path) - 1
|
||||
out += "\n\t\tcase \"" + group.Path[0:end] + "\":"
|
||||
on(2, "case \""+group.Path[0:end]+"\":")
|
||||
out += runBefore(group.RunBefore, 3)
|
||||
out += "\n\t\t\tswitch(req.URL.Path) {"
|
||||
on(3, "switch(req.URL.Path) {")
|
||||
|
||||
defaultRoute := blankRoute()
|
||||
for _, route := range group.RouteList {
|
||||
@ -117,89 +171,72 @@ func main() {
|
||||
}
|
||||
mapIt(route.Name)
|
||||
|
||||
out += "\n\t\t\t\tcase \"" + route.Path + "\":"
|
||||
//out += "\n\t\t\t\t\tid = " + strconv.Itoa(allRouteMap[route.Name])
|
||||
on(4, "case \""+route.Path+"\":")
|
||||
//on(5,"id = " + strconv.Itoa(allRouteMap[route.Name]))
|
||||
if len(route.RunBefore) > 0 {
|
||||
skipRunnable:
|
||||
for _, runnable := range route.RunBefore {
|
||||
for _, gRunnable := range group.RunBefore {
|
||||
if gRunnable.Contents == runnable.Contents {
|
||||
continue
|
||||
continue skipRunnable
|
||||
}
|
||||
f := func(e1, e2 string) bool {
|
||||
return gRunnable.Contents == e1 && runnable.Contents == e2
|
||||
}
|
||||
// TODO: Stop hard-coding these
|
||||
if gRunnable.Contents == "AdminOnly" && runnable.Contents == "MemberOnly" {
|
||||
if f("AdminOnly", "MemberOnly") {
|
||||
continue skipRunnable
|
||||
}
|
||||
if gRunnable.Contents == "AdminOnly" && runnable.Contents == "SuperModOnly" {
|
||||
if f("AdminOnly", "SuperModOnly") {
|
||||
continue skipRunnable
|
||||
}
|
||||
if gRunnable.Contents == "SuperModOnly" && runnable.Contents == "MemberOnly" {
|
||||
if f("SuperModOnly", "MemberOnly") {
|
||||
continue skipRunnable
|
||||
}
|
||||
}
|
||||
|
||||
if runnable.Literal {
|
||||
out += "\n\t\t\t\t\t" + runnable.Contents
|
||||
on(5, runnable.Contents)
|
||||
} else {
|
||||
out += `
|
||||
err = c.` + runnable.Contents + `(w,req,user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
`
|
||||
on(5, "err = c."+runnable.Contents+"(w,req,user)")
|
||||
iferrn(5)
|
||||
on(5, "")
|
||||
}
|
||||
}
|
||||
}
|
||||
if !route.Action && !route.NoHead && !group.NoHead {
|
||||
//out += "\n\t\t\t\th, err := c.UserCheck(w,req,user)"
|
||||
out += "\n\t\t\t\th, err := c.UserCheckNano(w,req,user,cn)"
|
||||
out += "\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}"
|
||||
vcpy := route.Vars
|
||||
route.Vars = []string{"h"}
|
||||
route.Vars = append(route.Vars, vcpy...)
|
||||
//on(5,"h, err := c.UserCheck(w,req,user)")
|
||||
userCheckNano(5, route)
|
||||
} else {
|
||||
//out += "\n\t\t\t\t\tcn := uutils.Nanotime()"
|
||||
//on(5, "cn := uutils.Nanotime()")
|
||||
}
|
||||
out += "\n\t\t\t\t\terr = " + strings.Replace(route.Name, "common.", "c.", -1) + "(w,req,user"
|
||||
for _, item := range route.Vars {
|
||||
out += "," + item
|
||||
}
|
||||
out += ")"
|
||||
writeRoute(5, route)
|
||||
/*if !route.Action && !route.NoHead && !group.NoHead {
|
||||
out += "\n\t\t\t\t\tco.RouteViewCounter.Bump2(" + strconv.Itoa(allRouteMap[route.Name]) + ", h.StartedAt)"
|
||||
on(5,"co.RouteViewCounter.Bump2(" + strconv.Itoa(allRouteMap[route.Name]) + ", h.StartedAt)")
|
||||
} else {*/
|
||||
//out += "\n\t\t\t\t\tco.RouteViewCounter.Bump(" + strconv.Itoa(allRouteMap[route.Name]) + ")"
|
||||
out += "\n\t\t\t\t\tco.RouteViewCounter.Bump3(" + strconv.Itoa(allRouteMap[route.Name]) + ", cn)"
|
||||
//on(5,"co.RouteViewCounter.Bump(" + strconv.Itoa(allRouteMap[route.Name]) + ")")
|
||||
on(5, "co.RouteViewCounter.Bump3("+strconv.Itoa(allRouteMap[route.Name])+", cn)")
|
||||
//}
|
||||
}
|
||||
|
||||
if defaultRoute.Name != "" {
|
||||
mapIt(defaultRoute.Name)
|
||||
out += "\n\t\t\t\tdefault:"
|
||||
//out += "\n\t\t\t\t\tid = " + strconv.Itoa(allRouteMap[defaultRoute.Name])
|
||||
on(4, "default:")
|
||||
//on(5,"id = " + strconv.Itoa(allRouteMap[defaultRoute.Name]))
|
||||
out += runBefore(defaultRoute.RunBefore, 4)
|
||||
if !defaultRoute.Action && !defaultRoute.NoHead && !group.NoHead {
|
||||
//out += "\n\t\t\t\t\th, err := c.UserCheck(w,req,user)"
|
||||
out += "\n\t\t\t\t\th, err := c.UserCheckNano(w,req,user,cn)"
|
||||
out += "\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn err\n\t\t\t\t\t}"
|
||||
vcpy := defaultRoute.Vars
|
||||
defaultRoute.Vars = []string{"h"}
|
||||
defaultRoute.Vars = append(defaultRoute.Vars, vcpy...)
|
||||
//on(5, "h, err := c.UserCheck(w,req,user)"
|
||||
userCheckNano(5, defaultRoute)
|
||||
}
|
||||
out += "\n\t\t\t\t\terr = " + strings.Replace(defaultRoute.Name, "common.", "c.", -1) + "(w,req,user"
|
||||
for _, item := range defaultRoute.Vars {
|
||||
out += ", " + item
|
||||
}
|
||||
out += ")"
|
||||
writeRoute(5, defaultRoute)
|
||||
/*if !defaultRoute.Action && !defaultRoute.NoHead && !group.NoHead {
|
||||
out += "\n\t\t\t\t\tco.RouteViewCounter.Bump2(" + strconv.Itoa(allRouteMap[defaultRoute.Name]) + ", h.StartedAt)"
|
||||
on(5,"co.RouteViewCounter.Bump2(" + strconv.Itoa(allRouteMap[defaultRoute.Name]) + ", h.StartedAt)")
|
||||
} else {*/
|
||||
//out += "\n\t\t\t\t\tco.RouteViewCounter.Bump(" + strconv.Itoa(allRouteMap[defaultRoute.Name]) + ")"
|
||||
out += "\n\t\t\tco.RouteViewCounter.Bump3(" + strconv.Itoa(allRouteMap[defaultRoute.Name]) + ", cn)"
|
||||
//on(5,co.RouteViewCounter.Bump(" + strconv.Itoa(allRouteMap[defaultRoute.Name]) + ")")
|
||||
on(5, "co.RouteViewCounter.Bump3("+strconv.Itoa(allRouteMap[defaultRoute.Name])+", cn)")
|
||||
//}
|
||||
}
|
||||
out += `
|
||||
}`
|
||||
on(3, "}")
|
||||
}
|
||||
|
||||
// Stubs for us to refer to these routes through
|
||||
|
@ -184,6 +184,7 @@ func accountRoutes() *RouteGroup {
|
||||
}
|
||||
|
||||
func panelRoutes() *RouteGroup {
|
||||
// TODO: Implement subgroups
|
||||
return newRouteGroup("/panel/").Before("SuperModOnly").NoHeader().Routes(
|
||||
View("panel.Dashboard", "/panel/"),
|
||||
//View("panel.StatsDisk", "/panel/stats/disk/"),
|
||||
|
Loading…
Reference in New Issue
Block a user