refactor: remove unused remarks and add quick domain create

Drop remark fields from Zone, Zone domains, proxy routes, WAF rule
groups and IP groups across models, APIs, UI and DB columns (keep
certificate/origin remarks). Add quick-create domain input for short
labels, @ apex and full FQDNs when binding domains.
This commit is contained in:
ryan
2026-07-12 16:16:56 +08:00
parent 8afd103751
commit d615d85a26
43 changed files with 616 additions and 433 deletions
@@ -57,7 +57,6 @@ type snapshotRoute struct {
BasicAuthEnabled bool `json:"basic_auth_enabled,omitempty"`
BasicAuthUsername string `json:"basic_auth_username,omitempty"`
BasicAuthPassword string `json:"basic_auth_password,omitempty"`
Remark string `json:"remark,omitempty"`
UpstreamType string `json:"upstream_type,omitempty"`
TunnelNodeID *uint `json:"tunnel_node_id,omitempty"`
TunnelTargetAddr string `json:"tunnel_target_addr,omitempty"`
@@ -297,7 +296,6 @@ func buildSnapshotRoutes(ctx context.Context, routes []*model.ProxyRoute) ([]sna
BasicAuthEnabled: route.BasicAuthEnabled,
BasicAuthUsername: route.BasicAuthUsername,
BasicAuthPassword: route.BasicAuthPassword,
Remark: route.Remark,
UpstreamType: upstreamType,
TunnelNodeID: tunnelNodeID,
TunnelTargetAddr: tunnelTargetAddr,
@@ -114,7 +114,6 @@ func TestSecurityWAFTLSMigrationFlow(t *testing.T) {
"ip_whitelist": []string{"192.0.2.1"},
"ip_blacklist": []string{"203.0.113.10"},
"country_blacklist": []string{"CN"},
"remark": "integration rule group",
}, adminAuthHeaders(seed.Token))
require.Equal(t, http.StatusOK, rec.Code)
@@ -179,7 +178,6 @@ func TestSecurityWAFTLSMigrationFlow(t *testing.T) {
"name": "edge-security-updated",
"enabled": true,
"block_status_code": 451,
"remark": "updated by integration test",
},
adminAuthHeaders(seed.Token),
)
@@ -197,7 +195,6 @@ func TestSecurityWAFTLSMigrationFlow(t *testing.T) {
"type": "manual",
"enabled": true,
"ip_list": []string{"203.0.113.0/24", "198.51.100.10"},
"remark": "manual deny list",
}, adminAuthHeaders(seed.Token))
require.Equal(t, http.StatusOK, rec.Code)
@@ -306,7 +303,7 @@ func TestSecurityWAFTLSMigrationFlow(t *testing.T) {
assert.NotEmpty(t, errResp.ErrorMsg)
rec = performJSONRequest(t, engine, http.MethodPost, fmt.Sprintf("%s/zones/%d/domains", apiPath(""), zoneID), map[string]any{
"domain": "security.example.com", "cert_id": certID, "remark": "primary security domain",
"domain": "security.example.com", "cert_id": certID,
}, adminAuthHeaders(seed.Token))
require.Equal(t, http.StatusOK, rec.Code)
@@ -88,7 +88,7 @@ func populateProxyRouteFields(
jsonFields *proxyRouteJSONFields,
originID *uint,
upstreams []string,
originHost, remark, cachePolicy string,
originHost, cachePolicy string,
limitConnPerServer, limitConnPerIP int,
limitRate, upstreamType string,
) {
@@ -110,7 +110,6 @@ func populateProxyRouteFields(
route.BasicAuthEnabled = input.BasicAuthEnabled
route.BasicAuthUsername = input.BasicAuthUsername
route.BasicAuthPassword = input.BasicAuthPassword
route.Remark = remark
route.UpstreamType = upstreamType
}
@@ -151,7 +150,7 @@ func updateProxyRouteRecord(tx *gorm.DB, route *model.ProxyRoute) error {
"limit_rate": route.LimitRate, "cache_enabled": route.CacheEnabled, "cache_policy": route.CachePolicy,
"cache_rules": route.CacheRules, "custom_headers": route.CustomHeaders,
"basic_auth_enabled": route.BasicAuthEnabled, "basic_auth_username": route.BasicAuthUsername,
"basic_auth_password": route.BasicAuthPassword, "remark": route.Remark,
"basic_auth_password": route.BasicAuthPassword,
"upstream_type": route.UpstreamType, "tunnel_node_id": route.TunnelNodeID,
"tunnel_target_addr": route.TunnelTargetAddr, "tunnel_target_protocol": route.TunnelTargetProtocol,
"pages_project_id": route.PagesProjectID,
@@ -45,7 +45,6 @@ type Input struct {
BasicAuthEnabled bool `json:"basic_auth_enabled"`
BasicAuthUsername string `json:"basic_auth_username"`
BasicAuthPassword string `json:"basic_auth_password"`
Remark string `json:"remark"`
UpstreamType string `json:"upstream_type"`
TunnelNodeID *uint `json:"tunnel_node_id"`
TunnelID *uint `json:"tunnel_id"`
@@ -80,7 +79,6 @@ type View struct {
BasicAuthEnabled bool `json:"basic_auth_enabled"`
BasicAuthUsername string `json:"basic_auth_username"`
BasicAuthPassword string `json:"basic_auth_password"`
Remark string `json:"remark"`
UpstreamType string `json:"upstream_type"`
TunnelNodeID *uint `json:"tunnel_node_id"`
TunnelID *uint `json:"tunnel_id"`
@@ -187,7 +185,6 @@ func buildProxyRoute(ctx context.Context, route *model.ProxyRoute, input Input)
return nil, nil, err
}
originHost := strings.TrimSpace(input.OriginHost)
remark := strings.TrimSpace(input.Remark)
cachePolicy := strings.TrimSpace(input.CachePolicy)
cacheRules, err := normalizeCacheRules(input.CacheEnabled, cachePolicy, input.CacheRules)
if err != nil {
@@ -245,7 +242,6 @@ func buildProxyRoute(ctx context.Context, route *model.ProxyRoute, input Input)
originID,
upstreams,
originHost,
remark,
cachePolicy,
limitConnPerServer,
limitConnPerIP,
@@ -321,7 +317,6 @@ func buildProxyRouteView(ctx context.Context, route *model.ProxyRoute) (*View, e
BasicAuthEnabled: route.BasicAuthEnabled,
BasicAuthUsername: route.BasicAuthUsername,
BasicAuthPassword: route.BasicAuthPassword,
Remark: route.Remark,
UpstreamType: route.UpstreamType,
TunnelNodeID: route.TunnelNodeID,
TunnelID: route.TunnelNodeID,
-8
View File
@@ -55,7 +55,6 @@ type RuleGroupInput struct {
CountryBlacklist []string `json:"country_blacklist"`
RegionWhitelist []string `json:"region_whitelist"`
RegionBlacklist []string `json:"region_blacklist"`
Remark string `json:"remark"`
PoWEnabled bool `json:"pow_enabled"`
PoWConfig json.RawMessage `json:"pow_config"`
}
@@ -95,7 +94,6 @@ type RuleGroupView struct {
CountryBlacklist []string `json:"country_blacklist"`
RegionWhitelist []string `json:"region_whitelist"`
RegionBlacklist []string `json:"region_blacklist"`
Remark string `json:"remark"`
PoWEnabled bool `json:"pow_enabled"`
PoWConfig *PoWConfig `json:"pow_config"`
AppliedSiteIDs []uint `json:"applied_site_ids"`
@@ -129,7 +127,6 @@ type IPGroupInput struct {
SubscriptionFormat string `json:"subscription_format"`
SubscriptionMappingRule string `json:"subscription_mapping_rule"`
SyncIntervalMinutes int `json:"sync_interval_minutes"`
Remark string `json:"remark"`
}
// IPGroupExtIPView is an external IP entry in API responses.
@@ -155,7 +152,6 @@ type IPGroupView struct {
NextSyncAt string `json:"next_sync_at,omitempty"`
LastSyncStatus string `json:"last_sync_status"`
LastSyncMessage string `json:"last_sync_message"`
Remark string `json:"remark"`
ReferencedByRuleCount int `json:"referenced_by_rule_count"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
@@ -597,7 +593,6 @@ func buildRuleGroup(ctx context.Context, group *model.OpenFlareWAFRuleGroup, inp
group.RegionBlacklist = string(regionBlacklistJSON)
group.PoWEnabled = input.PoWEnabled
group.PoWConfig = string(powConfigJSON)
group.Remark = strings.TrimSpace(input.Remark)
return group, nil
}
@@ -613,7 +608,6 @@ func buildRuleGroupView(group *model.OpenFlareWAFRuleGroup, appliedSiteIDs []uin
IsGlobal: group.IsGlobal,
BlockStatusCode: group.BlockStatusCode,
BlockResponseBody: group.BlockResponseBody,
Remark: group.Remark,
PoWEnabled: group.PoWEnabled,
AppliedSiteIDs: appliedSiteIDs,
AppliedSiteCount: len(appliedSiteIDs),
@@ -709,7 +703,6 @@ func buildIPGroup(group *model.OpenFlareWAFIPGroup, input IPGroupInput) (*model.
group.SubscriptionMappingRule = mappingRule
group.SyncIntervalMinutes = syncInterval
group.NextSyncAt = nextIPGroupSyncAt(group.Type, group.Enabled, syncInterval, group.NextSyncAt)
group.Remark = strings.TrimSpace(input.Remark)
return group, nil
}
@@ -750,7 +743,6 @@ func buildIPGroupView(group *model.OpenFlareWAFIPGroup, referenceCount int) (IPG
SyncIntervalMinutes: group.SyncIntervalMinutes,
LastSyncStatus: group.LastSyncStatus,
LastSyncMessage: group.LastSyncMessage,
Remark: group.Remark,
ReferencedByRuleCount: referenceCount,
CreatedAt: group.CreatedAt.Format(time.RFC3339),
UpdatedAt: group.UpdatedAt.Format(time.RFC3339),
@@ -100,7 +100,6 @@ func TestUpdateIPGroupPrunesAutomaticExtIPs(t *testing.T) {
Enabled: created.Enabled,
IPList: []string{"203.0.113.10"},
AutoConfig: created.AutoConfig,
Remark: created.Remark,
})
require.NoError(t, err)
require.Len(t, updated.IPList, 1)
+1 -1
View File
@@ -14,5 +14,5 @@ const (
errDomainExists = "域名已存在"
errCertificateNotFound = "所选证书不存在"
errDomainBoundToRoute = "域名已绑定反代路由,请先解除绑定"
errZoneHasDomains = "Zone 下仍有域名,请先删除全部域名"
errZoneHasDomains = "根域下仍有域名,请先删除全部域名"
)
+12 -16
View File
@@ -33,7 +33,6 @@ func (r ImportReport) LogAndReturn(err error) error {
type legacyDomain struct {
Domain string
CertID *uint
Remark string
ProxyRouteID *uint
}
@@ -139,9 +138,9 @@ func ImportLegacyTx(ctx context.Context, tx *sql.Tx, postgres bool) (report Impo
}
if _, insErr := tx.ExecContext(ctx, q(`
INSERT INTO of_zone_domains (zone_id, proxy_route_id, domain, cert_id, remark, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
`), zoneID, nullableUint(item.ProxyRouteID), domain, nullableUint(item.CertID), item.Remark); insErr != nil {
INSERT INTO of_zone_domains (zone_id, proxy_route_id, domain, cert_id, created_at, updated_at)
VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
`), zoneID, nullableUint(item.ProxyRouteID), domain, nullableUint(item.CertID)); insErr != nil {
return report, insErr
}
report.Domains++
@@ -169,8 +168,8 @@ func ensureZone(
return 0, err
}
if _, execErr := tx.ExecContext(ctx, q(`
INSERT INTO of_zones (domain, remark, created_at, updated_at)
VALUES (?, '', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
INSERT INTO of_zones (domain, created_at, updated_at)
VALUES (?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
`), root); execErr != nil {
return 0, execErr
}
@@ -187,12 +186,12 @@ func collectLegacyRouteDomainsImpl(
q func(string) string,
) (items []legacyDomain, hasRouteDomains bool, conflicts []string, err error) {
// Probe domain_cert_ids: if SELECT fails, fall back without it.
queryWithCert := q(`SELECT id, domain, domains, COALESCE(domain_cert_ids, '[]'), remark FROM of_proxy_routes`)
queryWithCert := q(`SELECT id, domain, domains, COALESCE(domain_cert_ids, '[]') FROM of_proxy_routes`)
rows, err := tx.QueryContext(ctx, queryWithCert)
useCert := true
if err != nil {
useCert = false
rows, err = tx.QueryContext(ctx, q(`SELECT id, domain, domains, remark FROM of_proxy_routes`))
rows, err = tx.QueryContext(ctx, q(`SELECT id, domain, domains FROM of_proxy_routes`))
if err != nil {
return nil, false, nil, err
}
@@ -205,14 +204,13 @@ func collectLegacyRouteDomainsImpl(
domain string
domains string
certIDs string
remark string
)
if useCert {
if err := rows.Scan(&id, &domain, &domains, &certIDs, &remark); err != nil {
if err := rows.Scan(&id, &domain, &domains, &certIDs); err != nil {
return nil, false, nil, err
}
} else {
if err := rows.Scan(&id, &domain, &domains, &remark); err != nil {
if err := rows.Scan(&id, &domain, &domains); err != nil {
return nil, false, nil, err
}
certIDs = "[]"
@@ -236,7 +234,6 @@ func collectLegacyRouteDomainsImpl(
items = append(items, legacyDomain{
Domain: d,
CertID: certID,
Remark: remark,
ProxyRouteID: &routeID,
})
}
@@ -245,7 +242,7 @@ func collectLegacyRouteDomainsImpl(
}
func collectLegacyManagedDomains(ctx context.Context, tx *sql.Tx, q func(string) string) ([]legacyDomain, error) {
rows, err := tx.QueryContext(ctx, q(`SELECT domain, cert_id, remark FROM of_managed_domains`))
rows, err := tx.QueryContext(ctx, q(`SELECT domain, cert_id FROM of_managed_domains`))
if err != nil {
return nil, err
}
@@ -256,12 +253,11 @@ func collectLegacyManagedDomains(ctx context.Context, tx *sql.Tx, q func(string)
var (
domain string
certID sql.NullInt64
remark string
)
if err := rows.Scan(&domain, &certID, &remark); err != nil {
if err := rows.Scan(&domain, &certID); err != nil {
return nil, err
}
item := legacyDomain{Domain: domain, Remark: remark}
item := legacyDomain{Domain: domain}
if certID.Valid && certID.Int64 > 0 {
v := uint(certID.Int64)
item.CertID = &v
@@ -27,7 +27,6 @@ func setupLegacyImportDB(t *testing.T) (*sql.DB, func()) {
`CREATE TABLE of_zones (
id INTEGER PRIMARY KEY AUTOINCREMENT,
domain TEXT NOT NULL UNIQUE,
remark TEXT NOT NULL DEFAULT '',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
)`,
@@ -37,7 +36,6 @@ func setupLegacyImportDB(t *testing.T) (*sql.DB, func()) {
proxy_route_id INTEGER,
domain TEXT NOT NULL UNIQUE,
cert_id INTEGER,
remark TEXT NOT NULL DEFAULT '',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
)`,
@@ -124,7 +122,6 @@ func TestImportLegacyTxNoOpWithoutLegacyColumns(t *testing.T) {
CREATE TABLE of_zones (
id INTEGER PRIMARY KEY AUTOINCREMENT,
domain TEXT NOT NULL UNIQUE,
remark TEXT NOT NULL DEFAULT '',
created_at DATETIME, updated_at DATETIME
);
CREATE TABLE of_zone_domains (
@@ -133,7 +130,6 @@ func TestImportLegacyTxNoOpWithoutLegacyColumns(t *testing.T) {
proxy_route_id INTEGER,
domain TEXT NOT NULL UNIQUE,
cert_id INTEGER,
remark TEXT NOT NULL DEFAULT '',
created_at DATETIME, updated_at DATETIME
);
CREATE TABLE of_proxy_routes (
+4 -8
View File
@@ -19,14 +19,12 @@ import (
// Input is the mutable Zone payload.
type Input struct {
Domain string `json:"domain"`
Remark string `json:"remark"`
}
// DomainInput is the mutable Zone-domain payload.
type DomainInput struct {
Domain string `json:"domain"`
CertID *uint `json:"cert_id"`
Remark string `json:"remark"`
}
// Overview joins a Zone with its explicit domains.
@@ -39,7 +37,6 @@ type Overview struct {
type ListItem struct {
ID uint `json:"id"`
Domain string `json:"domain"`
Remark string `json:"remark"`
DomainCount int64 `json:"domain_count"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
@@ -76,7 +73,7 @@ func Create(ctx context.Context, input Input) (*model.Zone, error) {
if err != nil || root != domain {
return nil, errors.New(errZoneRootInvalid)
}
zone := &model.Zone{Domain: domain, Remark: strings.TrimSpace(input.Remark)}
zone := &model.Zone{Domain: domain}
if err := db.DB(ctx).Create(zone).Error; err != nil {
if isUnique(err) {
return nil, errors.New(errDomainExists)
@@ -100,7 +97,7 @@ func Update(ctx context.Context, id uint, input Input) (*model.Zone, error) {
if err != nil || root != domain {
return nil, errors.New(errZoneRootInvalid)
}
zone.Domain, zone.Remark = domain, strings.TrimSpace(input.Remark)
zone.Domain = domain
if err := db.DB(ctx).Save(&zone).Error; err != nil {
if isUnique(err) {
return nil, errors.New(errDomainExists)
@@ -138,7 +135,6 @@ func List(ctx context.Context) ([]ListItem, error) {
items = append(items, ListItem{
ID: zone.ID,
Domain: zone.Domain,
Remark: zone.Remark,
DomainCount: counts[zone.ID],
CreatedAt: zone.CreatedAt,
UpdatedAt: zone.UpdatedAt,
@@ -179,7 +175,7 @@ func CreateDomain(ctx context.Context, zoneID uint, input DomainInput) (*model.Z
return nil, errors.New(errCertificateNotFound)
}
}
item := &model.ZoneDomain{ZoneID: zoneID, Domain: domain, CertID: input.CertID, Remark: strings.TrimSpace(input.Remark)}
item := &model.ZoneDomain{ZoneID: zoneID, Domain: domain, CertID: input.CertID}
if err := db.DB(ctx).Create(item).Error; err != nil {
if isUnique(err) {
return nil, errors.New(errDomainExists)
@@ -212,7 +208,7 @@ func UpdateDomain(ctx context.Context, zoneID, id uint, input DomainInput) (*mod
return nil, errors.New(errCertificateNotFound)
}
}
item.Domain, item.CertID, item.Remark = domain, input.CertID, strings.TrimSpace(input.Remark)
item.Domain, item.CertID = domain, input.CertID
if err = db.DB(ctx).Save(&item).Error; err != nil {
if isUnique(err) {
return nil, errors.New(errDomainExists)