ソースを参照

feature: Cloudflare支持不缓存

世祺 1 年間 前
コミット
072107b6df
2 ファイル変更13 行追加8 行削除
  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{
 			{