Browse Source

Improvements

master
Jan-Lukas Else 9 months ago
parent
commit
8a72be6fc2
6 changed files with 10 additions and 13 deletions
  1. +1
    -1
      cdn.go
  2. +1
    -0
      imagecompression.go
  3. +1
    -0
      mediaendpoint.go
  4. +1
    -1
      mediastorage.go
  5. +4
    -9
      validation.go
  6. +2
    -2
      webmention.go

+ 1
- 1
cdn.go View File

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


+ 1
- 0
imagecompression.go View File

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


+ 1
- 0
mediaendpoint.go View File

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


+ 1
- 1
mediastorage.go View File

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


+ 4
- 9
validation.go View File

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


+ 2
- 2
webmention.go View File

@ -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…
Cancel
Save