Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

add path

aichy126bad5e855a094
diff --git a/cmd/answer/main.go b/cmd/answer/main.go
index cea99db9..0a88df84 100644
--- a/cmd/answer/main.go
+++ b/cmd/answer/main.go
@@ -45,6 +45,7 @@ func runApp() {
if err != nil {
panic(err)
}
+ conf.GetPathIgnoreList()
app, cleanup, err := initApplication(
c.Debug, c.Server, c.Data.Database, c.Data.Cache, c.I18n, c.Swaggerui, c.ServiceConfig, log.GetLogger())
if err != nil {
diff --git a/configs/config.go b/configs/config.go
index ca53c09b..3a7c32c2 100644
--- a/configs/config.go
+++ b/configs/config.go
@@ -4,4 +4,6 @@ import _ "embed"
//go:embed config.yaml
var Config []byte
+
+//go:embed path_ignore.yaml
var PathIgnore []byte
diff --git a/docs/docs.go b/docs/docs.go
index 868dbe0a..5d69dd2c 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -6400,11 +6400,7 @@ const docTemplate = `{
},
"user_info": {
"description": "user info",
- "allOf": [
- {
- "$ref": "#/definitions/schema.UserBasicInfo"
- }
- ]
+ "$ref": "#/definitions/schema.UserBasicInfo"
},
"vote_count": {
"type": "integer"
@@ -6416,11 +6412,7 @@ const docTemplate = `{
"properties": {
"object": {
"description": "this object",
- "allOf": [
- {
- "$ref": "#/definitions/schema.SearchObject"
- }
- ]
+ "$ref": "#/definitions/schema.SearchObject"
},
"object_type": {
"description": "object_type",
@@ -6818,11 +6810,7 @@ const docTemplate = `{
"properties": {
"avatar": {
"description": "avatar",
- "allOf": [
- {
- "$ref": "#/definitions/schema.AvatarInfo"
- }
- ]
+ "$ref": "#/definitions/schema.AvatarInfo"
},
"bio": {
"description": "bio",
diff --git a/docs/swagger.json b/docs/swagger.json
index e3d2f7fb..534cccc6 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -6388,11 +6388,7 @@
},
"user_info": {
"description": "user info",
- "allOf": [
- {
- "$ref": "#/definitions/schema.UserBasicInfo"
- }
- ]
+ "$ref": "#/definitions/schema.UserBasicInfo"
},
"vote_count": {
"type": "integer"
@@ -6404,11 +6400,7 @@
"properties": {
"object": {
"description": "this object",
- "allOf": [
- {
- "$ref": "#/definitions/schema.SearchObject"
- }
- ]
+ "$ref": "#/definitions/schema.SearchObject"
},
"object_type": {
"description": "object_type",
@@ -6806,11 +6798,7 @@
"properties": {
"avatar": {
"description": "avatar",
- "allOf": [
- {
- "$ref": "#/definitions/schema.AvatarInfo"
- }
- ]
+ "$ref": "#/definitions/schema.AvatarInfo"
},
"bio": {
"description": "bio",
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 45da2b7c..6ad1e87c 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -1139,8 +1139,7 @@ definitions:
title:
type: string
user_info:
- allOf:
- - $ref: '#/definitions/schema.UserBasicInfo'
+ $ref: '#/definitions/schema.UserBasicInfo'
description: user info
vote_count:
type: integer
@@ -1148,8 +1147,7 @@ definitions:
schema.SearchResp:
properties:
object:
- allOf:
- - $ref: '#/definitions/schema.SearchObject'
+ $ref: '#/definitions/schema.SearchObject'
description: this object
object_type:
description: object_type
@@ -1427,8 +1425,7 @@ definitions:
schema.UpdateInfoRequest:
properties:
avatar:
- allOf:
- - $ref: '#/definitions/schema.AvatarInfo'
+ $ref: '#/definitions/schema.AvatarInfo'
description: avatar
bio:
description: bio
diff --git a/internal/base/conf/conf.go b/internal/base/conf/conf.go
index 18a841d9..615405f1 100644
--- a/internal/base/conf/conf.go
+++ b/internal/base/conf/conf.go
@@ -4,6 +4,8 @@ import (
"bytes"
"path/filepath"
+ "github.com/answerdev/answer/configs"
+ "github.com/answerdev/answer/internal/base/constant"
"github.com/answerdev/answer/internal/base/data"
"github.com/answerdev/answer/internal/base/server"
"github.com/answerdev/answer/internal/base/translator"
@@ -12,6 +14,7 @@ import (
"github.com/answerdev/answer/internal/service/service_config"
"github.com/answerdev/answer/pkg/writer"
"github.com/segmentfault/pacman/contrib/conf/viper"
+ "github.com/segmentfault/pacman/log"
"gopkg.in/yaml.v3"
)
@@ -25,6 +28,10 @@ type AllConfig struct {
Swaggerui *router.SwaggerConfig `json:"swaggerui" mapstructure:"swaggerui" yaml:"swaggerui"`
}
+type PathIgnore struct {
+ Users []string `yaml:"users"`
+}
+
// Server server config
type Server struct {
HTTP *server.HTTP `json:"http" mapstructure:"http" yaml:"http"`
@@ -62,3 +69,18 @@ func RewriteConfig(configFilePath string, allConfig *AllConfig) error {
}
return writer.ReplaceFile(configFilePath, buf.String())
}
+
+func GetPathIgnoreList() map[string]bool {
+ list := make(map[string]bool, 0)
+ data := &PathIgnore{}
+ err := yaml.Unmarshal(configs.PathIgnore, data)
+ if err != nil {
+ log.Error(err)
+ return list
+ }
+ for _, item := range data.Users {
+ list[item] = true
+ }
+ constant.PathIgnoreMap = list
+ return list
+}
diff --git a/internal/base/constant/constant.go b/internal/base/constant/constant.go
index f7f2a9cc..40d7440e 100644
--- a/internal/base/constant/constant.go
+++ b/internal/base/constant/constant.go
@@ -30,6 +30,8 @@ const (
var (
Version string = ""
+ PathIgnoreMap map[string]bool
+
ObjectTypeStrMapping = map[string]int{
QuestionObjectType: 1,
AnswerObjectType: 2,
@@ -59,3 +61,11 @@ const (
SiteTypeLegal = "legal"
SiteTypeSeo = "seo"
)
+
+func ExistInPathIgnore(name string) bool {
+ _, ok := PathIgnoreMap[name]
+ if ok {
+ return true
+ }
+ return false
+}
diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.go
index 74ffe8d2..2918bf51 100644
--- a/internal/controller/template_controller.go
+++ b/internal/controller/template_controller.go
@@ -9,6 +9,7 @@ import (
"strings"
"time"
+ "github.com/answerdev/answer/internal/base/constant"
"github.com/answerdev/answer/internal/base/handler"
templaterender "github.com/answerdev/answer/internal/controller/template_render"
"github.com/answerdev/answer/internal/schema"
@@ -265,15 +266,23 @@ func (tc *TemplateController) TagInfo(ctx *gin.Context) {
// UserInfo user info
func (tc *TemplateController) UserInfo(ctx *gin.Context) {
- // urlPath := ctx.Request.URL.Path
- // filePath := ""
- // switch urlPath {
- // case "/users/login":
- // filePath = "build/index.html"
- // case "/users/register":
- // filePath = "build/index.html"
- // default:
username := ctx.Param("username")
+ if username == "" {
+ tc.Page404(ctx)
+ return
+ }
+ exist := constant.ExistInPathIgnore(username)
+ if exist {
+ file, err := ui.Build.ReadFile("build/index.html")
+ if err != nil {
+ log.Error(err)
+ tc.Page404(ctx)
+ return
+ }
+ ctx.Header("content-type", "text/html;charset=utf-8")
+ ctx.String(http.StatusOK, string(file))
+ return
+ }
req := &schema.GetOtherUserInfoByUsernameReq{}
req.Username = username
userinfo, err := tc.templateRenderController.UserInfo(ctx, req)
@@ -292,16 +301,6 @@ func (tc *TemplateController) UserInfo(ctx *gin.Context) {
"userinfo": userinfo,
"bio": template.HTML(userinfo.Info.BioHTML),
})
- // }
-
- // file, err := ui.Build.ReadFile(filePath)
- // if err != nil {
- // log.Error(err)
- // ctx.Status(http.StatusNotFound)
- // return
- // }
- // ctx.Header("content-type", "text/html;charset=utf-8")
- // ctx.String(http.StatusOK, string(file))
}
diff --git a/internal/router/template_router.go b/internal/router/template_router.go
index fbc48cdd..af108081 100644
--- a/internal/router/template_router.go
+++ b/internal/router/template_router.go
@@ -41,6 +41,6 @@ func (a *TemplateRouter) RegisterTemplateRouter(r *gin.RouterGroup) {
r.GET("/tags", a.templateController.TagList)
r.GET("/tags/:tag", a.templateController.TagInfo)
- // r.GET("/users/:username", a.templateController.UserInfo)
+ r.GET("/users/:username", a.templateController.UserInfo)
r.GET("/404", a.templateController.Page404)
}