Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions frontend/src/views/app-store/installed/detail/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ import { getAppInstallParams, updateAppInstallParams, updateInstallConfig } from
import { reactive, ref } from 'vue';
import { FormInstance } from 'element-plus';
import { Rules, checkNumberRange } from '@/global/form-rules';
import { MsgSuccess } from '@/utils/message';
import { getLabel, splitHttp } from '@/utils/util';
import { MsgError, MsgSuccess } from '@/utils/message';
import { getLabel, splitHttp, checkIpV4V6, checkDomain } from '@/utils/util';
import i18n from '@/lang';
interface ParamProps {
Expand Down Expand Up @@ -176,6 +176,31 @@ const webUI = reactive({
domain: '',
});
function checkWebUI() {
if (webUI.domain !== '') {
let domain = webUI.domain;
let port = null;
if (domain.includes(':')) {
const parts = domain.split(':');
domain = parts[0];
port = parts[1];
if (!checkPort(port)) {
return false;
}
}
if (checkIpV4V6(domain) && checkDomain(domain)) {
return false;
}
}
return true;
}
function checkPort(port: string) {
const portNum = parseInt(port, 10);
return !isNaN(portNum) && portNum > 0 && portNum <= 65535;
}
const acceptParams = async (props: ParamProps) => {
submitModel.value.installId = props.id;
params.value = [];
Expand Down Expand Up @@ -297,6 +322,10 @@ const updateAppConfig = async () => {
if (!webUI.domain || webUI.domain === '') {
req.webUI = '';
}
if (!checkWebUI()) {
MsgError(i18n.global.t('commons.rule.host'));
return;
}
await updateInstallConfig(req);
MsgSuccess(i18n.global.t('commons.msg.updateSuccess'));
handleClose();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the changes have been suggested to improve readability and maintainability:

  1. In acceptParams, add a line to log parameters before updating:
params.value = [];
console.log("Received params:", JSON.stringify(props));
  1. Update comment style consistency:
// Potential issue: The comments on lines 114, 129, and 165 should be consistent about their content type (e.g., all function docs).

Replace with something like:

/*
 * Function description goes here...
 */
  1. Add spacing after commas in imports and declarations:
import { reactive, ref } from 'vue';
+import { FormInstance } from 'element-plus';

interface ParamProps {
  // ...
}

let webUI = reactive({
  serverUrl: '',
  username: '',
  password: '',
  domainName: '',

+ isDeployed: true,
});
  1. Refactor check functions:
  • Rename MsgError to showErrorMessage for clarity.
  • Move duplicate if (!check...) {} else return false; checks into separate functions.

Here's an optimized version:

function showErrorMessage(message) {
  MsgError(i18n.global.t(`commons.msg.${message}`));
  throw new Error(); // Or some other mechanism to indicate failure
}

async function validateWebUI() {
  if (!webUI.domain || webUI.domain === '') {
    showErrorMessage('emptyHost');  
  }

  try {
    const [host, port] = webUI.domain.split(':').map(item => item.trim());

    if (!/^\d+$/.test(port)) {
      showErrorMessage('invalidPort');  
    }

    if (!(await checkIpAddressOrDomain(host)) || !isHostValid(port)) {
      showErrorMessage('invalidHost');  
    }
  } catch (error) {
    console.error(error);    
  } finally {
    return !!webUI.domain;
  }
}

const acceptParams = async (props: ParamProps): Promise<void> => {
    submitModel.value.installId = props.id;

    let errorOccurred = false;
    if (!validateWebUI()) {
        errorOccurred = true;
    }
    // Continue processing based on validation errors
};

Additional notes: Ensure that checkIpAddressOrDomain and isHostValid are implemented correctly according to your specific needs. Always include proper comments and documentation for these functions to avoid future maintenance challenges.

Expand Down
Loading