Fix link issue with forum redirects
This commit is contained in:
parent
a84ec79ee2
commit
c8373aae81
|
@ -292,7 +292,7 @@ func BuildProjectNew() string {
|
||||||
return Url("/projects/new", nil)
|
return Url("/projects/new", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
var RegexPersonalProject = regexp.MustCompile("^/p/(?P<projectid>[0-9]+)(/(?P<slug>[a-zA-Z0-9-]+))?")
|
var RegexPersonalProject = regexp.MustCompile("^/p/(?P<projectid>[0-9]+)(/(?P<projectslug>[a-zA-Z0-9-]+))?")
|
||||||
|
|
||||||
func BuildPersonalProject(id int, slug string) string {
|
func BuildPersonalProject(id int, slug string) string {
|
||||||
defer CatchPanic()
|
defer CatchPanic()
|
||||||
|
@ -452,7 +452,7 @@ func (c *UrlContext) BuildForumThreadWithPostHash(subforums []string, threadId i
|
||||||
defer CatchPanic()
|
defer CatchPanic()
|
||||||
builder := buildForumThreadPath(subforums, threadId, title, page)
|
builder := buildForumThreadPath(subforums, threadId, title, page)
|
||||||
|
|
||||||
return UrlWithFragment(builder.String(), nil, strconv.Itoa(postId))
|
return c.UrlWithFragment(builder.String(), nil, strconv.Itoa(postId))
|
||||||
}
|
}
|
||||||
|
|
||||||
var RegexForumPost = regexp.MustCompile(`^/forums(/(?P<subforums>[^\d/]+(/[^\d]+)*))?/t/(?P<threadid>\d+)/p/(?P<postid>\d+)$`)
|
var RegexForumPost = regexp.MustCompile(`^/forums(/(?P<subforums>[^\d/]+(/[^\d]+)*))?/t/(?P<threadid>\d+)/p/(?P<postid>\d+)$`)
|
||||||
|
|
|
@ -34,6 +34,14 @@ type Route struct {
|
||||||
Handler Handler
|
Handler Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Route) String() string {
|
||||||
|
var routeStrings []string
|
||||||
|
for _, regex := range r.Regexes {
|
||||||
|
routeStrings = append(routeStrings, regex.String())
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s %v", r.Method, routeStrings)
|
||||||
|
}
|
||||||
|
|
||||||
type RouteBuilder struct {
|
type RouteBuilder struct {
|
||||||
Router *Router
|
Router *Router
|
||||||
Prefixes []*regexp.Regexp
|
Prefixes []*regexp.Regexp
|
||||||
|
@ -107,6 +115,12 @@ nextroute:
|
||||||
if paramName == "" {
|
if paramName == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if _, alreadyExists := params[paramName]; alreadyExists {
|
||||||
|
logging.Warn().
|
||||||
|
Str("route", route.String()).
|
||||||
|
Str("paramName", paramName).
|
||||||
|
Msg("duplicate names for path parameters; last one wins")
|
||||||
|
}
|
||||||
params[paramName] = paramValue
|
params[paramName] = paramValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,13 +132,8 @@ nextroute:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var routeStrings []string
|
|
||||||
for _, regex := range route.Regexes {
|
|
||||||
routeStrings = append(routeStrings, regex.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
c := &RequestContext{
|
c := &RequestContext{
|
||||||
Route: fmt.Sprintf("%v", routeStrings),
|
Route: route.String(),
|
||||||
Logger: logging.GlobalLogger(),
|
Logger: logging.GlobalLogger(),
|
||||||
Req: req,
|
Req: req,
|
||||||
Res: rw,
|
Res: rw,
|
||||||
|
|
|
@ -307,7 +307,7 @@ func NewWebsiteRoutes(longRequestContext context.Context, conn *pgxpool.Pool, pe
|
||||||
return c.Redirect(c.UrlContext.RewriteProjectUrl(c.URL()), http.StatusSeeOther)
|
return c.Redirect(c.UrlContext.RewriteProjectUrl(c.URL()), http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.PathParams["slug"] != models.GeneratePersonalProjectSlug(p.Project.Name) {
|
if c.PathParams["projectslug"] != models.GeneratePersonalProjectSlug(p.Project.Name) {
|
||||||
return c.Redirect(c.UrlContext.RewriteProjectUrl(c.URL()), http.StatusSeeOther)
|
return c.Redirect(c.UrlContext.RewriteProjectUrl(c.URL()), http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue