Remove CDN purgin

master
Jan-Lukas Else 2020-05-17 12:06:00 +02:00
parent c0c480c660
commit ed21c00622
5 changed files with 0 additions and 86 deletions

27
cdn.go
View File

@ -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)
}

View File

@ -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")
}

View File

@ -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

View File

@ -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 {

View File

@ -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
}