mirror of https://gitee.com/answerdev/answer.git
add path
This commit is contained in:
parent
0ae6ddaa67
commit
bad5e855a0
|
@ -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 {
|
||||
|
|
|
@ -4,4 +4,6 @@ import _ "embed"
|
|||
|
||||
//go:embed config.yaml
|
||||
var Config []byte
|
||||
|
||||
//go:embed path_ignore.yaml
|
||||
var PathIgnore []byte
|
||||
|
|
18
docs/docs.go
18
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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue