feat: add HIDE_HISTORY option to control visibility of history page

This commit is contained in:
g.petrakis 2025-04-02 15:02:56 +03:00
parent 794cc7c474
commit 9d1c93155c
5 changed files with 42 additions and 28 deletions

View file

@ -4,28 +4,32 @@ export const Header = ({
loggedIn,
accountRegistration,
allowUnauthenticated,
hideHistory,
webroot = "",
}: {
loggedIn?: boolean;
accountRegistration?: boolean;
allowUnauthenticated?: boolean;
hideHistory?: boolean;
webroot?: string;
}) => {
let rightNav: JSX.Element;
if (loggedIn) {
rightNav = (
<ul class="flex gap-4">
<li>
<a
class={`
text-accent-600 transition-all
hover:text-accent-500 hover:underline
`}
href={`${webroot}/history`}
>
History
</a>
</li>
{!hideHistory && (
<li>
<a
class={`
text-accent-600 transition-all
hover:text-accent-500 hover:underline
`}
href={`${webroot}/history`}
>
History
</a>
</li>
)}
{!allowUnauthenticated ? (
<li>
<a

View file

@ -36,6 +36,8 @@ const ALLOW_UNAUTHENTICATED =
const AUTO_DELETE_EVERY_N_HOURS = process.env.AUTO_DELETE_EVERY_N_HOURS
? Number(process.env.AUTO_DELETE_EVERY_N_HOURS)
: 24;
const HIDE_HISTORY =
process.env.HIDE_HISTORY?.toLowerCase() === "true" || false;
const WEBROOT = process.env.WEBROOT ?? "";
@ -351,6 +353,7 @@ const app = new Elysia({
webroot={WEBROOT}
accountRegistration={ACCOUNT_REGISTRATION}
allowUnauthenticated={ALLOW_UNAUTHENTICATED}
hideHistory={HIDE_HISTORY}
/>
<main
class={`
@ -953,6 +956,10 @@ const app = new Elysia({
},
)
.get("/history", async ({ jwt, redirect, cookie: { auth } }) => {
if (HIDE_HISTORY) {
return redirect(`${WEBROOT}/`, 302);
}
if (!auth?.value) {
return redirect(`${WEBROOT}/login`, 302);
}
@ -986,6 +993,7 @@ const app = new Elysia({
<Header
webroot={WEBROOT}
allowUnauthenticated={ALLOW_UNAUTHENTICATED}
hideHistory={HIDE_HISTORY}
loggedIn
/>
<main