mirror of
				https://github.com/songquanpeng/one-api.git
				synced 2025-11-04 15:53:42 +08:00 
			
		
		
		
	fix: fix option update logic not working properly
This commit is contained in:
		@@ -12,7 +12,6 @@ const OtherSetting = () => {
 | 
			
		||||
    Logo: '',
 | 
			
		||||
    HomePageContent: '',
 | 
			
		||||
  });
 | 
			
		||||
  let originInputs = {};
 | 
			
		||||
  let [loading, setLoading] = useState(false);
 | 
			
		||||
  const [showUpdateModal, setShowUpdateModal] = useState(false);
 | 
			
		||||
  const [updateData, setUpdateData] = useState({
 | 
			
		||||
@@ -21,7 +20,7 @@ const OtherSetting = () => {
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  const getOptions = async () => {
 | 
			
		||||
    const res = await API.get('/api/option');
 | 
			
		||||
    const res = await API.get('/api/option/');
 | 
			
		||||
    const { success, message, data } = res.data;
 | 
			
		||||
    if (success) {
 | 
			
		||||
      let newInputs = {};
 | 
			
		||||
@@ -31,7 +30,6 @@ const OtherSetting = () => {
 | 
			
		||||
        }
 | 
			
		||||
      });
 | 
			
		||||
      setInputs(newInputs);
 | 
			
		||||
      originInputs = newInputs;
 | 
			
		||||
    } else {
 | 
			
		||||
      showError(message);
 | 
			
		||||
    }
 | 
			
		||||
@@ -43,7 +41,7 @@ const OtherSetting = () => {
 | 
			
		||||
 | 
			
		||||
  const updateOption = async (key, value) => {
 | 
			
		||||
    setLoading(true);
 | 
			
		||||
    const res = await API.put('/api/option', {
 | 
			
		||||
    const res = await API.put('/api/option/', {
 | 
			
		||||
      key,
 | 
			
		||||
      value,
 | 
			
		||||
    });
 | 
			
		||||
 
 | 
			
		||||
@@ -27,16 +27,17 @@ const SystemSetting = () => {
 | 
			
		||||
    TurnstileSecretKey: '',
 | 
			
		||||
    RegisterEnabled: '',
 | 
			
		||||
    QuotaForNewUser: 0,
 | 
			
		||||
    QuotaRemindThreshold: 0,
 | 
			
		||||
    ModelRatio: '',
 | 
			
		||||
    TopUpLink: '',
 | 
			
		||||
    AutomaticDisableChannelEnabled: '',
 | 
			
		||||
    ChannelDisableThreshold: 0,
 | 
			
		||||
  });
 | 
			
		||||
  let originInputs = {};
 | 
			
		||||
  const [originInputs, setOriginInputs] = useState({});
 | 
			
		||||
  let [loading, setLoading] = useState(false);
 | 
			
		||||
 | 
			
		||||
  const getOptions = async () => {
 | 
			
		||||
    const res = await API.get('/api/option');
 | 
			
		||||
    const res = await API.get('/api/option/');
 | 
			
		||||
    const { success, message, data } = res.data;
 | 
			
		||||
    if (success) {
 | 
			
		||||
      let newInputs = {};
 | 
			
		||||
@@ -44,7 +45,7 @@ const SystemSetting = () => {
 | 
			
		||||
        newInputs[item.key] = item.value;
 | 
			
		||||
      });
 | 
			
		||||
      setInputs(newInputs);
 | 
			
		||||
      originInputs = newInputs;
 | 
			
		||||
      setOriginInputs(newInputs);
 | 
			
		||||
    } else {
 | 
			
		||||
      showError(message);
 | 
			
		||||
    }
 | 
			
		||||
@@ -70,7 +71,7 @@ const SystemSetting = () => {
 | 
			
		||||
      default:
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    const res = await API.put('/api/option', {
 | 
			
		||||
    const res = await API.put('/api/option/', {
 | 
			
		||||
      key,
 | 
			
		||||
      value
 | 
			
		||||
    });
 | 
			
		||||
@@ -96,6 +97,7 @@ const SystemSetting = () => {
 | 
			
		||||
      name === 'TurnstileSiteKey' ||
 | 
			
		||||
      name === 'TurnstileSecretKey' ||
 | 
			
		||||
      name === 'QuotaForNewUser' ||
 | 
			
		||||
      name === 'QuotaRemindThreshold' ||
 | 
			
		||||
      name === 'ModelRatio' ||
 | 
			
		||||
      name === 'TopUpLink'
 | 
			
		||||
    ) {
 | 
			
		||||
@@ -114,6 +116,9 @@ const SystemSetting = () => {
 | 
			
		||||
    if (originInputs['QuotaForNewUser'] !== inputs.QuotaForNewUser) {
 | 
			
		||||
      await updateOption('QuotaForNewUser', inputs.QuotaForNewUser);
 | 
			
		||||
    }
 | 
			
		||||
    if (originInputs['QuotaRemindThreshold'] !== inputs.QuotaRemindThreshold) {
 | 
			
		||||
      await updateOption('QuotaRemindThreshold', inputs.QuotaRemindThreshold);
 | 
			
		||||
    }
 | 
			
		||||
    if (originInputs['ModelRatio'] !== inputs.ModelRatio) {
 | 
			
		||||
      if (!verifyJSON(inputs.ModelRatio)) {
 | 
			
		||||
        showError('模型倍率不是合法的 JSON 字符串');
 | 
			
		||||
@@ -287,6 +292,16 @@ const SystemSetting = () => {
 | 
			
		||||
              type='link'
 | 
			
		||||
              placeholder='例如发卡网站的购买链接'
 | 
			
		||||
            />
 | 
			
		||||
            <Form.Input
 | 
			
		||||
              label='额度提醒阈值'
 | 
			
		||||
              name='QuotaRemindThreshold'
 | 
			
		||||
              onChange={handleInputChange}
 | 
			
		||||
              autoComplete='new-password'
 | 
			
		||||
              value={inputs.QuotaRemindThreshold}
 | 
			
		||||
              type='number'
 | 
			
		||||
              min='0'
 | 
			
		||||
              placeholder='低于此额度时将发送邮件提醒用户'
 | 
			
		||||
            />
 | 
			
		||||
          </Form.Group>
 | 
			
		||||
          <Form.Group widths='equal'>
 | 
			
		||||
            <Form.TextArea
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user