mirror of https://gitee.com/answerdev/answer.git
fix(template): fix incorrect answer id
This commit is contained in:
parent
0bd540661c
commit
2ffcf2bf4b
|
@ -161,35 +161,41 @@ func (tc *TemplateController) QuestionList(ctx *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tc *TemplateController) QuestionInfoeRdirect(ctx *gin.Context, siteInfo *schema.TemplateSiteInfoResp, correctTitle bool) (jump bool, url string) {
|
func (tc *TemplateController) QuestionInfoeRdirect(ctx *gin.Context, siteInfo *schema.TemplateSiteInfoResp, correctTitle bool) (jump bool, url string) {
|
||||||
id := ctx.Param("id")
|
questionID := ctx.Param("id")
|
||||||
title := ctx.Param("title")
|
title := ctx.Param("title")
|
||||||
|
answerID := uid.DeShortID(title)
|
||||||
titleIsAnswerID := false
|
titleIsAnswerID := false
|
||||||
needChangeShortID := false
|
needChangeShortID := false
|
||||||
|
|
||||||
|
objectType, err := obj.GetObjectTypeStrByObjectID(answerID)
|
||||||
|
if err == nil && objectType == constant.AnswerObjectType {
|
||||||
|
titleIsAnswerID = true
|
||||||
|
}
|
||||||
|
|
||||||
siteSeo, err := tc.siteInfoService.GetSiteSeo(ctx)
|
siteSeo, err := tc.siteInfoService.GetSiteSeo(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, ""
|
return false, ""
|
||||||
}
|
}
|
||||||
isShortID := uid.IsShortID(id)
|
isShortID := uid.IsShortID(questionID)
|
||||||
if siteSeo.IsShortLink() {
|
if siteSeo.IsShortLink() {
|
||||||
if !isShortID {
|
if !isShortID {
|
||||||
id = uid.EnShortID(id)
|
questionID = uid.EnShortID(questionID)
|
||||||
needChangeShortID = true
|
needChangeShortID = true
|
||||||
}
|
}
|
||||||
|
if titleIsAnswerID {
|
||||||
|
answerID = uid.EnShortID(answerID)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if isShortID {
|
if isShortID {
|
||||||
needChangeShortID = true
|
needChangeShortID = true
|
||||||
id = uid.DeShortID(id)
|
questionID = uid.DeShortID(questionID)
|
||||||
|
}
|
||||||
|
if titleIsAnswerID {
|
||||||
|
answerID = uid.DeShortID(answerID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
objectType, objectTypeerr := obj.GetObjectTypeStrByObjectID(uid.DeShortID(title))
|
url = fmt.Sprintf("%s/questions/%s", siteInfo.General.SiteUrl, questionID)
|
||||||
if objectTypeerr == nil {
|
|
||||||
if objectType == constant.AnswerObjectType {
|
|
||||||
titleIsAnswerID = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
url = fmt.Sprintf("%s/questions/%s", siteInfo.General.SiteUrl, id)
|
|
||||||
if siteInfo.SiteSeo.PermaLink == constant.PermaLinkQuestionID || siteInfo.SiteSeo.PermaLink == constant.PermaLinkQuestionIDByShortID {
|
if siteInfo.SiteSeo.PermaLink == constant.PermaLinkQuestionID || siteInfo.SiteSeo.PermaLink == constant.PermaLinkQuestionIDByShortID {
|
||||||
if len(ctx.Request.URL.Query()) > 0 {
|
if len(ctx.Request.URL.Query()) > 0 {
|
||||||
url = fmt.Sprintf("%s?%s", url, ctx.Request.URL.RawQuery)
|
url = fmt.Sprintf("%s?%s", url, ctx.Request.URL.RawQuery)
|
||||||
|
@ -205,14 +211,14 @@ func (tc *TemplateController) QuestionInfoeRdirect(ctx *gin.Context, siteInfo *s
|
||||||
return true, url
|
return true, url
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
detail, err := tc.templateRenderController.QuestionDetail(ctx, id)
|
detail, err := tc.templateRenderController.QuestionDetail(ctx, questionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tc.Page404(ctx)
|
tc.Page404(ctx)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
url = fmt.Sprintf("%s/%s", url, htmltext.UrlTitle(detail.Title))
|
url = fmt.Sprintf("%s/%s", url, htmltext.UrlTitle(detail.Title))
|
||||||
if titleIsAnswerID {
|
if titleIsAnswerID {
|
||||||
url = fmt.Sprintf("%s/%s", url, title)
|
url = fmt.Sprintf("%s/%s", url, answerID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(ctx.Request.URL.Query()) > 0 {
|
if len(ctx.Request.URL.Query()) > 0 {
|
||||||
|
|
Loading…
Reference in New Issue