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
Path string
Name string
Action string
Cmd string
Content string
Order int
}
@ -100,7 +100,7 @@ func (cui *ConfigUI) App(w http.ResponseWriter, r *http.Request) {
}
} else {
tmp, err = file.Read()
data.File.Action = file.Action
data.File.Cmd = file.Cmd
data.File.Name = file.Name
if file.Lang != "" {
data.Editor.Lang = file.Lang

View File

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

17
file.go
View File

@ -12,9 +12,9 @@ import (
)
type File struct {
Path string `json:"path"`
Name string `json:"name"`
Action string `json:"action"`
Path string `json:"path"`
Name string `json:"name"`
Cmd string `json:"cmd"`
// RO is readonly
RO bool `json:"ro"`
Lang string `json:"lang"`
@ -29,6 +29,9 @@ type File struct {
owner *ConfigUI `json:"-"`
run chan struct{} `json:"-"`
pid int `json:"-"`
// deprecated
Action string `json:"action,omitempty"`
}
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) {
if f.Action == "" {
if f.Cmd == "" {
return "", nil
}
f.lock.RLock()
@ -77,11 +80,11 @@ func (f *File) Do(CmdTimeout time.Duration) (string, error) {
// prepare cmd
cmd := &exec.Cmd{}
if runtime.GOOS == "windows" {
cmd = exec.Command(WIN_SHELL, "/c", f.Action)
cmd = exec.Command(WIN_SHELL, "/c", f.Cmd)
} 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)
go func() {

View File

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

View File

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

View File

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

View File

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