diff --git a/CHANGELOG.md b/CHANGELOG.md index 94e9cd9..05be076 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,13 @@ ## Feature +* download files #26 +* add goto last line toolbar #21 + ## Fix * all cmds should be pass straight back to user +* timeout on none ending cmds #34 # 0.1.1 diff --git a/api.go b/api.go index 90fa4aa..f5ac9b8 100644 --- a/api.go +++ b/api.go @@ -3,8 +3,10 @@ package main import ( "encoding/json" "io/ioutil" + "log" "net/http" "os" + "path/filepath" "kumoly.io/tools/configui/configui" ) @@ -70,6 +72,7 @@ func Apply(w http.ResponseWriter, r *http.Request) { return } result, err := file.Do() + log.Println(err) if err != nil { panic(err) } @@ -77,10 +80,36 @@ func Apply(w http.ResponseWriter, r *http.Request) { } func Download(w http.ResponseWriter, r *http.Request) { + if name := r.URL.Query().Get("name"); name != "" { + if name == "ConfigUI" { + data, err := GetConfig() + if err != nil { + panic(err) + } + w.Header().Set("Content-Disposition", `attachment; filename="ConfigUI.json"`) + w.Write(data) + return + } + file, ok := files[name] + if !ok { + MakeResponse(w, 404, []byte("file not found")) + return + } + data, err := file.Read() + if err != nil { + panic(err) + } + w.Header().Set("Content-Disposition", `attachment; filename="`+filepath.Base(file.Path)+`"`) + w.Write(data) + return + } fs := []string{} for _, v := range files { fs = append(fs, v.Path) } + if flagConfigPath != "" { + fs = append(fs, flagConfigPath) + } w.Header().Set("Content-Disposition", `attachment; filename="export.tar.gz"`) bundle(w, fs, false) } diff --git a/configui/file.go b/configui/file.go index b902260..b43d83d 100644 --- a/configui/file.go +++ b/configui/file.go @@ -8,6 +8,7 @@ import ( "os/exec" "runtime" "sync" + "time" ) var UNIX_SHELL = "sh" @@ -54,15 +55,30 @@ func (f *File) Do() (string, error) { if f.Action == "" { return "", nil } - cmd := exec.Command(UNIX_SHELL, "-c", f.Action) + timeout := time.After(2 * time.Second) + cmd := &exec.Cmd{} if runtime.GOOS == "windows" { cmd = exec.Command(WIN_SHELL, "/c", f.Action) + } else { + exec.Command(UNIX_SHELL, "-c", f.Action) + } + var out []byte + done := make(chan struct{}, 1) + go func() { + out, _ = cmd.CombinedOutput() + // real cmd err is only pass down + // if err != nil { + // return string(out), err + // } + done <- struct{}{} + }() + select { + case <-timeout: + cmd.Process.Kill() + return "", errors.New("command timeout") + case <-done: + return string(out), nil } - out, _ := cmd.CombinedOutput() - // if err != nil { - // return "", err - // } - return string(out), nil } func ReadConfig(confstr string) ([]File, error) { diff --git a/public/js/main.js b/public/js/main.js index a029722..c6ea147 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -58,7 +58,8 @@ async function FileApply(){ method: 'POST', }) if(!res.ok){ - handleError(res) + const result = await handleError(res) + result_editor.session.setValue(result) return } const result = await res.text() @@ -69,6 +70,7 @@ async function FileApply(){ async function handleError(res){ const msg = await res.text() ShowError(msg) + return msg } // starting point diff --git a/release.sh b/release.sh index e69de29..176236e 100644 --- a/release.sh +++ b/release.sh @@ -0,0 +1,19 @@ +VERSION=$(git describe --tags --abbrev=0) +BUILD=$(git rev-parse --short HEAD) +PROJ=$(basename "$(PWD)") +HUB=hub.kumoly.io +HUB_PROJECT=tools +LDFLAGS='-ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD} -w"' + +PLATFORMS='darwin linux' +ARCHITECTURES=amd64 +APPS=configui + +echo $LDFLAGS + +build(){ + foreach GOOS $1 + echo $GOOS +} + +build $PLATFORMS \ No newline at end of file diff --git a/src/ace.scss b/src/ace.scss index 6f25add..b0ef414 100644 --- a/src/ace.scss +++ b/src/ace.scss @@ -3,8 +3,15 @@ // } #editor,#result_editor { - height: 75vh; font-size: 1rem; position: relative; width: inherit !important; } + +#editor { + height: 70vh; +} + +#result_editor { + min-height: 50vh; +} diff --git a/src/main.scss b/src/main.scss index 81692c6..5ce04b7 100644 --- a/src/main.scss +++ b/src/main.scss @@ -12,6 +12,10 @@ $modal-content-width: 90vw; position: fixed; /* Sit on top of the page content */ top: 1; left: 50%; - z-index: 2; + z-index: 50; transform: translateX(-50%) +} + +#title { + padding: 0.5rem; } \ No newline at end of file diff --git a/templates/components/editor.tmpl b/templates/components/editor.tmpl index cc3cb44..ede66ed 100644 --- a/templates/components/editor.tmpl +++ b/templates/components/editor.tmpl @@ -1,9 +1,9 @@ {{define "components/editor"}} {{template "components/toolbar" .}} - +
{{.File.Content}}
-
+
-
+

ConfigUI

@@ -19,7 +19,7 @@ var Active = "{{.File.Alias}}"; {{template "components/menu" .}}