mirror of
https://github.com/pldubouilh/gossa.git
synced 2026-08-31 06:16:54 -04:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2e0396cf1 | ||
|
|
e22ef1bc12 | ||
|
|
5c9c8983e1 | ||
|
|
31775b6ae9 |
@@ -7,10 +7,10 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
- name: Set up Go 1.12
|
- name: Set up Go 1.13
|
||||||
uses: actions/setup-go@v1
|
uses: actions/setup-go@v1
|
||||||
with:
|
with:
|
||||||
go-version: 1.12
|
go-version: 1.13
|
||||||
id: go
|
id: go
|
||||||
|
|
||||||
- name: Check out code into the Go module directory
|
- name: Check out code into the Go module directory
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ build:
|
|||||||
make -C gossa-ui/
|
make -C gossa-ui/
|
||||||
go vet && go fmt
|
go vet && go fmt
|
||||||
CGO_ENABLED=0 go build gossa.go
|
CGO_ENABLED=0 go build gossa.go
|
||||||
rm gossa.go
|
sleep 1 && rm gossa.go
|
||||||
|
|
||||||
run:
|
run:
|
||||||
make build
|
make build
|
||||||
@@ -13,13 +13,23 @@ run-extra:
|
|||||||
make build
|
make build
|
||||||
./gossa -verb=true -prefix="/fancy-path/" -k=false -symlinks=true test-fixture
|
./gossa -verb=true -prefix="/fancy-path/" -k=false -symlinks=true test-fixture
|
||||||
|
|
||||||
|
test:
|
||||||
|
timeout 60 make run &
|
||||||
|
sleep 15 && cp src/gossa_test.go . && go test -run TestNormal
|
||||||
|
rm gossa_test.go
|
||||||
|
-killall gossa
|
||||||
|
|
||||||
|
test-extra:
|
||||||
|
timeout 60 make run-extra &
|
||||||
|
sleep 15 && cp src/gossa_test.go . && go test -run TestExtra
|
||||||
|
rm gossa_test.go
|
||||||
|
-killall gossa
|
||||||
|
|
||||||
ci:
|
ci:
|
||||||
-@cd test-fixture && ln -s ../support .
|
-@cd test-fixture && ln -s ../support .
|
||||||
make build
|
make test
|
||||||
timeout 15 make run &
|
make test-extra
|
||||||
sleep 16 && timeout 15 make run-extra &
|
|
||||||
cp src/gossa_test.go . && go test
|
|
||||||
rm gossa_test.go
|
|
||||||
|
|
||||||
watch:
|
watch:
|
||||||
ls src/* gossa-ui/* | entr -rc make run
|
ls src/* gossa-ui/* | entr -rc make run
|
||||||
|
|||||||
+1
-1
Submodule gossa-ui updated: cc8fff1e26...6a14c317ef
@@ -1,7 +1,7 @@
|
|||||||
gossa
|
gossa
|
||||||
=============
|
=============
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
[](https://github.com/pldubouilh/gossa/actions)
|
[](https://github.com/pldubouilh/gossa/actions)
|
||||||
[](https://hub.docker.com/r/pldubouilh/gossa)
|
[](https://hub.docker.com/r/pldubouilh/gossa)
|
||||||
|
|||||||
+6
-6
@@ -20,7 +20,6 @@ import (
|
|||||||
|
|
||||||
var host = flag.String("h", "127.0.0.1", "host to listen to")
|
var host = flag.String("h", "127.0.0.1", "host to listen to")
|
||||||
var port = flag.String("p", "8001", "port to listen to")
|
var port = flag.String("p", "8001", "port to listen to")
|
||||||
var history = flag.Bool("history", true, "keep history for paths visited. default location is path/.gossa_history")
|
|
||||||
var extraPath = flag.String("prefix", "/", "url prefix at which gossa can be reached, e.g. /gossa/ (slashes of importance)")
|
var extraPath = flag.String("prefix", "/", "url prefix at which gossa can be reached, e.g. /gossa/ (slashes of importance)")
|
||||||
var symlinks = flag.Bool("symlinks", false, "follow symlinks \033[4mWARNING\033[0m: symlinks will by nature allow to escape the defined path (default: false)")
|
var symlinks = flag.Bool("symlinks", false, "follow symlinks \033[4mWARNING\033[0m: symlinks will by nature allow to escape the defined path (default: false)")
|
||||||
var verb = flag.Bool("verb", false, "verbosity")
|
var verb = flag.Bool("verb", false, "verbosity")
|
||||||
@@ -77,9 +76,10 @@ func humanize(bytes int64) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func replyList(w http.ResponseWriter, r *http.Request, fullPath string, path string) {
|
func replyList(w http.ResponseWriter, fullPath string, path string) {
|
||||||
_files, err := ioutil.ReadDir(fullPath)
|
_files, err := ioutil.ReadDir(fullPath)
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
if !strings.HasSuffix(path, "/") {
|
if !strings.HasSuffix(path, "/") {
|
||||||
path += "/"
|
path += "/"
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,8 @@ func replyList(w http.ResponseWriter, r *http.Request, fullPath string, path str
|
|||||||
p.RowsFolders = append(p.RowsFolders, rowTemplate{el.Name() + "/", template.HTML(href), "", "folder"})
|
p.RowsFolders = append(p.RowsFolders, rowTemplate{el.Name() + "/", template.HTML(href), "", "folder"})
|
||||||
} else {
|
} else {
|
||||||
sl := strings.Split(el.Name(), ".")
|
sl := strings.Split(el.Name(), ".")
|
||||||
p.RowsFiles = append(p.RowsFiles, rowTemplate{el.Name(), template.HTML(href), humanize(el.Size()), strings.ToLower(sl[len(sl)-1])})
|
ext := strings.ToLower(sl[len(sl)-1])
|
||||||
|
p.RowsFiles = append(p.RowsFiles, rowTemplate{el.Name(), template.HTML(href), humanize(el.Size()), ext})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +126,7 @@ func doContent(w http.ResponseWriter, r *http.Request) {
|
|||||||
check(errStat)
|
check(errStat)
|
||||||
|
|
||||||
if stat.IsDir() {
|
if stat.IsDir() {
|
||||||
replyList(w, r, fullPath, path)
|
replyList(w, fullPath, path)
|
||||||
} else {
|
} else {
|
||||||
fs.ServeHTTP(w, r)
|
fs.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
@@ -147,7 +148,6 @@ func rpc(w http.ResponseWriter, r *http.Request) {
|
|||||||
bodyBytes, _ := ioutil.ReadAll(r.Body)
|
bodyBytes, _ := ioutil.ReadAll(r.Body)
|
||||||
json.Unmarshal(bodyBytes, &rpc)
|
json.Unmarshal(bodyBytes, &rpc)
|
||||||
defer exitPath(w, "rpc", rpc)
|
defer exitPath(w, "rpc", rpc)
|
||||||
ret := "ok"
|
|
||||||
|
|
||||||
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)
|
||||||
@@ -158,7 +158,7 @@ func rpc(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
check(err)
|
check(err)
|
||||||
w.Write([]byte(ret))
|
w.Write([]byte("ok"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkPath(p string) string {
|
func checkPath(p string) string {
|
||||||
|
|||||||
+5
-10
@@ -8,7 +8,6 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func dieMaybe(t *testing.T, err error) {
|
func dieMaybe(t *testing.T, err error) {
|
||||||
@@ -231,18 +230,14 @@ func doTest(t *testing.T, url string, testExtra bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetFolder(t *testing.T) {
|
func TestNormal(t *testing.T) {
|
||||||
time.Sleep(6 * time.Second)
|
|
||||||
fmt.Println("========== testing normal path ============")
|
fmt.Println("========== testing normal path ============")
|
||||||
url := "http://127.0.0.1:8001/"
|
doTest(t, "http://127.0.0.1:8001/", false)
|
||||||
doTest(t, url, false)
|
|
||||||
|
|
||||||
fmt.Printf("\r\n=========\r\n")
|
fmt.Printf("\r\n=========\r\n")
|
||||||
time.Sleep(10 * time.Second)
|
}
|
||||||
|
|
||||||
url = "http://127.0.0.1:8001/fancy-path/"
|
func TestExtra(t *testing.T) {
|
||||||
fmt.Println("========== testing at fancy path ============")
|
fmt.Println("========== testing at fancy path ============")
|
||||||
doTest(t, url, true)
|
doTest(t, "http://127.0.0.1:8001/fancy-path/", true)
|
||||||
|
|
||||||
fmt.Printf("\r\n=========\r\n")
|
fmt.Printf("\r\n=========\r\n")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user