mirror of
https://github.com/makew0rld/amfora.git
synced 2024-12-04 14:46:29 -05:00
🐛 Catch errors when downloading
This commit is contained in:
parent
aa28bc78b2
commit
e740c58ff9
@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- You can't change link selection while the page is loading
|
||||
- Only one request is made for each URL - `v1.3.0` accidentally made two requests each time (#50)
|
||||
- Using the `..` command doesn't keep the query string (#49)
|
||||
- Any error that occurs when downloading a file will be displayed, and the partially download file will be deleted
|
||||
|
||||
|
||||
## [1.3.0] - 2020-07-10
|
||||
|
@ -159,8 +159,15 @@ func downloadURL(u string, resp *gemini.Response) {
|
||||
App.SetFocus(dlModal)
|
||||
App.Draw()
|
||||
|
||||
io.Copy(io.MultiWriter(f, bar), resp.Body)
|
||||
_, err = io.Copy(io.MultiWriter(f, bar), resp.Body)
|
||||
done = true
|
||||
if err != nil {
|
||||
tabPages.HidePage("dl")
|
||||
Error("Download Error", err.Error())
|
||||
f.Close()
|
||||
os.Remove(savePath) // Remove partial file
|
||||
return
|
||||
}
|
||||
dlModal.SetText(fmt.Sprintf("Download complete! File saved to %s.", savePath))
|
||||
dlModal.ClearButtons()
|
||||
dlModal.AddButtons([]string{"Ok"})
|
||||
|
@ -65,11 +65,11 @@ func MakePage(url string, res *gemini.Response, width, leftMargin int) (*structs
|
||||
res.Body.Close()
|
||||
}()
|
||||
|
||||
_, err := io.CopyN(buf, res.Body, viper.GetInt64("a-general.page_max_size")) // 2 MiB max
|
||||
_, err := io.CopyN(buf, res.Body, viper.GetInt64("a-general.page_max_size")+1)
|
||||
res.Body.Close()
|
||||
rawText := buf.Bytes()
|
||||
if err == nil {
|
||||
// Content was larger than 2 MiB
|
||||
// Content was larger than max size
|
||||
return nil, ErrTooLarge
|
||||
} else if err != io.EOF {
|
||||
if strings.HasSuffix(err.Error(), "use of closed network connection") {
|
||||
|
Loading…
Reference in New Issue
Block a user