-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: Modify the script and upload the file name #8538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the provided diff of Go code changes between two versions, there are several potential issues and improvements:
Here are specific lines that need attention along with suggestions: @@ -182,7 +183,14 @@
}
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, " ", "_"))
+ } This line can be refined by explicitly adding checks or comments indicating its intent or purpose: - fileName := path.Join(fileDir, uuid.NewString())
+ fileName := "" // To-be-determined filename
+ json.Unmarshal([]byte(scriptItem.Name), &translations) // Unmarshal JSON
+ name := translations["en"] // Fetch language-specific name
+ if name != "" {
+ fileName = path.Join(fileDir, strings.ReplaceAll(name, " ", "_"))
+ } else {
+ // Fallback to generic naming convention
+ fileName = path.Join(fileDir, strings.ReplaceAll(scriptItem.Name, " ", "_"))
+ } Additionally, ensure that the rest of the method properly handles cases where Overall, while not critical, these modifications address edge cases related to naming consistency and handling unexpected data formats more gracefully compared to simply discarding them. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code provided has two main areas for improvements:
These changes address the localization issues and optimize the duplication within the method call. Remember that ensuring proper localisation involves setting up an i18n framework and mapping strings accordingly across different languages. Optimization helps improve the maintainability and readability of the code, which is crucial for handling larger applications effectively. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code seems mostly correct, but here are some minor improvements to make it more concise and clear:
These changes improve readability by removing extraneous characters and adding explanatory comments that clarify the purpose each step in the function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The differences between the provided code snippet appear to be modifications specifically related to handling default group options in a component with a dynamic dialog title. Here’s an explanation of these changes:
In summary, the provided changes primarily address setting default group list entries based on specific conditions derived from the dialog’s title. These additions seem well-intentioned but could benefit from comments explaining why certain actions take place under some circumstances compared to others. Without more context around how |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The differences between the provided code snippet and its original version have been reviewed. Here are some observations:
Encoding Library Update:
import ("github.com/google/uuid")
has been removed as it's no longer used.JSON Unmarshalling:
scriptItem.Name
. This suggests that there might be additional context or formatting requirements based on translations within script names.File Naming Optimization:
Code Readability Improvements:
Potential Edge Case Handling:
Overall, the changes enhance security by removing unnecessary libraries and provide a structured way to process script names during execution. However, further optimizations may be needed depending on specific use cases related to how scripts and their names are utilized in your application.