From 6eebd16ab61cd81ea786f030d1e31ad1f15f030b Mon Sep 17 00:00:00 2001 From: Szymon Uglis Date: Thu, 21 Nov 2024 18:09:25 +0100 Subject: [PATCH] Pass only needed parameters for template --- lib/src/settings.dart | 2 ++ lib/src/web_app/api_server.dart | 15 +++++++++++++-- templates/component/alert.html | 3 +++ templates/guilds.html | 4 +--- templates/index.html | 4 +--- 5 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 templates/component/alert.html diff --git a/lib/src/settings.dart b/lib/src/settings.dart index 5bae0b1..9ec16d9 100644 --- a/lib/src/settings.dart +++ b/lib/src/settings.dart @@ -67,6 +67,8 @@ __Package repositories__: ${docsPackages.map((packageName) => '- $packageName: ').join('\n')} '''); +final String webServerAlertContent = getEnv('WEB_SERVER_ALERT_CONTENT', 'Experimental version'); + /// The GitHub account to use when no other account is specified. final String githubAccount = getEnv('ROD_GITHUB_ACCOUNT', 'nyxx-discord'); diff --git a/lib/src/web_app/api_server.dart b/lib/src/web_app/api_server.dart index 4d62384..fc0b3a7 100644 --- a/lib/src/web_app/api_server.dart +++ b/lib/src/web_app/api_server.dart @@ -51,10 +51,21 @@ class WebServer { return shelf.Response.badRequest(); } + final additionalParameters = switch (templateName) { + 'navigation' => { + 'clientId': clientId, + 'redirectUri': clientRedirectUri, + }, + 'alert' => { + 'inner_content': webServerAlertContent, + }, + _ => {}, + }; + + return createTwigResponse('component/$templateName.html', parameters: { ...getCustomDataFromSession(request), - 'clientId': clientId, - 'redirectUri': clientRedirectUri, + ...additionalParameters, }); } diff --git a/templates/component/alert.html b/templates/component/alert.html new file mode 100644 index 0000000..9cbd30e --- /dev/null +++ b/templates/component/alert.html @@ -0,0 +1,3 @@ + diff --git a/templates/guilds.html b/templates/guilds.html index 749a508..1639251 100644 --- a/templates/guilds.html +++ b/templates/guilds.html @@ -11,9 +11,7 @@
- +
diff --git a/templates/index.html b/templates/index.html index 5f2e8e0..0b78969 100644 --- a/templates/index.html +++ b/templates/index.html @@ -11,9 +11,7 @@
- +