Skip to content

Commit

Permalink
chore: remove trailing slash when submitting
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed Nov 23, 2022
1 parent fd32554 commit 080ec29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 8 additions & 8 deletions web/src/components/SystemSetting.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';
import { Divider, Form, Grid, Header, Message } from 'semantic-ui-react';
import { API, showError } from '../helpers';
import { API, removeTrailingSlash, showError } from '../helpers';

const SystemSetting = () => {
let [inputs, setInputs] = useState({
Expand Down Expand Up @@ -95,10 +95,7 @@ const SystemSetting = () => {
};

const submitServerAddress = async () => {
let ServerAddress = inputs.ServerAddress;
if (ServerAddress.endsWith('/')) {
ServerAddress = ServerAddress.slice(0, ServerAddress.length - 1);
}
let ServerAddress = removeTrailingSlash(inputs.ServerAddress);
await updateOption('ServerAddress', ServerAddress);
};

Expand All @@ -119,7 +116,10 @@ const SystemSetting = () => {

const submitWeChat = async () => {
if (originInputs['WeChatServerAddress'] !== inputs.WeChatServerAddress) {
await updateOption('WeChatServerAddress', inputs.WeChatServerAddress);
await updateOption(
'WeChatServerAddress',
removeTrailingSlash(inputs.WeChatServerAddress)
);
}
if (
originInputs['WeChatAccountQRCodeImageURL'] !==
Expand Down Expand Up @@ -170,7 +170,7 @@ const SystemSetting = () => {
<Form.Group widths='equal'>
<Form.Input
label='服务器地址'
placeholder='例如:https://yourdomain.com(注意没有最后的斜杠)'
placeholder='例如:https://yourdomain.com'
value={inputs.ServerAddress}
name='ServerAddress'
onChange={handleInputChange}
Expand Down Expand Up @@ -316,7 +316,7 @@ const SystemSetting = () => {
<Form.Input
label='WeChat Server 服务器地址'
name='WeChatServerAddress'
placeholder='例如:https://yourdomain.com(注意没有最后的斜杠)'
placeholder='例如:https://yourdomain.com'
onChange={handleInputChange}
autoComplete='off'
value={inputs.WeChatServerAddress}
Expand Down
8 changes: 8 additions & 0 deletions web/src/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,11 @@ export function showNotice(message) {
export function openPage(url) {
window.open(url);
}

export function removeTrailingSlash(url) {
if (url.endsWith('/')) {
return url.slice(0, -1);
} else {
return url;
}
}

0 comments on commit 080ec29

Please sign in to comment.