index.jsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 from 'react';
  16. import ReactDOM from 'react-dom/client';
  17. import { BrowserRouter } from 'react-router-dom';
  18. import '@douyinfe/semi-ui/dist/css/semi.css';
  19. import { UserProvider } from './context/User';
  20. import 'react-toastify/dist/ReactToastify.css';
  21. import { StatusProvider } from './context/Status';
  22. import { ThemeProvider } from './context/Theme';
  23. import PageLayout from './components/layout/PageLayout';
  24. import './i18n/i18n';
  25. import './index.css';
  26. import { LocaleProvider } from '@douyinfe/semi-ui';
  27. import { useTranslation } from 'react-i18next';
  28. import zh_CN from '@douyinfe/semi-ui/lib/es/locale/source/zh_CN';
  29. import en_GB from '@douyinfe/semi-ui/lib/es/locale/source/en_GB';
  30. // 欢迎信息(二次开发者未经允许不准将此移除)
  31. // Welcome message (Do not remove this without permission from the original developer)
  32. if (typeof window !== 'undefined') {
  33. console.log(
  34. '%cWE ❤ NEWAPI%c Github: https://github.com/QuantumNous/new-api',
  35. 'color: #10b981; font-weight: bold; font-size: 24px;',
  36. 'color: inherit; font-size: 14px;',
  37. );
  38. }
  39. function SemiLocaleWrapper({ children }) {
  40. const { i18n } = useTranslation();
  41. const semiLocale = React.useMemo(
  42. () => ({ zh: zh_CN, en: en_GB })[i18n.language] || zh_CN,
  43. [i18n.language],
  44. );
  45. return <LocaleProvider locale={semiLocale}>{children}</LocaleProvider>;
  46. }
  47. // initialization
  48. const root = ReactDOM.createRoot(document.getElementById('root'));
  49. root.render(
  50. <React.StrictMode>
  51. <StatusProvider>
  52. <UserProvider>
  53. <BrowserRouter
  54. future={{
  55. v7_startTransition: true,
  56. v7_relativeSplatPath: true,
  57. }}
  58. >
  59. <ThemeProvider>
  60. <SemiLocaleWrapper>
  61. <PageLayout />
  62. </SemiLocaleWrapper>
  63. </ThemeProvider>
  64. </BrowserRouter>
  65. </UserProvider>
  66. </StatusProvider>
  67. </React.StrictMode>,
  68. );