fix: Modify the script and upload the file name (#8538)

This commit is contained in:
ssongliu 2025-05-04 21:20:06 +08:00 committed by GitHub
parent 3533eed5f4
commit c460d9fd7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 4 deletions

View file

@ -1,9 +1,11 @@
package v2
import (
"encoding/json"
"fmt"
"path"
"strconv"
"strings"
"github.com/1Panel-dev/1Panel/core/app/api/v2/helper"
"github.com/1Panel-dev/1Panel/core/app/dto"
@ -13,7 +15,6 @@ import (
"github.com/1Panel-dev/1Panel/core/utils/terminal"
"github.com/1Panel-dev/1Panel/core/utils/xpack"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/pkg/errors"
)
@ -182,7 +183,14 @@ func (b *BaseApi) RunScript(c *gin.Context) {
}
fileDir := path.Join(installDir, "1panel/tmp/script")
fileName := path.Join(fileDir, uuid.NewString())
fileName := ""
var translations = make(map[string]string)
_ = json.Unmarshal([]byte(scriptItem.Name), &translations)
if name, ok := translations["en"]; ok {
fileName = path.Join(fileDir, strings.ReplaceAll(name, " ", "_"))
} else {
fileName = path.Join(fileDir, strings.ReplaceAll(scriptItem.Name, " ", "_"))
}
initCmd := fmt.Sprintf("mkdir -p %s && cat > %s <<'MYMARKER'\n%s\nMYMARKER\n bash %s", fileDir, fileName, scriptItem.Script, fileName)
client, err := ssh.NewClient(*connInfo)
if wshandleError(wsConn, errors.WithMessage(err, "failed to set up the connection. Please check the host information")) {

View file

@ -49,7 +49,7 @@
</el-table-column>
<el-table-column :label="$t('commons.table.group')" min-width="120" prop="group">
<template #default="{ row }">
<el-button class="mr-3" size="small" v-if="row.isSystem">system</el-button>
<el-button class="mr-3" size="small" v-if="row.isSystem">{{ $t('menu.system') }}</el-button>
<span v-if="row.groupBelong">
<el-button size="small" v-for="(item, index) in row.groupBelong" :key="index">
<span v-if="item === 'Default'">
@ -131,7 +131,7 @@ const groupOptions = ref();
const dialogGroupRef = ref();
const onOpenGroupDialog = () => {
dialogGroupRef.value!.acceptParams({ type: 'script', hideDefaultButton: true });
dialogGroupRef.value!.acceptParams({ type: 'script' });
};
const dialogRef = ref();

View file

@ -127,6 +127,15 @@ const onSubmit = async (formEl: FormInstance | undefined) => {
const loadGroupOptions = async () => {
const res = await getGroupList('script');
groupOptions.value = res.data || [];
if (dialogData.value.title !== 'create') {
return;
}
for (const group of groupOptions.value) {
if (group.isDefault) {
dialogData.value.rowData.groupList = [group.id];
break;
}
}
};
defineExpose({