Skip to content

Commit 4cb8e58

Browse files
committed
Merge remote-tracking branch 'origin/main' into meta
2 parents d48615a + a6bfd40 commit 4cb8e58

15 files changed

Lines changed: 174 additions & 17 deletions

File tree

cmd/wire_gen.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

i18n/cs_CZ.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ backend:
5858
undelete:
5959
other: Obnovit
6060
merge:
61-
other:
61+
other: Sloučit
6262
role:
6363
name:
6464
user:

i18n/id_ID.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ backend:
110110
rank_invite_someone_to_answer_label:
111111
other: Undang seseorang untuk menjawab
112112
rank_tag_add_label:
113-
other:
113+
other: Buat tag baru
114114
rank_tag_edit_label:
115115
other: Edit tag description (need to review)
116116
rank_question_edit_label:
@@ -132,7 +132,7 @@ backend:
132132
rank_tag_synonym_label:
133133
other: Manage tag synonyms
134134
email:
135-
other:
135+
other: Email
136136
e_mail:
137137
other: Email
138138
password:

i18n/ru_RU.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ backend:
5858
undelete:
5959
other: Отменить удаление
6060
merge:
61-
other:
61+
other: Объединить
6262
role:
6363
name:
6464
user:
@@ -701,7 +701,7 @@ backend:
701701
other: Активный участник на год, опубликовал по крайней мере один раз.
702702
appreciated:
703703
name:
704-
other:
704+
other: Appreciated
705705
desc:
706706
other: Received 1 up vote on 20 posts.
707707
respected:
@@ -1454,7 +1454,7 @@ ui:
14541454
content: Are you sure you want to list?
14551455
unlist:
14561456
confirm_btn: Убрать из списка
1457-
title:
1457+
title: Unlist this post
14581458
content: Are you sure you want to unlist?
14591459
pin:
14601460
title: Закрепить сообщение
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package middleware
21+
22+
import (
23+
"github.com/apache/answer/internal/base/handler"
24+
"github.com/apache/answer/internal/base/reason"
25+
"github.com/gin-gonic/gin"
26+
"github.com/segmentfault/pacman/errors"
27+
)
28+
29+
// AuthAPIKey middleware to authenticate API key
30+
func (am *AuthUserMiddleware) AuthAPIKey() gin.HandlerFunc {
31+
return func(ctx *gin.Context) {
32+
token := ExtractToken(ctx)
33+
if len(token) == 0 {
34+
handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil)
35+
ctx.Abort()
36+
return
37+
}
38+
pass, err := am.authService.AuthAPIKey(ctx, ctx.Request.Method == "GET", token)
39+
if err != nil {
40+
handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil)
41+
ctx.Abort()
42+
return
43+
}
44+
if !pass {
45+
handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil)
46+
ctx.Abort()
47+
return
48+
}
49+
ctx.Next()
50+
}
51+
}

internal/base/server/http.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,10 @@ func NewHTTPServer(debug bool,
113113
agent.RegisterAuthAdminRouter(adminauthV1)
114114
return nil
115115
})
116+
117+
// mcp
118+
mcpAPIGroup := r.Group(uiConf.APIBaseURL + "/answer/api/v1")
119+
mcpAPIGroup.Use(authUserMiddleware.AuthMcpEnable(), authUserMiddleware.AuthAPIKey())
120+
answerRouter.RegisterMCPRouter(mcpAPIGroup)
116121
return r
117122
}

internal/cli/reset_password.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/apache/answer/internal/base/conf"
3333
"github.com/apache/answer/internal/base/data"
3434
"github.com/apache/answer/internal/base/path"
35+
"github.com/apache/answer/internal/repo/api_key"
3536
"github.com/apache/answer/internal/repo/auth"
3637
"github.com/apache/answer/internal/repo/user"
3738
authService "github.com/apache/answer/internal/service/auth"
@@ -95,7 +96,8 @@ func ResetPassword(ctx context.Context, dataDirPath string, opts *ResetPasswordO
9596

9697
userRepo := user.NewUserRepo(dataData)
9798
authRepo := auth.NewAuthRepo(dataData)
98-
authSvc := authService.NewAuthService(authRepo)
99+
apiKeyRepo := api_key.NewAPIKeyRepo(dataData)
100+
authSvc := authService.NewAuthService(authRepo, apiKeyRepo)
99101

100102
email := strings.TrimSpace(opts.Email)
101103
if email == "" {

internal/migrations/init.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ func (m *Mentor) InitDB() error {
8787
m.do("init site info security", m.initSiteInfoSecurityConfig)
8888
m.do("init default content", m.initDefaultContent)
8989
m.do("init default badges", m.initDefaultBadges)
90+
m.do("init default ai config", m.initSiteInfoAI)
91+
m.do("init default MCP config", m.initSiteInfoMCP)
9092
return m.err
9193
}
9294

@@ -606,3 +608,29 @@ func (m *Mentor) initDefaultBadges() {
606608
}
607609
}
608610
}
611+
612+
func (m *Mentor) initSiteInfoAI() {
613+
content := &schema.SiteAIReq{
614+
PromptConfig: &schema.AIPromptConfig{
615+
ZhCN: constant.DefaultAIPromptConfigZhCN,
616+
EnUS: constant.DefaultAIPromptConfigEnUS,
617+
},
618+
}
619+
writeDataBytes, _ := json.Marshal(content)
620+
_, m.err = m.engine.Context(m.ctx).Insert(&entity.SiteInfo{
621+
Type: constant.SiteTypeAI,
622+
Content: string(writeDataBytes),
623+
Status: 1,
624+
})
625+
}
626+
func (m *Mentor) initSiteInfoMCP() {
627+
content := &schema.SiteMCPReq{
628+
Enabled: true,
629+
}
630+
writeDataBytes, _ := json.Marshal(content)
631+
_, m.err = m.engine.Context(m.ctx).Insert(&entity.SiteInfo{
632+
Type: constant.SiteTypeMCP,
633+
Content: string(writeDataBytes),
634+
Status: 1,
635+
})
636+
}

internal/migrations/init_data.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ var (
7676
&entity.BadgeAward{},
7777
&entity.FileRecord{},
7878
&entity.PluginKVStorage{},
79+
&entity.APIKey{},
80+
&entity.AIConversation{},
81+
&entity.AIConversationRecord{},
7982
}
8083

8184
roles = []*entity.Role{
@@ -350,6 +353,7 @@ var (
350353
{ID: 128, Key: "rank.answer.undeleted", Value: `-1`},
351354
{ID: 129, Key: "rank.question.undeleted", Value: `-1`},
352355
{ID: 130, Key: "rank.tag.undeleted", Value: `-1`},
356+
{ID: 131, Key: "ai_config.provider", Value: `[{"default_api_host":"https://api.openai.com","display_name":"OpenAI","name":"openai"},{"default_api_host":"https://generativelanguage.googleapis.com","display_name":"Gemini","name":"gemini"},{"default_api_host":"https://api.anthropic.com","display_name":"Anthropic","name":"anthropic"}]`},
353357
}
354358

355359
defaultBadgeGroupTable = []*entity.BadgeGroup{

internal/migrations/v31.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func addAPIKey(ctx context.Context, x *xorm.Engine) error {
6161
}
6262

6363
defaultConfigTable := []*entity.Config{
64-
{ID: 10000, Key: "ai_config.provider", Value: `[{"default_api_host":"https://api.openai.com","display_name":"OpenAI","name":"openai"},{"default_api_host":"https://generativelanguage.googleapis.com","display_name":"Gemini","name":"gemini"},{"default_api_host":"https://api.anthropic.com","display_name":"Anthropic","name":"anthropic"}]`},
64+
{ID: 131, Key: "ai_config.provider", Value: `[{"default_api_host":"https://api.openai.com","display_name":"OpenAI","name":"openai"},{"default_api_host":"https://generativelanguage.googleapis.com","display_name":"Gemini","name":"gemini"},{"default_api_host":"https://api.anthropic.com","display_name":"Anthropic","name":"anthropic"}]`},
6565
}
6666
for _, c := range defaultConfigTable {
6767
exist, err := x.Context(ctx).Get(&entity.Config{Key: c.Key})

0 commit comments

Comments
 (0)