App.js 8.0 KB

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