Skip to content

Commit 3972d48

Browse files
committed
Merge branch 'test' of github.com:apache/answer into test
2 parents 82b1211 + 849ad8d commit 3972d48

File tree

12 files changed

+341
-27
lines changed

12 files changed

+341
-27
lines changed

configs/config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ data:
2424
connection: "/data/sqlite3/answer.db"
2525
cache:
2626
file_path: "/data/cache/cache.db"
27+
ssl:
28+
enabled: "no"
29+
mode: "require"
30+
cert_file: "/data/cache/ssl/certs/server-ca.pem"
31+
key_file: "/data/cache/ssl/certs/client-cert.pem"
32+
pem_file: "/data/cache/ssl/certs/client-key.pem"
2733
i18n:
2834
bundle_dir: "/data/i18n"
2935
swaggerui:

i18n/en_US.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,23 @@ ui:
16551655
label: Database file
16561656
placeholder: /data/answer.db
16571657
msg: Database file cannot be empty.
1658+
ssl_enabled:
1659+
label: Enable SSL
1660+
ssl_enabled_on:
1661+
label: On
1662+
ssl_enabled_off:
1663+
label: Off
1664+
ssl_mode:
1665+
label: SSL Mode
1666+
key_file:
1667+
placeholder: Key file path
1668+
msg: Path to Key file cannot be empty
1669+
cert_file:
1670+
placeholder: Cert file path
1671+
msg: Path to Cert file cannot be empty
1672+
pem_file:
1673+
placeholder: Pem file path
1674+
msg: Path to Pem file cannot be empty
16581675
config_yaml:
16591676
title: Create config.yaml
16601677
label: The config.yaml file created.

i18n/zh_CN.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,23 @@ ui:
16191619
label: 数据库文件
16201620
placeholder: /data/answer.db
16211621
msg: 数据库文件不能为空。
1622+
ssl_enabled:
1623+
label: 使能够 SSL
1624+
ssl_enabled_on:
1625+
label:
1626+
ssl_enabled_off:
1627+
label:
1628+
ssl_mode:
1629+
label: SSL 模式
1630+
key_file:
1631+
placeholder: Key 文件路径
1632+
msg: 文件路径不能为空
1633+
cert_file:
1634+
placeholder: Cert 文件路径
1635+
msg: 文件路径不能为空
1636+
pem_file:
1637+
placeholder: Pem 文件路径
1638+
msg: 文件路径不能为空
16221639
config_yaml:
16231640
title: 创建 config.yaml
16241641
label: 已创建 config.yaml 文件。

internal/cli/build.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func BuildNewAnswer(buildDir, outputPath string, plugins []string, originalAnswe
125125
builder := newAnswerBuilder(buildDir, outputPath, plugins, originalAnswerInfo)
126126
builder.DoTask(createMainGoFile)
127127
builder.DoTask(downloadGoModFile)
128+
builder.DoTask(movePluginToVendor)
128129
builder.DoTask(copyUIFiles)
129130
builder.DoTask(buildUI)
130131
builder.DoTask(mergeI18nFiles)
@@ -221,6 +222,24 @@ func downloadGoModFile(b *buildingMaterial) (err error) {
221222
return
222223
}
223224

225+
// movePluginToVendor move plugin to vendor dir
226+
// Traverse the plugins, and if the plugin path is not github.com/apache/answer-plugins, move the contents of the current plugin to the vendor/github.com/apache/answer-plugins/ directory.
227+
func movePluginToVendor(b *buildingMaterial) (err error) {
228+
pluginsDir := filepath.Join(b.tmpDir, "vendor/github.com/apache/answer-plugins/")
229+
for _, p := range b.plugins {
230+
pluginDir := filepath.Join(b.tmpDir, "vendor/", p.Name)
231+
pluginName := filepath.Base(p.Name)
232+
if !strings.HasPrefix(p.Name, "github.com/apache/answer-plugins/") {
233+
fmt.Printf("try to copy dir from %s to %s\n", pluginDir, filepath.Join(pluginsDir, pluginName))
234+
err = copyDirEntries(os.DirFS(pluginDir), ".", filepath.Join(pluginsDir, pluginName), "node_modules")
235+
if err != nil {
236+
return err
237+
}
238+
}
239+
}
240+
return nil
241+
}
242+
224243
// copyUIFiles copy ui files from answer module to tmp dir
225244
func copyUIFiles(b *buildingMaterial) (err error) {
226245
goListCmd := b.newExecCmd("go", "list", "-mod=mod", "-m", "-f", "{{.Dir}}", "github.com/apache/answer")

internal/install/install_req.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ import (
2727
"github.com/apache/answer/internal/base/reason"
2828
"github.com/apache/answer/internal/base/validator"
2929
"github.com/apache/answer/pkg/checker"
30+
"github.com/apache/answer/pkg/dir"
3031
"github.com/segmentfault/pacman/errors"
32+
"github.com/segmentfault/pacman/log"
3133
"xorm.io/xorm/schemas"
3234
)
3335

@@ -40,12 +42,17 @@ type CheckConfigFileResp struct {
4042

4143
// CheckDatabaseReq check database
4244
type CheckDatabaseReq struct {
43-
DbType string `validate:"required,oneof=postgres sqlite3 mysql" json:"db_type"`
44-
DbUsername string `json:"db_username"`
45-
DbPassword string `json:"db_password"`
46-
DbHost string `json:"db_host"`
47-
DbName string `json:"db_name"`
48-
DbFile string `json:"db_file"`
45+
DbType string `validate:"required,oneof=postgres sqlite3 mysql" json:"db_type"`
46+
DbUsername string `json:"db_username"`
47+
DbPassword string `json:"db_password"`
48+
DbHost string `json:"db_host"`
49+
DbName string `json:"db_name"`
50+
DbFile string `json:"db_file"`
51+
Ssl bool `json:"ssl_enabled"`
52+
SslMode string `json:"ssl_mode"`
53+
SslCrt string `json:"pem_file"`
54+
SslKey string `json:"key_file"`
55+
SslCrtClient string `json:"cert_file"`
4956
}
5057

5158
// GetConnection get connection string
@@ -59,8 +66,25 @@ func (r *CheckDatabaseReq) GetConnection() string {
5966
}
6067
if r.DbType == string(schemas.POSTGRES) {
6168
host, port := parsePgSQLHostPort(r.DbHost)
62-
return fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable",
63-
host, port, r.DbUsername, r.DbPassword, r.DbName)
69+
if !r.Ssl {
70+
return fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable",
71+
host, port, r.DbUsername, r.DbPassword, r.DbName)
72+
} else if r.SslMode == "require" {
73+
return fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s",
74+
host, port, r.DbUsername, r.DbPassword, r.DbName, r.SslMode)
75+
} else if r.SslMode == "verify-ca" || r.SslMode == "verify-full" {
76+
if dir.CheckFileExist(r.SslCrt) {
77+
log.Warnf("ssl crt file not exist: %s", r.SslCrt)
78+
}
79+
if dir.CheckFileExist(r.SslCrtClient) {
80+
log.Warnf("ssl crt client file not exist: %s", r.SslCrtClient)
81+
}
82+
if dir.CheckFileExist(r.SslKey) {
83+
log.Warnf("ssl key file not exist: %s", r.SslKey)
84+
}
85+
return fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s sslrootcert=%s sslcert=%s sslkey=%s",
86+
host, port, r.DbUsername, r.DbPassword, r.DbName, r.SslMode, r.SslCrt, r.SslCrtClient, r.SslKey)
87+
}
6488
}
6589
return ""
6690
}

