App.jsx 8.3 KB

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