don't make two attachment requests concurrently either
This commit is contained in:
parent
0535e0af36
commit
c871ba9468
33
activity.go
33
activity.go
|
@ -19,6 +19,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html"
|
"html"
|
||||||
"io"
|
"io"
|
||||||
|
@ -141,6 +142,22 @@ func GetJunkTimeout(url string, timeout time.Duration) (junk.Junk, error) {
|
||||||
return j, nil
|
return j, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fetchsome(url string) ([]byte, error) {
|
||||||
|
resp, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error fetching %s: %s", url, err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return nil, errors.New("not 200")
|
||||||
|
}
|
||||||
|
var buf bytes.Buffer
|
||||||
|
limiter := io.LimitReader(resp.Body, 10*1024*1024)
|
||||||
|
io.Copy(&buf, limiter)
|
||||||
|
return buf.Bytes(), nil
|
||||||
|
}
|
||||||
|
|
||||||
func savedonk(url string, name, desc, media string, localize bool) *Donk {
|
func savedonk(url string, name, desc, media string, localize bool) *Donk {
|
||||||
if url == "" {
|
if url == "" {
|
||||||
return nil
|
return nil
|
||||||
|
@ -154,22 +171,16 @@ func savedonk(url string, name, desc, media string, localize bool) *Donk {
|
||||||
xid := xfiltrate()
|
xid := xfiltrate()
|
||||||
data := []byte{}
|
data := []byte{}
|
||||||
if localize {
|
if localize {
|
||||||
resp, err := http.Get(url)
|
fn := func() (interface{}, error) {
|
||||||
|
return fetchsome(url)
|
||||||
|
}
|
||||||
|
ii, err := flightdeck.Call(url, fn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error fetching %s: %s", url, err)
|
|
||||||
localize = false
|
localize = false
|
||||||
goto saveit
|
goto saveit
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
data = ii.([]byte)
|
||||||
if resp.StatusCode != 200 {
|
|
||||||
localize = false
|
|
||||||
goto saveit
|
|
||||||
}
|
|
||||||
var buf bytes.Buffer
|
|
||||||
limiter := io.LimitReader(resp.Body, 10*1024*1024)
|
|
||||||
io.Copy(&buf, limiter)
|
|
||||||
|
|
||||||
data = buf.Bytes()
|
|
||||||
if len(data) == 10*1024*1024 {
|
if len(data) == 10*1024*1024 {
|
||||||
log.Printf("truncation likely")
|
log.Printf("truncation likely")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue