mirror of
https://github.com/pldubouilh/gossa
synced 2025-12-06 16:32:52 +01:00
archive download
This commit is contained in:
parent
dd6cb90e9d
commit
c1eeb9820a
4 changed files with 69 additions and 13 deletions
2
gossa-ui
2
gossa-ui
|
|
@ -1 +1 @@
|
||||||
Subproject commit a88fc12cf53249238cf45dc382be0851cf7261df
|
Subproject commit 26b93fd4bd969143105c23bc1bc644eeba000e13
|
||||||
23
readme.md
23
readme.md
|
|
@ -8,24 +8,26 @@ gossa
|
||||||
[](https://hub.docker.com/r/pldubouilh/gossa)
|
[](https://hub.docker.com/r/pldubouilh/gossa)
|
||||||
[](https://github.com/pldubouilh/gossa/releases)
|
[](https://github.com/pldubouilh/gossa/releases)
|
||||||
|
|
||||||
a fast and simple webserver for your files, that's dependency-free and with under 200 lines of code, easy to review.
|
a fast and simple webserver for your files, that's dependency-free and with under 250 lines of code, easy to review.
|
||||||
|
|
||||||
a [simple UI](https://github.com/pldubouilh/gossa-ui) comes as default, featuring :
|
a [simple UI](https://github.com/pldubouilh/gossa-ui) comes as default, featuring :
|
||||||
|
|
||||||
* 🔍 files/directories browser
|
* 🔍 files/directories browser & handler
|
||||||
* 📩 drag-and-drop file/directory uploader
|
* 📩 drag-and-drop uploader
|
||||||
* 🚀 lightweight, default ui weights 110kB and prints in ms
|
* 🚀 lightweight and dependency free
|
||||||
* 🗺️ files handling - move/rename/delete
|
* 💾 90s web UI that prints in ms
|
||||||
* 📸 picture browser
|
* 📸 picture browser
|
||||||
* 📽️ video streaming
|
* 📽️ video streaming
|
||||||
* ✍️ simple text editor
|
* ✍️ simple text editor
|
||||||
* ⌨️ keyboard shortcuts
|
* ⌨️ keyboard navigation
|
||||||
* 🥂 fast golang static server, easily fills available bandwidth
|
* 🥂 fast golang static server
|
||||||
* 🔒 easy/secure multi account setup
|
* 🔒 easy/secure multi account setup, read-only mode
|
||||||
|
|
||||||
### build
|
### build
|
||||||
built blobs are available on the [release page](https://github.com/pldubouilh/gossa/releases) - or simply `make build` this repo.
|
built blobs are available on the [release page](https://github.com/pldubouilh/gossa/releases) - or simply `make build` this repo.
|
||||||
|
|
||||||
|
arch linux users can also install through the [user repos](https://aur.archlinux.org/packages/gossa/) - e.g. `yay -S gossa`
|
||||||
|
|
||||||
### usage
|
### usage
|
||||||
```sh
|
```sh
|
||||||
% ./gossa --help
|
% ./gossa --help
|
||||||
|
|
@ -33,6 +35,9 @@ built blobs are available on the [release page](https://github.com/pldubouilh/go
|
||||||
% ./gossa -h 192.168.100.33 ~/storage
|
% ./gossa -h 192.168.100.33 ~/storage
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### shortcuts
|
||||||
|
press `Ctrl/Cmd + h` to see all the UI/keyboard shortcuts.
|
||||||
|
|
||||||
### fancier setups
|
### fancier setups
|
||||||
release images are pushed to [dockerhub](https://hub.docker.com/r/pldubouilh/gossa), e.g. :
|
release images are pushed to [dockerhub](https://hub.docker.com/r/pldubouilh/gossa), e.g. :
|
||||||
|
|
||||||
|
|
@ -43,6 +48,4 @@ release images are pushed to [dockerhub](https://hub.docker.com/r/pldubouilh/gos
|
||||||
|
|
||||||
in a do-one-thing-well mindset, HTTPS and authentication has been left to middlewares and proxies. [sample caddy configs](https://github.com/pldubouilh/gossa/blob/master/support/) are available to quickly setup multi users setups along with https.
|
in a do-one-thing-well mindset, HTTPS and authentication has been left to middlewares and proxies. [sample caddy configs](https://github.com/pldubouilh/gossa/blob/master/support/) are available to quickly setup multi users setups along with https.
|
||||||
|
|
||||||
### shortcuts
|
|
||||||
the default UI is fully usable by through keyboard/UI shortcuts - press `Ctrl/Cmd + h` to see them all.
|
|
||||||
|
|
||||||
|
|
|
||||||
34
src/gossa.go
34
src/gossa.go
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"archive/zip"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
|
|
@ -147,12 +148,41 @@ func upload(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Write([]byte("ok"))
|
w.Write([]byte("ok"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func walkZip(wz *zip.Writer, fp, baseInZip string) {
|
||||||
|
files, err := ioutil.ReadDir(fp)
|
||||||
|
check(err)
|
||||||
|
|
||||||
|
for _, file := range files {
|
||||||
|
if !file.IsDir() {
|
||||||
|
data, err := ioutil.ReadFile(fp + file.Name())
|
||||||
|
check(err)
|
||||||
|
f, err := wz.Create(baseInZip + file.Name())
|
||||||
|
check(err)
|
||||||
|
_, err = f.Write(data)
|
||||||
|
check(err)
|
||||||
|
} else if file.IsDir() {
|
||||||
|
newBase := fp + file.Name() + "/"
|
||||||
|
walkZip(wz, newBase, baseInZip+file.Name()+"/")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func zipRPC(w http.ResponseWriter, r *http.Request) {
|
||||||
|
zipPath := r.URL.Query().Get("zipPath")
|
||||||
|
zipName := r.URL.Query().Get("zipName")
|
||||||
|
defer exitPath(w, "zip", zipPath)
|
||||||
|
wz := zip.NewWriter(w)
|
||||||
|
w.Header().Add("Content-Disposition", "attachment; filename=\""+zipName+".zip\"")
|
||||||
|
walkZip(wz, checkPath(zipPath)+"/", "")
|
||||||
|
wz.Close()
|
||||||
|
}
|
||||||
|
|
||||||
func rpc(w http.ResponseWriter, r *http.Request) {
|
func rpc(w http.ResponseWriter, r *http.Request) {
|
||||||
var err error
|
var err error
|
||||||
var rpc rpcCall
|
var rpc rpcCall
|
||||||
|
defer exitPath(w, "rpc", rpc)
|
||||||
bodyBytes, _ := ioutil.ReadAll(r.Body)
|
bodyBytes, _ := ioutil.ReadAll(r.Body)
|
||||||
json.Unmarshal(bodyBytes, &rpc)
|
json.Unmarshal(bodyBytes, &rpc)
|
||||||
defer exitPath(w, "rpc", rpc)
|
|
||||||
|
|
||||||
if rpc.Call == "mkdirp" {
|
if rpc.Call == "mkdirp" {
|
||||||
err = os.MkdirAll(checkPath(rpc.Args[0]), os.ModePerm)
|
err = os.MkdirAll(checkPath(rpc.Args[0]), os.ModePerm)
|
||||||
|
|
@ -197,6 +227,8 @@ func main() {
|
||||||
http.HandleFunc(*extraPath+"rpc", rpc)
|
http.HandleFunc(*extraPath+"rpc", rpc)
|
||||||
http.HandleFunc(*extraPath+"post", upload)
|
http.HandleFunc(*extraPath+"post", upload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
http.HandleFunc(*extraPath+"zip", zipRPC)
|
||||||
http.HandleFunc("/", doContent)
|
http.HandleFunc("/", doContent)
|
||||||
fs = http.StripPrefix(*extraPath, http.FileServer(http.Dir(initPath)))
|
fs = http.StripPrefix(*extraPath, http.FileServer(http.Dir(initPath)))
|
||||||
fmt.Printf("Gossa startig on directory %s\nListening on http://%s:%s%s\n", initPath, *host, *port, *extraPath)
|
fmt.Printf("Gossa startig on directory %s\nListening on http://%s:%s%s\n", initPath, *host, *port, *extraPath)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/sha256"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -24,11 +25,16 @@ func trimSpaces(str string) string {
|
||||||
return space.ReplaceAllString(str, " ")
|
return space.ReplaceAllString(str, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
func get(t *testing.T, url string) string {
|
func getRaw(t *testing.T, url string) []byte {
|
||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url)
|
||||||
dieMaybe(t, err)
|
dieMaybe(t, err)
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
dieMaybe(t, err)
|
dieMaybe(t, err)
|
||||||
|
return body
|
||||||
|
}
|
||||||
|
|
||||||
|
func get(t *testing.T, url string) string {
|
||||||
|
body := getRaw(t, url)
|
||||||
return trimSpaces(string(body))
|
return trimSpaces(string(body))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,6 +121,21 @@ func doTestRegular(t *testing.T, url string, testExtra bool) {
|
||||||
fetchAndTestDefault(t, url+path) // extra path will just redirect to root dir
|
fetchAndTestDefault(t, url+path) // extra path will just redirect to root dir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~
|
||||||
|
fmt.Println("\r\n~~~~~~~~~~ test zip")
|
||||||
|
bodyRaw := getRaw(t, url+"zip?zipPath=%2F%E4%B8%AD%E6%96%87%2F&zipName=%E4%B8%AD%E6%96%87")
|
||||||
|
hashStr := fmt.Sprintf("%x", sha256.Sum256(bodyRaw))
|
||||||
|
if hashStr != "b02436a76b149e6c4458bbbe622ab7c5e789bb0d26b87f604cf0f989cfaf669f" {
|
||||||
|
t.Fatal("invalid zip checksum", hashStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ~~~~~~~~~~~~~~~~~
|
||||||
|
fmt.Println("\r\n~~~~~~~~~~ test zip invalid path")
|
||||||
|
body0 = get(t, url+"zip?zipPath=%2Ftmp&zipName=subdir")
|
||||||
|
if body0 == `ok` {
|
||||||
|
t.Fatal("zip passed for invalid path")
|
||||||
|
}
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~
|
||||||
fmt.Println("\r\n~~~~~~~~~~ test mkdir rpc")
|
fmt.Println("\r\n~~~~~~~~~~ test mkdir rpc")
|
||||||
body0 = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["/AAA"]}`)
|
body0 = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["/AAA"]}`)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue