Skip to content

Conversation

fit2bot
Copy link
Contributor

@fit2bot fit2bot commented Mar 17, 2025

Fixed: Filter SFTP

@@ -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}`)
}
Copy link
Member

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.

  1. The const res = await this.$axios.get(url) line is used frequently here but should be refactored into a dedicated method like requestProtocolInfo. 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

  1. 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:

  •  catch(error) {// 暂将SFTP过滤逻辑放在这个错误处理里
    
    throw new Error (error.message)// 抛出原始的错误
    }

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.

@fit2bot fit2bot requested a review from a team March 17, 2025 08:35
@@ -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}/`,
Copy link
Member

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!

@ZhaoJiSen ZhaoJiSen merged commit f1a79cc into dev Mar 17, 2025
3 of 4 checks passed
@ZhaoJiSen ZhaoJiSen deleted the pr@dev@fix_filter_sftp branch March 17, 2025 08:35
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants