mirror of https://gitee.com/answerdev/answer.git
feat(agent): add site info url for agent
This commit is contained in:
parent
ba475ddfbb
commit
3952439d49
|
@ -1,5 +1,6 @@
|
|||
package constant
|
||||
|
||||
var (
|
||||
DefaultAvatar = "system"
|
||||
DefaultAvatar = "system"
|
||||
DefaultSiteURL = ""
|
||||
)
|
||||
|
|
|
@ -36,12 +36,15 @@ func NewSiteInfoService(
|
|||
tagCommonService *tagcommon.TagCommonService,
|
||||
configRepo config.ConfigRepo,
|
||||
) *SiteInfoService {
|
||||
resp, err := siteInfoCommonService.GetSiteUsers(context.Background())
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
} else {
|
||||
constant.DefaultAvatar = resp.DefaultAvatar
|
||||
usersSiteInfo, _ := siteInfoCommonService.GetSiteUsers(context.Background())
|
||||
if usersSiteInfo != nil {
|
||||
constant.DefaultAvatar = usersSiteInfo.DefaultAvatar
|
||||
}
|
||||
generalSiteInfo, _ := siteInfoCommonService.GetSiteGeneral(context.Background())
|
||||
if generalSiteInfo != nil {
|
||||
constant.DefaultSiteURL = generalSiteInfo.SiteUrl
|
||||
}
|
||||
|
||||
return &SiteInfoService{
|
||||
siteInfoRepo: siteInfoRepo,
|
||||
siteInfoCommonService: siteInfoCommonService,
|
||||
|
@ -116,18 +119,16 @@ func (s *SiteInfoService) GetSiteTheme(ctx context.Context) (resp *schema.SiteTh
|
|||
|
||||
func (s *SiteInfoService) SaveSiteGeneral(ctx context.Context, req schema.SiteGeneralReq) (err error) {
|
||||
req.FormatSiteUrl()
|
||||
var (
|
||||
siteType = "general"
|
||||
content []byte
|
||||
)
|
||||
content, _ = json.Marshal(req)
|
||||
|
||||
data := entity.SiteInfo{
|
||||
Type: siteType,
|
||||
content, _ := json.Marshal(req)
|
||||
data := &entity.SiteInfo{
|
||||
Type: constant.SiteTypeGeneral,
|
||||
Content: string(content),
|
||||
Status: 1,
|
||||
}
|
||||
err = s.siteInfoRepo.SaveByType(ctx, constant.SiteTypeGeneral, data)
|
||||
if err == nil {
|
||||
constant.DefaultSiteURL = req.SiteUrl
|
||||
}
|
||||
|
||||
err = s.siteInfoRepo.SaveByType(ctx, siteType, &data)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"github.com/answerdev/answer/internal/base/constant"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
|
@ -15,3 +16,9 @@ var (
|
|||
CallAgent,
|
||||
registerAgent = MakePlugin[Agent](true)
|
||||
)
|
||||
|
||||
// SiteURL The site url is the domain address of the current site. e.g. http://localhost:8080
|
||||
// When some Agent plugins want to redirect to the origin site, it can use this function to get the site url.
|
||||
func SiteURL() string {
|
||||
return constant.DefaultSiteURL
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue