From ed21c00622bb30d389a8cf3c92933d5774b88b24 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Sun, 17 May 2020 12:06:00 +0200 Subject: [PATCH] Remove CDN purgin --- cdn.go | 27 --------------------------- cdn_test.go | 30 ------------------------------ config.go | 13 ------------- micropub.go | 9 --------- webmention.go | 7 ------- 5 files changed, 86 deletions(-) delete mode 100644 cdn.go delete mode 100644 cdn_test.go diff --git a/cdn.go b/cdn.go deleted file mode 100644 index b2d16b2..0000000 --- a/cdn.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "net/http" -) - -type Cdn interface { - // Purge url from CDN - Purge(url string) -} - -// BunnyCDN -type BunnyCdn struct { - // Access Key - key string -} - -var bunnyCdnUrl = "https://bunnycdn.com" - -func (cdn *BunnyCdn) Purge(url string) { - client := http.DefaultClient - req, _ := http.NewRequest("POST", bunnyCdnUrl+"/api/purge?url="+url, nil) - req.Header.Add("Content-Type", "application/json") - req.Header.Add("Accept", "application/json") - req.Header.Add("AccessKey", cdn.key) - _, _ = client.Do(req) -} diff --git a/cdn_test.go b/cdn_test.go deleted file mode 100644 index 8255d17..0000000 --- a/cdn_test.go +++ /dev/null @@ -1,30 +0,0 @@ -package main - -import ( - "net/http" - "net/http/httptest" - "testing" -) - -func TestBunnyCdn_Purge(t *testing.T) { - cdn := &BunnyCdn{ - key: "testkey", - } - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if expectedUrl := "/api/purge?url=https://test.url/test"; r.URL.String() != expectedUrl { - t.Errorf("Wrong URL: Got %s, but expected %s", r.URL.String(), expectedUrl) - } - if expectedContentType := "application/json"; r.Header.Get("Content-Type") != expectedContentType { - t.Errorf("Wrong Content-Type Header: Got %s, but expected %s", r.Header.Get("Content-Type"), expectedContentType) - } - if expectedAccept := "application/json"; r.Header.Get("Accept") != expectedAccept { - t.Errorf("Wrong Accept Header: Got %s, but expected %s", r.Header.Get("Accept"), expectedAccept) - } - if r.Header.Get("AccessKey") != cdn.key { - t.Errorf("Wrong AccessKey Header: Got %s, but expected %s", r.Header.Get("AccessKey"), cdn.key) - } - })) - defer ts.Close() - bunnyCdnUrl = ts.URL - cdn.Purge("https://test.url/test") -} diff --git a/config.go b/config.go index afa5639..dfe50de 100644 --- a/config.go +++ b/config.go @@ -15,7 +15,6 @@ var ( SyndicationTargets []SyndicationTarget SelectedStorage Storage SelectedMediaStorage MediaStorage - SelectedCdn Cdn SelectedNotificationServices NotificationServices SelectedImageCompression ImageCompression DefaultLanguage string @@ -41,7 +40,6 @@ type YamlConfig struct { } type BunnyCdnConfig struct { - Key string `yaml:"key"` StorageKey string `yaml:"storageKey"` StorageName string `yaml:"storageName"` } @@ -173,17 +171,6 @@ func initConfig() (err error) { if SelectedMediaStorage == nil { log.Println("no media storage configured") } - // Find selected CDN (optional) - SelectedCdn = func() Cdn { - // BunnyCDN - if len(cfg.BunnyCdn.Key) > 0 { - return &BunnyCdn{key: cfg.BunnyCdn.Key} - } - return nil - }() - if SelectedCdn == nil { - log.Println("no CDN configured") - } // Find configured notification services (optional) SelectedNotificationServices = func() NotificationServices { var notificationServices []NotificationService = nil diff --git a/micropub.go b/micropub.go index 82693a7..4ebc42f 100644 --- a/micropub.go +++ b/micropub.go @@ -3,7 +3,6 @@ package main import ( "encoding/json" "net/http" - "time" ) type MicropubConfig struct { @@ -65,14 +64,6 @@ func HandleMicroPub(w http.ResponseWriter, r *http.Request) { } else { w.Header().Add("Location", location+"?cache=0") w.WriteHeader(http.StatusAccepted) - // Purge CDN after 30 seconds, send webmentions, post to social media - go func() { - time.Sleep(30 * time.Second) - if SelectedCdn != nil { - SelectedCdn.Purge(location) - time.Sleep(10 * time.Second) - } - }() return } } else { diff --git a/webmention.go b/webmention.go index 37aabb5..1947c10 100644 --- a/webmention.go +++ b/webmention.go @@ -157,12 +157,5 @@ func returnSuccess(target string, w http.ResponseWriter, r *http.Request) { } else { w.WriteHeader(http.StatusCreated) } - // Purge CDN after 30 seconds - go func() { - time.Sleep(30 * time.Second) - if SelectedCdn != nil { - SelectedCdn.Purge(target) - } - }() return }