From a8ffbc87d1a179a7a974125931dbbf9bf1daed23 Mon Sep 17 00:00:00 2001
From: daniel31x13
Date: Thu, 18 Jul 2024 16:29:59 -0400
Subject: [PATCH] UI improvements
---
.env.sample | 4 +-
pages/api/v1/archives/[linkId].ts | 2 +-
pages/api/v1/auth/forgot-password.ts | 2 +-
pages/api/v1/auth/reset-password.ts | 2 +-
pages/api/v1/auth/verify-email.ts | 2 +-
pages/api/v1/collections/[id].ts | 4 +-
pages/api/v1/collections/index.ts | 2 +-
pages/api/v1/links/[id]/archive/index.ts | 2 +-
pages/api/v1/links/[id]/index.ts | 4 +-
pages/api/v1/links/index.ts | 6 +--
pages/api/v1/migration/index.ts | 2 +-
pages/api/v1/tags/[id].ts | 4 +-
pages/api/v1/tokens/[id].ts | 2 +-
pages/api/v1/tokens/index.ts | 2 +-
pages/api/v1/users/[id].ts | 4 +-
pages/api/v1/users/index.ts | 2 +-
pages/login.tsx | 60 ++++++++++++++++++++++++
17 files changed, 84 insertions(+), 22 deletions(-)
diff --git a/.env.sample b/.env.sample
index 2993c39..22bda55 100644
--- a/.env.sample
+++ b/.env.sample
@@ -21,7 +21,9 @@ BROWSER_TIMEOUT=
IGNORE_UNAUTHORIZED_CA=
IGNORE_HTTPS_ERRORS=
IGNORE_URL_SIZE_LIMIT=
-DEMO_MODE=
+NEXT_PUBLIC_DEMO=
+NEXT_PUBLIC_DEMO_USERNAME=
+NEXT_PUBLIC_DEMO_PASSWORD=
NEXT_PUBLIC_ADMIN=
NEXT_PUBLIC_MAX_FILE_BUFFER=
MONOLITH_MAX_BUFFER=
diff --git a/pages/api/v1/archives/[linkId].ts b/pages/api/v1/archives/[linkId].ts
index cf044b1..aed8288 100644
--- a/pages/api/v1/archives/[linkId].ts
+++ b/pages/api/v1/archives/[linkId].ts
@@ -77,7 +77,7 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {
return res.send(file);
}
} else if (req.method === "POST") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
diff --git a/pages/api/v1/auth/forgot-password.ts b/pages/api/v1/auth/forgot-password.ts
index 1728365..66fb807 100644
--- a/pages/api/v1/auth/forgot-password.ts
+++ b/pages/api/v1/auth/forgot-password.ts
@@ -7,7 +7,7 @@ export default async function forgotPassword(
res: NextApiResponse
) {
if (req.method === "POST") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
diff --git a/pages/api/v1/auth/reset-password.ts b/pages/api/v1/auth/reset-password.ts
index 7199fcb..5bbadfd 100644
--- a/pages/api/v1/auth/reset-password.ts
+++ b/pages/api/v1/auth/reset-password.ts
@@ -7,7 +7,7 @@ export default async function resetPassword(
res: NextApiResponse
) {
if (req.method === "POST") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
diff --git a/pages/api/v1/auth/verify-email.ts b/pages/api/v1/auth/verify-email.ts
index c19521d..41a9d0c 100644
--- a/pages/api/v1/auth/verify-email.ts
+++ b/pages/api/v1/auth/verify-email.ts
@@ -7,7 +7,7 @@ export default async function verifyEmail(
res: NextApiResponse
) {
if (req.method === "POST") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
diff --git a/pages/api/v1/collections/[id].ts b/pages/api/v1/collections/[id].ts
index 994dd33..9409031 100644
--- a/pages/api/v1/collections/[id].ts
+++ b/pages/api/v1/collections/[id].ts
@@ -19,7 +19,7 @@ export default async function collections(
.status(collections.status)
.json({ response: collections.response });
} else if (req.method === "PUT") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
@@ -28,7 +28,7 @@ export default async function collections(
const updated = await updateCollectionById(user.id, collectionId, req.body);
return res.status(updated.status).json({ response: updated.response });
} else if (req.method === "DELETE") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
diff --git a/pages/api/v1/collections/index.ts b/pages/api/v1/collections/index.ts
index 369863f..3198ea5 100644
--- a/pages/api/v1/collections/index.ts
+++ b/pages/api/v1/collections/index.ts
@@ -16,7 +16,7 @@ export default async function collections(
.status(collections.status)
.json({ response: collections.response });
} else if (req.method === "POST") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
diff --git a/pages/api/v1/links/[id]/archive/index.ts b/pages/api/v1/links/[id]/archive/index.ts
index fa6cf83..6cacf73 100644
--- a/pages/api/v1/links/[id]/archive/index.ts
+++ b/pages/api/v1/links/[id]/archive/index.ts
@@ -29,7 +29,7 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
});
if (req.method === "PUT") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
diff --git a/pages/api/v1/links/[id]/index.ts b/pages/api/v1/links/[id]/index.ts
index 02299f4..7f33c66 100644
--- a/pages/api/v1/links/[id]/index.ts
+++ b/pages/api/v1/links/[id]/index.ts
@@ -14,7 +14,7 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
response: updated.response,
});
} else if (req.method === "PUT") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
@@ -29,7 +29,7 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
response: updated.response,
});
} else if (req.method === "DELETE") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
diff --git a/pages/api/v1/links/index.ts b/pages/api/v1/links/index.ts
index f506d3b..2000e79 100644
--- a/pages/api/v1/links/index.ts
+++ b/pages/api/v1/links/index.ts
@@ -37,7 +37,7 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
const links = await getLinks(user.id, convertedData);
return res.status(links.status).json({ response: links.response });
} else if (req.method === "POST") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
@@ -48,7 +48,7 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
response: newlink.response,
});
} else if (req.method === "PUT") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
@@ -64,7 +64,7 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
response: updated.response,
});
} else if (req.method === "DELETE") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
diff --git a/pages/api/v1/migration/index.ts b/pages/api/v1/migration/index.ts
index 60f52a7..4e47984 100644
--- a/pages/api/v1/migration/index.ts
+++ b/pages/api/v1/migration/index.ts
@@ -30,7 +30,7 @@ export default async function users(req: NextApiRequest, res: NextApiResponse) {
.status(data.status)
.json(data.response);
} else if (req.method === "POST") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
diff --git a/pages/api/v1/tags/[id].ts b/pages/api/v1/tags/[id].ts
index f9a9fd8..606daf0 100644
--- a/pages/api/v1/tags/[id].ts
+++ b/pages/api/v1/tags/[id].ts
@@ -10,7 +10,7 @@ export default async function tags(req: NextApiRequest, res: NextApiResponse) {
const tagId = Number(req.query.id);
if (req.method === "PUT") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
@@ -19,7 +19,7 @@ export default async function tags(req: NextApiRequest, res: NextApiResponse) {
const tags = await updeteTagById(user.id, tagId, req.body);
return res.status(tags.status).json({ response: tags.response });
} else if (req.method === "DELETE") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
diff --git a/pages/api/v1/tokens/[id].ts b/pages/api/v1/tokens/[id].ts
index a0615d7..c4501fb 100644
--- a/pages/api/v1/tokens/[id].ts
+++ b/pages/api/v1/tokens/[id].ts
@@ -7,7 +7,7 @@ export default async function token(req: NextApiRequest, res: NextApiResponse) {
if (!user) return;
if (req.method === "DELETE") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
diff --git a/pages/api/v1/tokens/index.ts b/pages/api/v1/tokens/index.ts
index 915980f..bc5117e 100644
--- a/pages/api/v1/tokens/index.ts
+++ b/pages/api/v1/tokens/index.ts
@@ -11,7 +11,7 @@ export default async function tokens(
if (!user) return;
if (req.method === "POST") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
diff --git a/pages/api/v1/users/[id].ts b/pages/api/v1/users/[id].ts
index 9e102f9..5213d7f 100644
--- a/pages/api/v1/users/[id].ts
+++ b/pages/api/v1/users/[id].ts
@@ -58,7 +58,7 @@ export default async function users(req: NextApiRequest, res: NextApiResponse) {
}
if (req.method === "PUT") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
@@ -67,7 +67,7 @@ export default async function users(req: NextApiRequest, res: NextApiResponse) {
const updated = await updateUserById(userId, req.body);
return res.status(updated.status).json({ response: updated.response });
} else if (req.method === "DELETE") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
diff --git a/pages/api/v1/users/index.ts b/pages/api/v1/users/index.ts
index 8f1f770..356a9f0 100644
--- a/pages/api/v1/users/index.ts
+++ b/pages/api/v1/users/index.ts
@@ -5,7 +5,7 @@ import verifyUser from "@/lib/api/verifyUser";
export default async function users(req: NextApiRequest, res: NextApiResponse) {
if (req.method === "POST") {
- if (process.env.DEMO_MODE === "true")
+ if (process.env.NEXT_PUBLIC_DEMO === "true")
return res.status(400).json({
response:
"This action is disabled because this is a read-only demo of Linkwarden.",
diff --git a/pages/login.tsx b/pages/login.tsx
index 6694cff..cc1a7f0 100644
--- a/pages/login.tsx
+++ b/pages/login.tsx
@@ -92,6 +92,66 @@ export default function Login({
{t("enter_credentials")}
+
+ {process.env.NEXT_PUBLIC_DEMO === "true" &&
+ process.env.NEXT_PUBLIC_DEMO_USERNAME &&
+ process.env.NEXT_PUBLIC_DEMO_PASSWORD && (
+
+
+
+
+ This is only a demo instance of Linkwarden and uploads are
+ disabled.
+
+
+
+
{
+ setForm({
+ username: process.env
+ .NEXT_PUBLIC_DEMO_USERNAME as string,
+ password: process.env
+ .NEXT_PUBLIC_DEMO_PASSWORD as string,
+ });
+ await signIn("credentials", {
+ username: process.env.NEXT_PUBLIC_DEMO_USERNAME,
+ password: process.env.NEXT_PUBLIC_DEMO_PASSWORD,
+ redirect: false,
+ });
+ }}
+ >
+ Login as demo user
+
+
+
+ )}
+
{availableLogins.emailEnabled === "true"