gosora/router_gen/route_impl.go
Azareal 9a3d8425e0 Added the post counter and the associated Control Panel graph.
Renamed the pre_render_panel_analytics hook to pre_render_panel_analytics_views.
Added a details table to the route graphs.
Moved the /topic/ and /reply/ routes to the router generator and hardened them.
Made some of the route names more consistent.
We now track IPs in odd situations in debug mode.
Fixed a bug where people could post on non-existent profiles.

Continued work on topic move.
Added the postchunks table.
2018-01-14 12:03:20 +00:00

120 lines
2.8 KiB
Go

package main
type RouteImpl struct {
Name string
Path string
Vars []string
RunBefore []Runnable
Parent *RouteGroup
}
type Runnable struct {
Contents string
Literal bool
}
func addRoute(route *RouteImpl) {
routeList = append(routeList, route)
}
func (route *RouteImpl) Before(items ...string) *RouteImpl {
for _, item := range items {
route.RunBefore = append(route.RunBefore, Runnable{item, false})
}
return route
}
func (route *RouteImpl) LitBefore(items ...string) *RouteImpl {
for _, item := range items {
route.RunBefore = append(route.RunBefore, Runnable{item, true})
}
return route
}
func (route *RouteImpl) hasBefore(items ...string) bool {
for _, item := range items {
if route.hasBeforeItem(item) {
return true
}
}
return false
}
func (route *RouteImpl) hasBeforeItem(item string) bool {
for _, before := range route.RunBefore {
if before.Contents == item {
return true
}
}
return false
}
func addRouteGroup(routeGroup *RouteGroup) {
routeGroups = append(routeGroups, routeGroup)
}
func blankRoute() *RouteImpl {
return &RouteImpl{"", "", []string{}, []Runnable{}, nil}
}
func route(fname string, path string, args ...string) *RouteImpl {
return &RouteImpl{fname, path, args, []Runnable{}, nil}
}
func View(fname string, path string, args ...string) *RouteImpl {
return route(fname, path, args...)
}
func MemberView(fname string, path string, args ...string) *RouteImpl {
route := route(fname, path, args...)
if !route.hasBefore("SuperModOnly", "AdminOnly") {
route.Before("MemberOnly")
}
return route
}
func ModView(fname string, path string, args ...string) *RouteImpl {
route := route(fname, path, args...)
if !route.hasBefore("AdminOnly") {
route.Before("SuperModOnly")
}
return route
}
func Action(fname string, path string, args ...string) *RouteImpl {
route := route(fname, path, args...)
route.Before("NoSessionMismatch")
if !route.hasBefore("SuperModOnly", "AdminOnly") {
route.Before("MemberOnly")
}
return route
}
func AnonAction(fname string, path string, args ...string) *RouteImpl {
return route(fname, path, args...).Before("ParseForm")
}
// Make this it's own type to force the user to manipulate methods on it to set parameters
type uploadAction struct {
Route *RouteImpl
}
func UploadAction(fname string, path string, args ...string) *uploadAction {
route := route(fname, path, args...)
if !route.hasBefore("SuperModOnly", "AdminOnly") {
route.Before("MemberOnly")
}
return &uploadAction{route}
}
func (action *uploadAction) MaxSizeVar(varName string) *RouteImpl {
action.Route.LitBefore(`err = common.HandleUploadRoute(w,req,user,` + varName + `)
if err != nil {
router.handleError(err,w,req,user)
return
}`)
action.Route.Before("NoUploadSessionMismatch")
return action.Route
}