mirror of https://gitee.com/answerdev/answer.git
feat: change site url from config file to database
This commit is contained in:
parent
38c8f80849
commit
9509a9a964
|
@ -156,12 +156,6 @@ func InitBaseInfo(ctx *gin.Context) {
|
|||
handler.HandleResponse(ctx, errors.BadRequest(reason.ReadConfigFailed), nil)
|
||||
return
|
||||
}
|
||||
c.ServiceConfig.WebHost = req.SiteURL
|
||||
if err := conf.RewriteConfig(confPath, c); err != nil {
|
||||
log.Errorf("rewrite config failed %s", err)
|
||||
handler.HandleResponse(ctx, errors.BadRequest(reason.ReadConfigFailed), nil)
|
||||
return
|
||||
}
|
||||
|
||||
err = migrations.UpdateInstallInfo(c.Data.Database, req.Language, req.SiteName, req.SiteURL, req.ContactEmail,
|
||||
req.AdminName, req.AdminPassword, req.AdminEmail)
|
||||
|
|
|
@ -2,6 +2,5 @@ package service_config
|
|||
|
||||
type ServiceConfig struct {
|
||||
SecretKey string `json:"secret_key" mapstructure:"secret_key" yaml:"secret_key"`
|
||||
WebHost string `json:"web_host" mapstructure:"web_host" yaml:"web_host"`
|
||||
UploadPath string `json:"upload_path" mapstructure:"upload_path" yaml:"upload_path"`
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
|
||||
"github.com/answerdev/answer/internal/base/reason"
|
||||
"github.com/answerdev/answer/internal/service/service_config"
|
||||
"github.com/answerdev/answer/internal/service/siteinfo_common"
|
||||
"github.com/answerdev/answer/pkg/dir"
|
||||
"github.com/answerdev/answer/pkg/uid"
|
||||
"github.com/disintegration/imaging"
|
||||
|
@ -27,7 +28,8 @@ const (
|
|||
|
||||
// UploaderService user service
|
||||
type UploaderService struct {
|
||||
serviceConfig *service_config.ServiceConfig
|
||||
serviceConfig *service_config.ServiceConfig
|
||||
siteInfoService *siteinfo_common.SiteInfoCommonService
|
||||
}
|
||||
|
||||
// NewUploaderService new upload service
|
||||
|
@ -122,10 +124,14 @@ func (us *UploaderService) UploadPostFile(ctx *gin.Context, file *multipart.File
|
|||
|
||||
func (us *UploaderService) uploadFile(ctx *gin.Context, file *multipart.FileHeader, fileSubPath string) (
|
||||
url string, err error) {
|
||||
siteGeneral, err := us.siteInfoService.GetSiteGeneral(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
filePath := path.Join(us.serviceConfig.UploadPath, fileSubPath)
|
||||
if err := ctx.SaveUploadedFile(file, filePath); err != nil {
|
||||
return "", errors.InternalServer(reason.UnknownError).WithError(err).WithStack()
|
||||
}
|
||||
url = fmt.Sprintf("%s/uploads/%s", us.serviceConfig.WebHost, fileSubPath)
|
||||
url = fmt.Sprintf("%s/uploads/%s", siteGeneral.SiteUrl, fileSubPath)
|
||||
return url, nil
|
||||
}
|
||||
|
|
|
@ -144,7 +144,7 @@ func (us *UserService) RetrievePassWord(ctx context.Context, req *schema.UserRet
|
|||
UserID: userInfo.ID,
|
||||
}
|
||||
code := uuid.NewString()
|
||||
verifyEmailURL := fmt.Sprintf("%s/users/password-reset?code=%s", us.serviceConfig.WebHost, code)
|
||||
verifyEmailURL := fmt.Sprintf("%s/users/password-reset?code=%s", us.getSiteUrl(ctx), code)
|
||||
title, body, err := us.emailService.PassResetTemplate(ctx, verifyEmailURL)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -308,7 +308,7 @@ func (us *UserService) UserRegisterByEmail(ctx context.Context, registerUserInfo
|
|||
UserID: userInfo.ID,
|
||||
}
|
||||
code := uuid.NewString()
|
||||
verifyEmailURL := fmt.Sprintf("%s/users/account-activation?code=%s", us.serviceConfig.WebHost, code)
|
||||
verifyEmailURL := fmt.Sprintf("%s/users/account-activation?code=%s", us.getSiteUrl(ctx), code)
|
||||
title, body, err := us.emailService.RegisterTemplate(ctx, verifyEmailURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -351,7 +351,7 @@ func (us *UserService) UserVerifyEmailSend(ctx context.Context, userID string) e
|
|||
UserID: userInfo.ID,
|
||||
}
|
||||
code := uuid.NewString()
|
||||
verifyEmailURL := fmt.Sprintf("%s/users/account-activation?code=%s", us.serviceConfig.WebHost, code)
|
||||
verifyEmailURL := fmt.Sprintf("%s/users/account-activation?code=%s", us.getSiteUrl(ctx), code)
|
||||
title, body, err := us.emailService.RegisterTemplate(ctx, verifyEmailURL)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -500,7 +500,7 @@ func (us *UserService) UserChangeEmailSendCode(ctx context.Context, req *schema.
|
|||
}
|
||||
code := uuid.NewString()
|
||||
var title, body string
|
||||
verifyEmailURL := fmt.Sprintf("%s/users/confirm-new-email?code=%s", us.serviceConfig.WebHost, code)
|
||||
verifyEmailURL := fmt.Sprintf("%s/users/confirm-new-email?code=%s", us.getSiteUrl(ctx), code)
|
||||
if userInfo.MailStatus == entity.EmailStatusToBeVerified {
|
||||
title, body, err = us.emailService.RegisterTemplate(ctx, verifyEmailURL)
|
||||
} else {
|
||||
|
@ -548,3 +548,13 @@ func (us *UserService) UserChangeEmailVerify(ctx context.Context, content string
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// getSiteUrl get site url
|
||||
func (us *UserService) getSiteUrl(ctx context.Context) string {
|
||||
siteGeneral, err := us.siteInfoService.GetSiteGeneral(ctx)
|
||||
if err != nil {
|
||||
log.Errorf("get site general failed: %s", err)
|
||||
return ""
|
||||
}
|
||||
return siteGeneral.SiteUrl
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue