mirror of
https://github.com/nxshock/simplefileshare.git
synced 2024-11-27 03:11:01 +05:00
Serve files with stdlib
This commit is contained in:
parent
f2ea91fcbb
commit
2df1c59031
2
PKGBUILD
2
PKGBUILD
@ -1,5 +1,5 @@
|
||||
pkgname=simplefileshare
|
||||
pkgver=0.1.2
|
||||
pkgver=0.1.3
|
||||
pkgrel=0
|
||||
pkgdesc="Simple file share"
|
||||
arch=('x86_64' 'aarch64')
|
||||
|
19
handlers.go
19
handlers.go
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user