mirror of
https://github.com/nxshock/simplefileshare.git
synced 2025-04-19 01:01:50 +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
|
pkgname=simplefileshare
|
||||||
pkgver=0.1.2
|
pkgver=0.1.3
|
||||||
pkgrel=0
|
pkgrel=0
|
||||||
pkgdesc="Simple file share"
|
pkgdesc="Simple file share"
|
||||||
arch=('x86_64' 'aarch64')
|
arch=('x86_64' 'aarch64')
|
||||||
|
19
handlers.go
19
handlers.go
@ -138,24 +138,7 @@ func HandleStream(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := os.Open(filepath.Join(config.StoragePath, filename))
|
http.ServeFile(w, r, 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))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleIcon(w http.ResponseWriter, r *http.Request) {
|
func HandleIcon(w http.ResponseWriter, r *http.Request) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user