PerformanceSetting.jsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. Copyright (C) 2025 QuantumNous
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial licensing, please contact support@quantumnous.com
  14. */
  15. import React, { useEffect, useState } from 'react';
  16. import { Card, Spin } from '@douyinfe/semi-ui';
  17. import SettingsPerformance from '../../pages/Setting/Performance/SettingsPerformance';
  18. import { API, showError, toBoolean } from '../../helpers';
  19. const PerformanceSetting = () => {
  20. let [inputs, setInputs] = useState({
  21. 'performance_setting.disk_cache_enabled': false,
  22. 'performance_setting.disk_cache_threshold_mb': 10,
  23. 'performance_setting.disk_cache_max_size_mb': 1024,
  24. 'performance_setting.disk_cache_path': '',
  25. });
  26. let [loading, setLoading] = useState(false);
  27. const getOptions = async () => {
  28. const res = await API.get('/api/option/');
  29. const { success, message, data } = res.data;
  30. if (success) {
  31. let newInputs = {};
  32. data.forEach((item) => {
  33. if (typeof inputs[item.key] === 'boolean') {
  34. newInputs[item.key] = toBoolean(item.value);
  35. } else {
  36. newInputs[item.key] = item.value;
  37. }
  38. });
  39. setInputs(newInputs);
  40. } else {
  41. showError(message);
  42. }
  43. };
  44. async function onRefresh() {
  45. try {
  46. setLoading(true);
  47. await getOptions();
  48. } catch (error) {
  49. showError('刷新失败');
  50. } finally {
  51. setLoading(false);
  52. }
  53. }
  54. useEffect(() => {
  55. onRefresh();
  56. }, []);
  57. return (
  58. <>
  59. <Spin spinning={loading} size='large'>
  60. {/* 性能设置 */}
  61. <Card style={{ marginTop: '10px' }}>
  62. <SettingsPerformance options={inputs} refresh={onRefresh} />
  63. </Card>
  64. </Spin>
  65. </>
  66. );
  67. };
  68. export default PerformanceSetting;