-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: Fix the problem that jumping to a directory that does not exist … #8353
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 |
|---|---|---|
|
|
@@ -49,8 +49,8 @@ export const SaveFileContent = (params: File.FileEdit) => { | |
| return http.post<File.File>('files/save', params); | ||
| }; | ||
|
|
||
| export const CheckFile = (path: string) => { | ||
| return http.post<boolean>('files/check', { path: path }); | ||
| export const CheckFile = (path: string, withInit: boolean) => { | ||
| return http.post<boolean>('files/check', { path: path, withInit: withInit }); | ||
| }; | ||
|
|
||
| export const BatchCheckFiles = (paths: string[]) => { | ||
|
Member
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 provided code contains a minor issue in the
Overall, the main difference is simply adding another attribute to one of the function parameters and not altering the return type or logic significantly. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,8 +60,9 @@ import DrawerHeader from '@/components/drawer-header/index.vue'; | |
| import { snapshotImport } from '@/api/modules/setting'; | ||
| import { getBackupList, getFilesFromBackup } from '@/api/modules/setting'; | ||
| import { Rules } from '@/global/form-rules'; | ||
| import { MsgSuccess } from '@/utils/message'; | ||
| import { MsgError, MsgSuccess } from '@/utils/message'; | ||
| import router from '@/routers'; | ||
| import { CheckFile } from '@/api/modules/files'; | ||
|
|
||
| const drawerVisible = ref(false); | ||
| const loading = ref(); | ||
|
|
@@ -109,7 +110,12 @@ const checkDisable = (val: string) => { | |
| return false; | ||
| }; | ||
| const toFolder = async () => { | ||
| router.push({ path: '/hosts/files', query: { path: backupPath.value } }); | ||
| const res = await CheckFile(backupPath.value, true); | ||
| if (res.data) { | ||
| router.push({ path: '/hosts/files', query: { path: backupPath.value } }); | ||
| } else { | ||
| MsgError(i18n.global.t('file.noSuchFile')); | ||
| } | ||
| }; | ||
|
|
||
| const submitImport = async (formEl: FormInstance | undefined) => { | ||
|
Member
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.
These changes improve robustness of your application, ensuring better user experience in certain situations where there may be issues with the data being processed. |
||
|
|
||
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 code appears to be designed for checking whether a file exists at the specified path or creating it if necessary. However, there are a few areas that could be improved:
Simplify Error Handling: The error handling logic is somewhat repetitive. Instead of repeating
helper.SuccessWithData(c, false)multiple times inside different branches of the conditional statements, consider consolidating those into a single call after detecting an error.By making these improvements, the code will be clearer, maintainable, and less prone to errors.