搜索网站时同时也会检查源站是否有匹配

This commit is contained in:
GoEdgeLab
2024-05-12 18:06:24 +08:00
parent 0b7ba12825
commit ad2352f519

View File

@@ -817,11 +817,18 @@ func (this *ServerDAO) CountAllEnabledServersMatch(tx *dbs.Tx, groupId int64, ke
Param("portRange", maps.Map{"portRange": keyword}.AsJSON()). Param("portRange", maps.Map{"portRange": keyword}.AsJSON()).
Param("serverId", keyword). Param("serverId", keyword).
Param("keyword", dbutils.QuoteLike(keyword)) Param("keyword", dbutils.QuoteLike(keyword))
} else {
if regexp.MustCompile(`^[a-z0-9.-]+$`).MatchString(keyword) {
// 可以搜索源站
query.Where("(name LIKE :keyword OR serverNames LIKE :keyword OR JSON_EXTRACT(reverseProxy, '$.reverseProxyId') IN (SELECT reverseProxyId FROM " + SharedOriginDAO.Table + " WHERE reverseProxyId > 0 AND JSON_EXTRACT(addr, '$.host')=:fullKeyword))")
query.Param("keyword", dbutils.QuoteLike(keyword))
query.Param("fullKeyword", keyword)
} else { } else {
query.Where("(name LIKE :keyword OR serverNames LIKE :keyword)"). query.Where("(name LIKE :keyword OR serverNames LIKE :keyword)").
Param("keyword", dbutils.QuoteLike(keyword)) Param("keyword", dbutils.QuoteLike(keyword))
} }
} }
}
if userId > 0 { if userId > 0 {
query.Attr("userId", userId) query.Attr("userId", userId)
query.UseIndex("userId") query.UseIndex("userId")
@@ -861,7 +868,7 @@ func (this *ServerDAO) CountAllEnabledServersMatch(tx *dbs.Tx, groupId int64, ke
// //
// groupId 分组ID如果为-1则搜索没有分组的服务 // groupId 分组ID如果为-1则搜索没有分组的服务
func (this *ServerDAO) ListEnabledServersMatch(tx *dbs.Tx, offset int64, size int64, groupId int64, keyword string, userId int64, clusterId int64, auditingFlag int32, protocolFamilies []string, order string) (result []*Server, err error) { func (this *ServerDAO) ListEnabledServersMatch(tx *dbs.Tx, offset int64, size int64, groupId int64, keyword string, userId int64, clusterId int64, auditingFlag int32, protocolFamilies []string, order string) (result []*Server, err error) {
query := this.Query(tx). var query = this.Query(tx).
State(ServerStateEnabled). State(ServerStateEnabled).
Offset(offset). Offset(offset).
Limit(size). Limit(size).
@@ -879,11 +886,18 @@ func (this *ServerDAO) ListEnabledServersMatch(tx *dbs.Tx, offset int64, size in
Param("portRange", string(maps.Map{"portRange": keyword}.AsJSON())). Param("portRange", string(maps.Map{"portRange": keyword}.AsJSON())).
Param("serverId", keyword). Param("serverId", keyword).
Param("keyword", dbutils.QuoteLike(keyword)) Param("keyword", dbutils.QuoteLike(keyword))
} else {
if regexp.MustCompile(`^[a-z0-9.-]+$`).MatchString(keyword) {
// 可以搜索源站
query.Where("(name LIKE :keyword OR serverNames LIKE :keyword OR JSON_EXTRACT(reverseProxy, '$.reverseProxyId') IN (SELECT reverseProxyId FROM " + SharedOriginDAO.Table + " WHERE reverseProxyId > 0 AND JSON_EXTRACT(addr, '$.host')=:fullKeyword))")
query.Param("keyword", dbutils.QuoteLike(keyword))
query.Param("fullKeyword", keyword)
} else { } else {
query.Where("(name LIKE :keyword OR serverNames LIKE :keyword)"). query.Where("(name LIKE :keyword OR serverNames LIKE :keyword)").
Param("keyword", dbutils.QuoteLike(keyword)) Param("keyword", dbutils.QuoteLike(keyword))
} }
} }
}
if userId > 0 { if userId > 0 {
query.Attr("userId", userId) query.Attr("userId", userId)
query.UseIndex("userId") query.UseIndex("userId")