-
Notifications
You must be signed in to change notification settings - Fork 127
Fixed: Filter SFTP #4821
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
Fixed: Filter SFTP #4821
Conversation
@@ -127,7 +127,8 @@ export default { | |||
const url = this.formatterArgs.url.replace('{id}', assetId) | |||
const res = await this.$axios.get(url) | |||
|
|||
if (res) this.protocols = res.protocols | |||
// 暂将 SFTP 过滤 | |||
if (res) this.protocols = res.protocols.filter(protocol => protocol.name !== 'sftp') | |||
} catch (e) { | |||
throw new Error(`Error getting protocols: ${e}`) | |||
} |
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.
In this specific function, there's no apparent issue with the code itself; however, I'll make some recommendations to improve it.
- The
const res = await this.$axios.get(url)
line is used frequently here but should be refactored into a dedicated method likerequestProtocolInfo
. This will separate concerns and allow you to reuse parts of your logic elsewhere:
function requestProtocolInfo() {
const url = `${this.formatterArgs.url}/info`;
return new Promise((resolve, reject) => {
try {
let data;
axios.post(url, null)
.then(response => {
Object.assign(this.protocols, response.data);
resolve(response);
})
.catch(() => {reject()})
})
}
This way, the function is self-contained, reducing redundancy throughout your file
-
For clarity on what is being returned from the API when an error occurs now that the
if
block has been updated without any modifications:
-
throw new Error (error.message)// 抛出原始的错误
catch(error) {// 暂将SFTP过滤逻辑放在这个错误处理里
}
3. It might be helpful to include more context such as how exactly this information is going to be utilized at each step:
```python
export default function() {
// get all the protocols available based on the ID provided in the form element
async () => {
....
const res = this.requestProtocolInfo();// replace this if statement with its equivalent
- if (res === undefined || typeof(res) !== 'object') {
throw new Error('No protocols found')
}
+ return res
});
}
...
}
This will make it clearer why we're trying to call one function versus another depending on the result.
Remember these improvements can vary according to the specifics within project structure and needs, so adjustments could differ accordingly.
@@ -205,7 +205,6 @@ export default { | |||
formatter: AccountConnectFormatter, | |||
formatterArgs: { | |||
buttonIcon: 'fa fa-desktop', | |||
titleText: '可选协议', | |||
url: '/api/v1/assets/assets/{id}', | |||
can: () => this.currentUserIsSuperAdmin, | |||
connectUrlTemplate: (row) => `/luna/pam_connect/${row.id}/${row.username}/${row.asset.id}/${row.asset.name}/`, |
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 looks good! There aren't any potential issues or inconsistencies found. The formatting is also consistent throughout the code. If you need further assistance, feel free to ask!
|
Fixed: Filter SFTP