internal/repo/question/question_repo.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,10 @@ func (qr *questionRepo) GetQuestionPage(ctx context.Context, page, pageSize int,
397397
questionList []*entity.Question, total int64, err error) {
398398
questionList = make([]*entity.Question, 0)
399399
session := qr.data.DB.Context(ctx)
400-
status := []int{entity.QuestionStatusAvailable, entity.QuestionStatusClosed}
400+
status := []int{entity.QuestionStatusAvailable}
401+
if orderCond != "unanswered" {
402+
status = append(status, entity.QuestionStatusClosed)
403+
}
401404
if showPending {
402405
status = append(status, entity.QuestionStatusPending)
403406
}

internal/schema/question_schema.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ const (
377377
QuestionOrderCondScore = "score"
378378
QuestionOrderCondUnanswered = "unanswered"
379379
QuestionOrderCondRecommend = "recommend"
380+
QuestionOrderCondFrequent = "frequent"
380381

381382
// HotInDays limit max days of the hottest question
382383
HotInDays = 90

internal/service/content/question_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ func (qs *QuestionService) GetRecommendQuestionPage(ctx context.Context, req *sc
14641464
return nil, 0, err
14651465
}
14661466

1467-
questions, err = qs.questioncommon.FormatQuestionsPage(ctx, questionList, req.LoginUserID, "frequent")
1467+
questions, err = qs.questioncommon.FormatQuestionsPage(ctx, questionList, req.LoginUserID, schema.QuestionOrderCondFrequent)
14681468
if err != nil {
14691469
return nil, 0, err
14701470
}

internal/service/question_common/question.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -410,19 +410,18 @@ func (qs *QuestionCommon) FormatQuestionsPage(
410410
}
411411
}
412412

413-
// if order condition is newest or nobody edited or nobody answered, only show question author
414-
if orderCond == schema.QuestionOrderCondNewest || (!haveEdited && !haveAnswered) {
415-
t.OperationType = schema.QuestionPageRespOperationTypeAsked
416-
t.OperatedAt = questionInfo.CreatedAt.Unix()
417-
t.Operator = &schema.QuestionPageRespOperator{ID: questionInfo.UserID}
418-
} else {
419-
// if no one
413+
// The default operation is to ask questions
414+
t.OperationType = schema.QuestionPageRespOperationTypeAsked
415+
t.OperatedAt = questionInfo.CreatedAt.Unix()
416+
t.Operator = &schema.QuestionPageRespOperator{ID: questionInfo.UserID}
417+
418+
// If the order is active, the last operation time is the last edit or answer time if it exists
419+
if orderCond == schema.QuestionOrderCondActive {
420420
if haveEdited {
421421
t.OperationType = schema.QuestionPageRespOperationTypeModified
422422
t.OperatedAt = questionInfo.UpdatedAt.Unix()
423423
t.Operator = &schema.QuestionPageRespOperator{ID: questionInfo.LastEditUserID}
424424
}
425-
426425
if haveAnswered {
427426
if t.LastAnsweredAt.Unix() > t.OperatedAt {
428427
t.OperationType = schema.QuestionPageRespOperationTypeAnswered
@@ -431,6 +430,7 @@ func (qs *QuestionCommon) FormatQuestionsPage(
431430
}
432431
}
433432
}
433+
434434
formattedQuestions = append(formattedQuestions, t)
435435
}
436436

pkg/converter/markdown.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040
// Markdown2HTML convert markdown to html
4141
func Markdown2HTML(source string) string {
4242
mdConverter := goldmark.New(
43-
goldmark.WithExtensions(&DangerousHTMLFilterExtension{}, extension.GFM),
43+
goldmark.WithExtensions(&DangerousHTMLFilterExtension{}, extension.GFM, extension.Footnote),
4444
goldmark.WithParserOptions(
4545
parser.WithAutoHeadingID(),
4646
),

0 commit comments

Comments
 (0)