Serve files with stdlib

This commit is contained in:
nxshock 2022-07-27 19:40:40 +05:00
parent f2ea91fcbb
commit 2df1c59031
2 changed files with 2 additions and 19 deletions

View File

@ -1,5 +1,5 @@
pkgname=simplefileshare
pkgver=0.1.2
pkgver=0.1.3
pkgrel=0
pkgdesc="Simple file share"
arch=('x86_64' 'aarch64')

View File

@ -138,24 +138,7 @@ func HandleStream(w http.ResponseWriter, r *http.Request) {
return
}
f, err := os.Open(filepath.Join(config.StoragePath, filename))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer f.Close()
fileStat, err := f.Stat()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", mime.TypeByExtension(filepath.Ext(filename)))
w.Header().Set("Accept-Ranges", "none")
w.Header().Set("Content-Length", strconv.Itoa(int(fileStat.Size())))
io.CopyBuffer(w, f, make([]byte, 4096))
http.ServeFile(w, r, filepath.Join(config.StoragePath, filename))
}
func HandleIcon(w http.ResponseWriter, r *http.Request) {