Improvements
parent
580724e9f9
commit
8a72be6fc2
2
cdn.go
2
cdn.go
|
@ -18,7 +18,7 @@ type BunnyCdn struct {
|
|||
var bunnyCdnUrl = "https://bunnycdn.com"
|
||||
|
||||
func (cdn *BunnyCdn) Purge(url string) {
|
||||
client := &http.Client{}
|
||||
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")
|
||||
|
|
|
@ -51,6 +51,7 @@ func (t *Tinify) Compress(url string) (location string, err error) {
|
|||
return
|
||||
}
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
_ = os.Remove(file.Name())
|
||||
}()
|
||||
e = s.ToFile(file.Name())
|
||||
|
|
|
@ -40,6 +40,7 @@ func HandleMedia(w http.ResponseWriter, r *http.Request) {
|
|||
_, _ = w.Write([]byte("Failed to get file"))
|
||||
return
|
||||
}
|
||||
defer func() { _ = file.Close() }()
|
||||
hashFile, _, _ := r.FormFile("file")
|
||||
defer func() { _ = hashFile.Close() }()
|
||||
fileName, err := getSHA256(hashFile)
|
||||
|
|
|
@ -27,7 +27,7 @@ type BunnyCdnStorage struct {
|
|||
var bunnyCdnStorageUrl = "https://storage.bunnycdn.com"
|
||||
|
||||
func (b *BunnyCdnStorage) Upload(fileName string, file multipart.File) (location string, err error) {
|
||||
client := &http.Client{}
|
||||
client := http.DefaultClient
|
||||
req, _ := http.NewRequest(http.MethodPut, bunnyCdnStorageUrl+"/"+url.PathEscape(b.storageZoneName)+"/"+url.PathEscape("/"+fileName), file)
|
||||
req.Header.Add("AccessKey", b.key)
|
||||
resp, err := client.Do(req)
|
||||
|
|
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
@ -34,7 +33,7 @@ func checkAccess(token string) (bool, error) {
|
|||
return false, errors.New("token string is empty")
|
||||
}
|
||||
// form the request to check the token
|
||||
client := &http.Client{}
|
||||
client := http.DefaultClient
|
||||
req, err := http.NewRequest("GET", indieAuthTokenUrl, nil)
|
||||
if err != nil {
|
||||
return false, errors.New("error making the request for checking token access")
|
||||
|
@ -46,14 +45,10 @@ func checkAccess(token string) (bool, error) {
|
|||
if err != nil {
|
||||
return false, errors.New("error sending the request for checking token access")
|
||||
}
|
||||
defer res.Body.Close()
|
||||
// parse the response
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return false, errors.New("error parsing the response for checking token access")
|
||||
}
|
||||
var indieAuthRes = new(IndieAuthRes)
|
||||
err = json.Unmarshal(body, &indieAuthRes)
|
||||
indieAuthRes := &IndieAuthRes{}
|
||||
err = json.NewDecoder(res.Body).Decode(&indieAuthRes)
|
||||
res.Body.Close()
|
||||
if err != nil {
|
||||
return false, errors.New("Error parsing the response into json for checking token access " + err.Error())
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ func HandleWebmention(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func responseCodeForSource(source string) (int, error) {
|
||||
client := &http.Client{}
|
||||
client := http.DefaultClient
|
||||
resp, err := client.Get(source)
|
||||
if err != nil || resp == nil {
|
||||
return 0, err
|
||||
|
@ -208,4 +208,4 @@ func returnSuccess(target string, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue