From d79c2f26888b512faaa0526936b8752cfb6c8b28 Mon Sep 17 00:00:00 2001
From: tobi <31960611+tsmethurst@users.noreply.github.com>
Date: Mon, 3 Jun 2024 11:20:53 +0200
Subject: [feature/frontend] Add debug sections to settings panel (#2950)

* [feature/frontend] Add debug sections to settings panel

* max-width

* swagger
---
 web/source/settings/views/admin/router.tsx | 33 +++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

(limited to 'web/source/settings/views/admin/router.tsx')

diff --git a/web/source/settings/views/admin/router.tsx b/web/source/settings/views/admin/router.tsx
index 92cd7ac33..d1240adc3 100644
--- a/web/source/settings/views/admin/router.tsx
+++ b/web/source/settings/views/admin/router.tsx
@@ -18,7 +18,7 @@
 */
 
 import React from "react";
-import { BaseUrlContext, useBaseUrl, useHasPermission } from "../../lib/navigation/util";
+import { BaseUrlContext, useBaseUrl, useHasPermission, useInstanceDebug } from "../../lib/navigation/util";
 import { Redirect, Route, Router, Switch } from "wouter";
 import { ErrorBoundary } from "../../lib/navigation/error";
 import InstanceSettings from "./instance/settings";
@@ -32,6 +32,8 @@ import RemoteEmoji from "./emoji/remote";
 import HeaderPermsOverview from "./http-header-permissions/overview";
 import HeaderPermDetail from "./http-header-permissions/detail";
 import Email from "./actions/email";
+import ApURL from "./debug/apurl";
+import Caches from "./debug/caches";
 
 /*
 	EXPORTED COMPONENTS
@@ -53,6 +55,7 @@ import Email from "./actions/email";
  * - /settings/admin/http-header-permissions/allows/:allowId
  * - /settings/admin/http-header-permissions/blocks
  * - /settings/admin/http-header-permissions/blocks/:blockId
+ * - /settings/admin/debug
  */
 export default function AdminRouter() {
 	const parentUrl = useBaseUrl();
@@ -66,6 +69,7 @@ export default function AdminRouter() {
 				<AdminEmojisRouter />
 				<AdminActionsRouter />
 				<AdminHTTPHeaderPermissionsRouter />
+				<AdminDebugRouter />
 			</Router>
 		</BaseUrlContext.Provider>
 	);
@@ -186,3 +190,30 @@ function AdminHTTPHeaderPermissionsRouter() {
 		</BaseUrlContext.Provider>
 	);
 }
+
+function AdminDebugRouter() {
+	const parentUrl = useBaseUrl();
+	const thisBase = "/debug";
+	const absBase = parentUrl + thisBase;
+
+	// Don't attach this route if instance
+	// is not running in debug mode.
+	const debug = useInstanceDebug();
+	if (!debug) {
+		return null;
+	}
+
+	return (
+		<BaseUrlContext.Provider value={absBase}>
+			<Router base={thisBase}>
+				<ErrorBoundary>
+					<Switch>
+						<Route path="/apurl" component={ApURL} />
+						<Route path="/caches" component={Caches} />
+						<Route><Redirect to="/apurl" /></Route>
+					</Switch>
+				</ErrorBoundary>
+			</Router>
+		</BaseUrlContext.Provider>
+	);
+}
-- 
cgit v1.2.3

