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

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

View File

@@ -818,8 +818,15 @@ func (this *ServerDAO) CountAllEnabledServersMatch(tx *dbs.Tx, groupId int64, ke
Param("serverId", keyword).
Param("keyword", dbutils.QuoteLike(keyword))
} else {
query.Where("(name LIKE :keyword OR serverNames LIKE :keyword)").
Param("keyword", dbutils.QuoteLike(keyword))
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 {
query.Where("(name LIKE :keyword OR serverNames LIKE :keyword)").
Param("keyword", dbutils.QuoteLike(keyword))
}
}
}
if userId > 0 {
@@ -861,7 +868,7 @@ func (this *ServerDAO) CountAllEnabledServersMatch(tx *dbs.Tx, groupId int64, ke
//
// 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) {
query := this.Query(tx).
var query = this.Query(tx).
State(ServerStateEnabled).
Offset(offset).
Limit(size).
@@ -880,8 +887,15 @@ func (this *ServerDAO) ListEnabledServersMatch(tx *dbs.Tx, offset int64, size in
Param("serverId", keyword).
Param("keyword", dbutils.QuoteLike(keyword))
} else {
query.Where("(name LIKE :keyword OR serverNames LIKE :keyword)").
Param("keyword", dbutils.QuoteLike(keyword))
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 {
query.Where("(name LIKE :keyword OR serverNames LIKE :keyword)").
Param("keyword", dbutils.QuoteLike(keyword))
}
}
}
if userId > 0 {