fix: deprecate 'action' and use 'cmd' in file

feat/muzan
Evan Chen 2021-11-11 10:21:10 +08:00
parent acec4a6af9
commit 4415ffe2ee
7 changed files with 32 additions and 23 deletions

4
app.go
View File

@ -12,7 +12,7 @@ type ActiveFile struct {
RO bool RO bool
Path string Path string
Name string Name string
Action string Cmd string
Content string Content string
Order int Order int
} }
@ -100,7 +100,7 @@ func (cui *ConfigUI) App(w http.ResponseWriter, r *http.Request) {
} }
} else { } else {
tmp, err = file.Read() tmp, err = file.Read()
data.File.Action = file.Action data.File.Cmd = file.Cmd
data.File.Name = file.Name data.File.Name = file.Name
if file.Lang != "" { if file.Lang != "" {
data.Editor.Lang = file.Lang data.Editor.Lang = file.Lang

View File

@ -139,6 +139,12 @@ func (cui *ConfigUI) LoadConfig(confstr string) error {
} }
f.owner = cui f.owner = cui
tmpIndex[f.Name] = i tmpIndex[f.Name] = i
// deprecated fix
if f.Cmd == "" && f.Action != "" {
f.Cmd = f.Action
f.Action = ""
}
} }
// copy // copy

13
file.go
View File

@ -14,7 +14,7 @@ import (
type File struct { type File struct {
Path string `json:"path"` Path string `json:"path"`
Name string `json:"name"` Name string `json:"name"`
Action string `json:"action"` Cmd string `json:"cmd"`
// RO is readonly // RO is readonly
RO bool `json:"ro"` RO bool `json:"ro"`
Lang string `json:"lang"` Lang string `json:"lang"`
@ -29,6 +29,9 @@ type File struct {
owner *ConfigUI `json:"-"` owner *ConfigUI `json:"-"`
run chan struct{} `json:"-"` run chan struct{} `json:"-"`
pid int `json:"-"` pid int `json:"-"`
// deprecated
Action string `json:"action,omitempty"`
} }
func (f *File) Read() ([]byte, error) { func (f *File) Read() ([]byte, error) {
@ -56,7 +59,7 @@ func (f *File) Write(data []byte) error {
} }
func (f *File) Do(CmdTimeout time.Duration) (string, error) { func (f *File) Do(CmdTimeout time.Duration) (string, error) {
if f.Action == "" { if f.Cmd == "" {
return "", nil return "", nil
} }
f.lock.RLock() f.lock.RLock()
@ -77,11 +80,11 @@ func (f *File) Do(CmdTimeout time.Duration) (string, error) {
// prepare cmd // prepare cmd
cmd := &exec.Cmd{} cmd := &exec.Cmd{}
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
cmd = exec.Command(WIN_SHELL, "/c", f.Action) cmd = exec.Command(WIN_SHELL, "/c", f.Cmd)
} else { } else {
cmd = exec.Command(UNIX_SHELL, "-c", f.Action) cmd = exec.Command(UNIX_SHELL, "-c", f.Cmd)
} }
f.owner.log.Info("DO: ", f.Action) f.owner.log.Info("DO: ", f.Cmd)
done := make(chan string, 1) done := make(chan string, 1)
go func() { go func() {

View File

@ -39,7 +39,7 @@ func (cui *ConfigUI) GetFile(w http.ResponseWriter, r *http.Request) {
response, err := json.Marshal(map[string]string{ response, err := json.Marshal(map[string]string{
"path": file.Path, "path": file.Path,
"name": file.Name, "name": file.Name,
"action": file.Action, "cmd": file.Cmd,
"data": string(data), "data": string(data),
"delta": strconv.Itoa(int(stat.Size())), "delta": strconv.Itoa(int(stat.Size())),
}) })
@ -83,7 +83,7 @@ func (cui *ConfigUI) GetDelta(w http.ResponseWriter, r *http.Request) {
response, err := json.Marshal(map[string]string{ response, err := json.Marshal(map[string]string{
"path": file.Path, "path": file.Path,
"name": file.Name, "name": file.Name,
"action": file.Action, "cmd": file.Cmd,
"data": string(buf), "data": string(buf),
"delta": strconv.Itoa(int(stat.Size())), "delta": strconv.Itoa(int(stat.Size())),
}) })

View File

@ -21,7 +21,7 @@
<ul class="menu-list"> <ul class="menu-list">
<li> <li>
<a class="has-tooltip-arrow {{if eq .File.Name .AppName }}is-active{{end}}" <a class="has-tooltip-arrow {{if eq .File.Name .AppName }}is-active{{end}}"
data-tooltip="{{$.File.Path}}" data-tooltip="Configuration"
href="{{.BaseUrl}}" href="{{.BaseUrl}}"
>Config</a></li> >Config</a></li>
</ul> </ul>

View File

@ -7,7 +7,7 @@
<button class="delete" aria-label="close" onclick="ResultViewTog()"></button> <button class="delete" aria-label="close" onclick="ResultViewTog()"></button>
</header> </header>
<section class="modal-card-body"> <section class="modal-card-body">
<p class="title">{{.File.Action}}</p> <p class="title">{{.File.Cmd}}</p>
<p class="subtitle">{{.File.Path}}</p> <p class="subtitle">{{.File.Path}}</p>
<div id="result_editor"></div> <div id="result_editor"></div>
</section> </section>

View File

@ -91,10 +91,10 @@
{{end}} {{end}}
</p> </p>
{{end}} {{end}}
{{if .File.Action}} {{if .File.Cmd}}
<p class="control"> <p class="control">
<button class="button is-small has-tooltip-arrow" <button class="button is-small has-tooltip-arrow"
data-tooltip="{{.File.Action}}" data-tooltip="{{.File.Cmd}}"
onclick="toolApply()"> onclick="toolApply()">
<span class="icon is-small"><span class="material-icons"id="toolApplyIco"> <span class="icon is-small"><span class="material-icons"id="toolApplyIco">
play_arrow play_arrow