Add timeouts for uploads and version check.
This commit is contained in:
parent
cb1f1d1a05
commit
13589535a8
10
dau.go
10
dau.go
@ -40,6 +40,8 @@ func main() {
|
|||||||
|
|
||||||
check_updates()
|
check_updates()
|
||||||
|
|
||||||
|
log.Print("Waiting for images to appear in ", path)
|
||||||
|
|
||||||
// wander the path, forever
|
// wander the path, forever
|
||||||
for {
|
for {
|
||||||
err := filepath.Walk(path, check_file)
|
err := filepath.Walk(path, check_file)
|
||||||
@ -59,9 +61,10 @@ func check_updates() {
|
|||||||
Body string
|
Body string
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := http.Get("https://api.github.com/repos/tardisx/discord-auto-upload/releases/latest")
|
client := &http.Client{ Timeout: time.Second * 5 }
|
||||||
|
resp, err := client.Get("https://api.github.com/repos/tardisx/discord-auto-upload/releases/latest")
|
||||||
if (err != nil) {
|
if (err != nil) {
|
||||||
log.Fatal("could not check for updates")
|
log.Fatal("could not check for updates:", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
@ -124,7 +127,6 @@ func parse_options() (webhook_url string, path string, watch int, username strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
func check_file(path string, f os.FileInfo, err error) error {
|
func check_file(path string, f os.FileInfo, err error) error {
|
||||||
// fmt.Println("Comparing", f.ModTime(), "to", last_check, "for", path)
|
|
||||||
|
|
||||||
if f.ModTime().After(last_check) && f.Mode().IsRegular() {
|
if f.ModTime().After(last_check) && f.Mode().IsRegular() {
|
||||||
|
|
||||||
@ -178,7 +180,7 @@ func process_file(file string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
client := &http.Client{}
|
client := &http.Client{ Timeout: time.Second * 30 }
|
||||||
resp, err := client.Do(request)
|
resp, err := client.Do(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user