mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
refactor(http): implement bufio (#1604)
* fix: misc http fixes * feat(io): implement bufio around syscalls * peek-a-boo * this can't be right. * you better be wearing a helmet * jesus christ. * refactor(notifications): check err on non-ok status * fix(notifications): add missing name method * refactor(indexer): api clients * fix(indexer): ptp test --------- Co-authored-by: ze0s <ze0s@riseup.net>
This commit is contained in:
parent
d13b421c42
commit
cc0cca9f0d
22 changed files with 465 additions and 304 deletions
25
web/build.go
25
web/build.go
|
@ -5,6 +5,7 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"embed"
|
||||
"fmt"
|
||||
|
@ -107,7 +108,7 @@ func fsFile(w http.ResponseWriter, r *http.Request, file string, filesystem fs.F
|
|||
return
|
||||
}
|
||||
|
||||
data, err := io.ReadAll(f)
|
||||
data, err := io.ReadAll(bufio.NewReader(f))
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to read the file", http.StatusInternalServerError)
|
||||
return
|
||||
|
@ -164,27 +165,7 @@ func RegisterHandler(c *chi.Mux, version, baseUrl string) {
|
|||
}
|
||||
|
||||
// if not valid web route then try and serve files
|
||||
f, err := DistDirFS.Open(file)
|
||||
if err != nil {
|
||||
http.Error(w, "File not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
stat, err := f.Stat()
|
||||
if err != nil {
|
||||
http.Error(w, "File not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to read the file", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
reader := bytes.NewReader(data)
|
||||
http.ServeContent(w, r, file, stat.ModTime(), reader)
|
||||
fsFile(w, r, file, DistDirFS)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue