Skip to content

Commit 5725856

Browse files
committed
fix: Modify the script and upload the file name
1 parent 4b5526a commit 5725856

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

core/app/api/v2/script_library.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package v2
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"path"
67
"strconv"
8+
"strings"
79

810
"github.com/1Panel-dev/1Panel/core/app/api/v2/helper"
911
"github.com/1Panel-dev/1Panel/core/app/dto"
@@ -13,7 +15,6 @@ import (
1315
"github.com/1Panel-dev/1Panel/core/utils/terminal"
1416
"github.com/1Panel-dev/1Panel/core/utils/xpack"
1517
"github.com/gin-gonic/gin"
16-
"github.com/google/uuid"
1718
"github.com/pkg/errors"
1819
)
1920

@@ -182,7 +183,14 @@ func (b *BaseApi) RunScript(c *gin.Context) {
182183
}
183184

184185
fileDir := path.Join(installDir, "1panel/tmp/script")
185-
fileName := path.Join(fileDir, uuid.NewString())
186+
fileName := ""
187+
var translations = make(map[string]string)
188+
_ = json.Unmarshal([]byte(scriptItem.Name), &translations)
189+
if name, ok := translations["en"]; ok {
190+
fileName = path.Join(fileDir, strings.ReplaceAll(name, " ", "_"))
191+
} else {
192+
fileName = path.Join(fileDir, strings.ReplaceAll(scriptItem.Name, " ", "_"))
193+
}
186194
initCmd := fmt.Sprintf("mkdir -p %s && cat > %s <<'MYMARKER'\n%s\nMYMARKER\n bash %s", fileDir, fileName, scriptItem.Script, fileName)
187195
client, err := ssh.NewClient(*connInfo)
188196
if wshandleError(wsConn, errors.WithMessage(err, "failed to set up the connection. Please check the host information")) {

frontend/src/views/cronjob/library/index.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
</el-table-column>
5050
<el-table-column :label="$t('commons.table.group')" min-width="120" prop="group">
5151
<template #default="{ row }">
52-
<el-button class="mr-3" size="small" v-if="row.isSystem">system</el-button>
52+
<el-button class="mr-3" size="small" v-if="row.isSystem">{{ $t('menu.system') }}</el-button>
5353
<span v-if="row.groupBelong">
5454
<el-button size="small" v-for="(item, index) in row.groupBelong" :key="index">
5555
<span v-if="item === 'Default'">
@@ -131,7 +131,7 @@ const groupOptions = ref();
131131
132132
const dialogGroupRef = ref();
133133
const onOpenGroupDialog = () => {
134-
dialogGroupRef.value!.acceptParams({ type: 'script', hideDefaultButton: true });
134+
dialogGroupRef.value!.acceptParams({ type: 'script' });
135135
};
136136
137137
const dialogRef = ref();

frontend/src/views/cronjob/library/operate/index.vue

+9
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ const onSubmit = async (formEl: FormInstance | undefined) => {
127127
const loadGroupOptions = async () => {
128128
const res = await getGroupList('script');
129129
groupOptions.value = res.data || [];
130+
if (dialogData.value.title === 'edit') {
131+
return;
132+
}
133+
for (const group of groupOptions.value) {
134+
if (group.isDefault) {
135+
dialogData.value.rowData.groupList = [group.id];
136+
break;
137+
}
138+
}
130139
};
131140
132141
defineExpose({

0 commit comments

Comments
 (0)