MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / getWebsiteDomains

Function getWebsiteDomains

agent/app/service/website_utils.go:1230–1289  ·  view source on GitHub ↗
(domains []request.WebsiteDomain, defaultHTTPPort, defaultHTTPsPort int, websiteID uint)

Source from the content-addressed store, hash-verified

1228}
1229
1230func getWebsiteDomains(domains []request.WebsiteDomain, defaultHTTPPort, defaultHTTPsPort int, websiteID uint) (domainModels []model.WebsiteDomain, addPorts []int, addDomains []string, err error) {
1231 var (
1232 ports = make(map[int]struct{})
1233 existPort = make(map[int]struct{})
1234 )
1235 existDomains, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithWebsiteId(websiteID))
1236 for _, domain := range existDomains {
1237 existPort[domain.Port] = struct{}{}
1238 }
1239 for _, domain := range domains {
1240 if domain.Domain == "" {
1241 continue
1242 }
1243 if !(common.IsValidNginxServerName(domain.Domain) || common.IsValidIP(domain.Domain)) {
1244 err = buserr.WithName("ErrDomainFormat", domain.Domain)
1245 return
1246 }
1247 var domainModel model.WebsiteDomain
1248 domainModel.Domain, err = handleChineseDomain(domain.Domain)
1249 if err != nil {
1250 return
1251 }
1252 domainModel.Domain = strings.ToLower(domainModel.Domain)
1253 domainModel.Port = domain.Port
1254 if domain.Port == 0 {
1255 domain.Port = defaultHTTPPort
1256 }
1257 domainModel.SSL = domain.SSL
1258 domainModel.WebsiteID = websiteID
1259 domainModels = append(domainModels, domainModel)
1260 if _, ok := existPort[domainModel.Port]; !ok {
1261 ports[domainModel.Port] = struct{}{}
1262 }
1263 if exist, _ := websiteDomainRepo.GetFirst(websiteDomainRepo.WithDomain(domainModel.Domain), websiteDomainRepo.WithWebsiteId(websiteID)); exist.ID == 0 {
1264 addDomains = append(addDomains, domainModel.Domain)
1265 }
1266 }
1267 for _, domain := range domainModels {
1268 if exist, _ := websiteDomainRepo.GetFirst(websiteDomainRepo.WithDomain(domain.Domain), websiteDomainRepo.WithPort(domain.Port)); exist.ID > 0 {
1269 website, _ := websiteRepo.GetFirst(repo.WithByID(exist.WebsiteID))
1270 err = buserr.WithName("ErrDomainIsUsed", website.PrimaryDomain)
1271 return
1272 }
1273 }
1274
1275 for port := range ports {
1276 if port == defaultHTTPPort || port == defaultHTTPsPort {
1277 addPorts = append(addPorts, port)
1278 continue
1279 }
1280 if err = checkWebsitePort(defaultHTTPsPort, port, ""); err != nil {
1281 return
1282 }
1283 if existPorts, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithWebsiteId(websiteID), websiteDomainRepo.WithPort(port)); len(existPorts) == 0 {
1284 addPorts = append(addPorts, port)
1285 }
1286 }
1287

Callers 2

CreateWebsiteDomainMethod · 0.85
CreateWebsiteMethod · 0.85

Calls 8

handleChineseDomainFunction · 0.85
checkWebsitePortFunction · 0.85
GetByMethod · 0.65
WithWebsiteIdMethod · 0.65
GetFirstMethod · 0.65
WithDomainMethod · 0.65
WithPortMethod · 0.65
WithByIDMethod · 0.65

Tested by

no test coverage detected