add base url

This commit is contained in:
Alireza Ahmadi
2024-02-26 19:01:01 +01:00
parent 30c9ed6aa7
commit c54d9c15bc
16 changed files with 80 additions and 30 deletions
+26
View File
@@ -21,6 +21,7 @@ var defaultValueMap = map[string]string{
"webSecret": common.Random(32),
"webCertFile": "",
"webKeyFile": "",
"webPath": "/app/",
"sessionMaxAge": "0",
"timeLocation": "Asia/Tehran",
"subListen": "",
@@ -158,6 +159,20 @@ func (s *SettingService) GetKeyFile() (string, error) {
return s.getString("webKeyFile")
}
func (s *SettingService) GetWebPath() (string, error) {
webPath, err := s.getString("webPath")
if err != nil {
return "", err
}
if !strings.HasPrefix(webPath, "/") {
webPath = "/" + webPath
}
if !strings.HasSuffix(webPath, "/") {
webPath += "/"
}
return webPath, nil
}
func (s *SettingService) GetSecret() ([]byte, error) {
secret, err := s.getString("webSecret")
if secret == defaultValueMap["webSecret"] {
@@ -278,6 +293,17 @@ func (s *SettingService) Save(tx *gorm.DB, changes []model.Changes) error {
}
}
// Correct Pathes start and ends with `/`
if key == "webPath" ||
key == "subPath" {
if !strings.HasPrefix(obj, "/") {
obj = "/" + obj
}
if !strings.HasSuffix(obj, "/") {
obj += "/"
}
}
err = tx.Model(model.Setting{}).Where("key = ?", key).Update("value", obj).Error
if err != nil {
return err