Browse Source

feature: Cloudflare支持不缓存

世祺 1 year ago
parent
commit
072107b6df
2 changed files with 13 additions and 8 deletions
  1. 1 1
      proto
  2. 12 7
      server/zone_convert.go

+ 1 - 1
proto

@@ -1 +1 @@
-Subproject commit e1cbc80711aa7c3259731a3642944221e6de6f4f
+Subproject commit 15ffd7fb7a6ea24e9a8bf1001c1cd0ff4692ecea

+ 12 - 7
server/zone_convert.go

@@ -223,7 +223,18 @@ func Proto2GoPageRule(rule *zone.PageRule) (*cloudflare.PageRule, error) {
 		action     []cloudflare.PageRuleAction
 	)
 	//TTL设置
-	if rule.Ttl != nil {
+	if rule.Ttl == nil {
+		//缓存级别
+		action = append(action, cloudflare.PageRuleAction{
+			ID:    "cache_level",
+			Value: "bypass",
+		})
+	} else {
+		//缓存级别
+		action = append(action, cloudflare.PageRuleAction{
+			ID:    "cache_level",
+			Value: "cache_everything",
+		})
 		action = append(action, cloudflare.PageRuleAction{
 			ID:    "edge_cache_ttl",
 			Value: rule.Ttl,
@@ -286,12 +297,6 @@ func Proto2GoPageRule(rule *zone.PageRule) (*cloudflare.PageRule, error) {
 		})
 	}
 
-	//缓存级别 恒为缓存所有
-	action = append(action, cloudflare.PageRuleAction{
-		ID:    "cache_level",
-		Value: "cache_everything",
-	})
-
 	return &cloudflare.PageRule{
 		Targets: []cloudflare.PageRuleTarget{
 			{