2020-08-21 21:09:42 +08:00
|
|
|
package locations
|
|
|
|
|
|
|
|
|
|
import (
|
2021-05-10 21:13:09 +08:00
|
|
|
"encoding/json"
|
2020-08-21 21:09:42 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
2021-01-03 20:25:15 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
|
2021-05-10 21:13:09 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
|
|
|
|
"github.com/iwind/TeaGo/maps"
|
|
|
|
|
"strings"
|
2020-08-21 21:09:42 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type IndexAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) Init() {
|
|
|
|
|
this.Nav("", "setting", "index")
|
|
|
|
|
this.SecondMenu("locations")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) RunGet(params struct {
|
|
|
|
|
ServerId int64
|
|
|
|
|
}) {
|
2021-01-03 20:25:15 +08:00
|
|
|
webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId)
|
2020-09-21 19:51:50 +08:00
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.Data["webId"] = webConfig.Id
|
|
|
|
|
|
2023-07-17 15:30:19 +08:00
|
|
|
var locationMaps = []maps.Map{}
|
2020-09-21 19:51:50 +08:00
|
|
|
if webConfig.Locations != nil {
|
2021-05-10 21:13:09 +08:00
|
|
|
for _, location := range webConfig.Locations {
|
|
|
|
|
err := location.ExtractPattern()
|
|
|
|
|
if err != nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
jsonData, err := json.Marshal(location)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
m := maps.Map{}
|
|
|
|
|
err = json.Unmarshal(jsonData, &m)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-07-17 15:30:19 +08:00
|
|
|
var pieces = strings.Split(location.Pattern, " ")
|
2021-05-10 21:13:09 +08:00
|
|
|
if len(pieces) == 2 {
|
|
|
|
|
m["pattern"] = pieces[1]
|
|
|
|
|
m["patternTypeName"] = serverconfigs.FindLocationPatternTypeName(location.PatternType())
|
|
|
|
|
} else {
|
|
|
|
|
m["pattern"] = location.Pattern
|
|
|
|
|
m["patternTypeName"] = serverconfigs.FindLocationPatternTypeName(serverconfigs.HTTPLocationPatternTypePrefix)
|
|
|
|
|
}
|
|
|
|
|
locationMaps = append(locationMaps, m)
|
|
|
|
|
}
|
2020-09-21 19:51:50 +08:00
|
|
|
}
|
2021-05-10 21:13:09 +08:00
|
|
|
this.Data["locations"] = locationMaps
|
2020-08-21 21:09:42 +08:00
|
|
|
|
|
|
|
|
this.Show()
|
|
|
|
|
}
|