App.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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, { lazy, Suspense } from 'react';
  16. import { Route, Routes, useLocation } from 'react-router-dom';
  17. import Loading from './components/common/ui/Loading.js';
  18. import User from './pages/User';
  19. import { AuthRedirect, PrivateRoute } from './helpers';
  20. import RegisterForm from './components/auth/RegisterForm.js';
  21. import LoginForm from './components/auth/LoginForm.js';
  22. import NotFound from './pages/NotFound';
  23. import Setting from './pages/Setting';
  24. import PasswordResetForm from './components/auth/PasswordResetForm.js';
  25. import PasswordResetConfirm from './components/auth/PasswordResetConfirm.js';
  26. import Channel from './pages/Channel';
  27. import Token from './pages/Token';
  28. import Redemption from './pages/Redemption';
  29. import TopUp from './pages/TopUp';
  30. import Log from './pages/Log';
  31. import Chat from './pages/Chat';
  32. import Chat2Link from './pages/Chat2Link';
  33. import Midjourney from './pages/Midjourney';
  34. import Pricing from './pages/Pricing/index.js';
  35. import Task from './pages/Task/index.js';
  36. import ModelPage from './pages/Model/index.js';
  37. import Playground from './pages/Playground/index.js';
  38. import OAuth2Callback from './components/auth/OAuth2Callback.js';
  39. import PersonalSetting from './components/settings/PersonalSetting.js';
  40. import Setup from './pages/Setup/index.js';
  41. import SetupCheck from './components/layout/SetupCheck.js';
  42. const Home = lazy(() => import('./pages/Home'));
  43. const Dashboard = lazy(() => import('./pages/Dashboard'));
  44. const About = lazy(() => import('./pages/About'));
  45. function App() {
  46. const location = useLocation();
  47. return (
  48. <SetupCheck>
  49. <Routes>
  50. <Route
  51. path='/'
  52. element={
  53. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  54. <Home />
  55. </Suspense>
  56. }
  57. />
  58. <Route
  59. path='/setup'
  60. element={
  61. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  62. <Setup />
  63. </Suspense>
  64. }
  65. />
  66. <Route
  67. path='/console/models'
  68. element={
  69. <PrivateRoute>
  70. <ModelPage />
  71. </PrivateRoute>
  72. }
  73. />
  74. <Route
  75. path='/console/channel'
  76. element={
  77. <PrivateRoute>
  78. <Channel />
  79. </PrivateRoute>
  80. }
  81. />
  82. <Route
  83. path='/console/token'
  84. element={
  85. <PrivateRoute>
  86. <Token />
  87. </PrivateRoute>
  88. }
  89. />
  90. <Route
  91. path='/console/playground'
  92. element={
  93. <PrivateRoute>
  94. <Playground />
  95. </PrivateRoute>
  96. }
  97. />
  98. <Route
  99. path='/console/redemption'
  100. element={
  101. <PrivateRoute>
  102. <Redemption />
  103. </PrivateRoute>
  104. }
  105. />
  106. <Route
  107. path='/console/user'
  108. element={
  109. <PrivateRoute>
  110. <User />
  111. </PrivateRoute>
  112. }
  113. />
  114. <Route
  115. path='/user/reset'
  116. element={
  117. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  118. <PasswordResetConfirm />
  119. </Suspense>
  120. }
  121. />
  122. <Route
  123. path='/login'
  124. element={
  125. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  126. <AuthRedirect>
  127. <LoginForm />
  128. </AuthRedirect>
  129. </Suspense>
  130. }
  131. />
  132. <Route
  133. path='/register'
  134. element={
  135. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  136. <AuthRedirect>
  137. <RegisterForm />
  138. </AuthRedirect>
  139. </Suspense>
  140. }
  141. />
  142. <Route
  143. path='/reset'
  144. element={
  145. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  146. <PasswordResetForm />
  147. </Suspense>
  148. }
  149. />
  150. <Route
  151. path='/oauth/github'
  152. element={
  153. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  154. <OAuth2Callback type='github'></OAuth2Callback>
  155. </Suspense>
  156. }
  157. />
  158. <Route
  159. path='/oauth/oidc'
  160. element={
  161. <Suspense fallback={<Loading></Loading>}>
  162. <OAuth2Callback type='oidc'></OAuth2Callback>
  163. </Suspense>
  164. }
  165. />
  166. <Route
  167. path='/oauth/linuxdo'
  168. element={
  169. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  170. <OAuth2Callback type='linuxdo'></OAuth2Callback>
  171. </Suspense>
  172. }
  173. />
  174. <Route
  175. path='/console/setting'
  176. element={
  177. <PrivateRoute>
  178. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  179. <Setting />
  180. </Suspense>
  181. </PrivateRoute>
  182. }
  183. />
  184. <Route
  185. path='/console/personal'
  186. element={
  187. <PrivateRoute>
  188. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  189. <PersonalSetting />
  190. </Suspense>
  191. </PrivateRoute>
  192. }
  193. />
  194. <Route
  195. path='/console/topup'
  196. element={
  197. <PrivateRoute>
  198. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  199. <TopUp />
  200. </Suspense>
  201. </PrivateRoute>
  202. }
  203. />
  204. <Route
  205. path='/console/log'
  206. element={
  207. <PrivateRoute>
  208. <Log />
  209. </PrivateRoute>
  210. }
  211. />
  212. <Route
  213. path='/console'
  214. element={
  215. <PrivateRoute>
  216. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  217. <Dashboard />
  218. </Suspense>
  219. </PrivateRoute>
  220. }
  221. />
  222. <Route
  223. path='/console/midjourney'
  224. element={
  225. <PrivateRoute>
  226. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  227. <Midjourney />
  228. </Suspense>
  229. </PrivateRoute>
  230. }
  231. />
  232. <Route
  233. path='/console/task'
  234. element={
  235. <PrivateRoute>
  236. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  237. <Task />
  238. </Suspense>
  239. </PrivateRoute>
  240. }
  241. />
  242. <Route
  243. path='/pricing'
  244. element={
  245. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  246. <Pricing />
  247. </Suspense>
  248. }
  249. />
  250. <Route
  251. path='/about'
  252. element={
  253. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  254. <About />
  255. </Suspense>
  256. }
  257. />
  258. <Route
  259. path='/console/chat/:id?'
  260. element={
  261. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  262. <Chat />
  263. </Suspense>
  264. }
  265. />
  266. {/* 方便使用chat2link直接跳转聊天... */}
  267. <Route
  268. path='/chat2link'
  269. element={
  270. <PrivateRoute>
  271. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  272. <Chat2Link />
  273. </Suspense>
  274. </PrivateRoute>
  275. }
  276. />
  277. <Route path='*' element={<NotFound />} />
  278. </Routes>
  279. </SetupCheck>
  280. );
  281. }
  282. export default App;