From f038ca8e79015e44ec847f4e9fc8695d9e97eb5d Mon Sep 17 00:00:00 2001 From: Pin Lin Date: Sun, 19 Oct 2025 02:06:40 +0800 Subject: [PATCH] Pass COMPUTER_NAME to templates --- docker-compose.yml | 1 + example.env | 1 + index.js | 20 ++++++++++++++------ templates/index.html | 6 +++--- templates/login-fail.html | 6 +++--- templates/login.html | 4 ++-- templates/wakeup-fail.html | 6 +++--- templates/wakeup-success.html | 4 ++-- 8 files changed, 29 insertions(+), 19 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 93aa896..194039b 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,6 +5,7 @@ services: environment: - NODE_ENV=production - PORT=3000 + - COMPUTER_NAME=MyComputer - MAC_ADDRESS=12:34:56:78:90:AB - OIDC_WELL_KNOWN_URL= - CLIENT_ID= diff --git a/example.env b/example.env index 06c6344..918b5a9 100644 --- a/example.env +++ b/example.env @@ -1,5 +1,6 @@ NODE_ENV=production PORT=3000 +COMPUTER_NAME=MyComputer MAC_ADDRESS=12:34:56:78:90:AB OIDC_WELL_KNOWN_URL= CLIENT_ID= diff --git a/index.js b/index.js index 05e2808..d712148 100755 --- a/index.js +++ b/index.js @@ -7,6 +7,7 @@ const { createTemplateRenderer } = require("./utils/templates.jsm"); require("dotenv").config(); const PORT = process.env.PORT || 3000; +const COMPUTER_NAME = process.env.COMPUTER_NAME || "MyComputer"; const REDIRECT_URI = process.env.REDIRECT_URI || "http://127.0.0.1:3000/callback"; @@ -37,9 +38,14 @@ let client; app.get("/", (req, res) => { if (req.session.user) { - res.send(renderHtml("index.html", { USERNAME: req.session.user.sub })); + res.send( + renderHtml("index.html", { + COMPUTER_NAME, + USERNAME: req.session.user.sub, + }) + ); } else { - res.send(renderHtml("login.html")); + res.send(renderHtml("login.html", { COMPUTER_NAME })); } }); @@ -60,18 +66,20 @@ let client; req.session.user = userinfo; res.redirect("/"); } catch (error) { - res.send(renderHtml("login-fail.html", { error })); + res.send(renderHtml("login-fail.html", { COMPUTER_NAME, ERROR: error })); } }); - app.get("/wakeup3770", (req, res) => { + app.get("/wakeup", (req, res) => { if (!req.session.user) return res.redirect("/"); wol.wake(process.env.MAC_ADDRESS, (error) => { if (error) { - res.send(renderHtml("wakeup-fail.html", { error })); + res.send( + renderHtml("wakeup-fail.html", { COMPUTER_NAME, ERROR: error }) + ); } else { - res.send(renderHtml("wakeup-success.html")); + res.send(renderHtml("wakeup-success.html", { COMPUTER_NAME })); } }); }); diff --git a/templates/index.html b/templates/index.html index 4afd512..31225e2 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,7 +3,7 @@ - 喚醒 PinLin3770 + 喚醒 {{COMPUTER_NAME}} -

喚醒 PinLin3770

+

喚醒 {{COMPUTER_NAME}}

已登入為身分 {{USERNAME}}


- 喚醒 PinLin3770 + 喚醒 {{COMPUTER_NAME}} diff --git a/templates/login-fail.html b/templates/login-fail.html index b41e459..ae5191f 100644 --- a/templates/login-fail.html +++ b/templates/login-fail.html @@ -3,7 +3,7 @@ - 登入失敗 | 喚醒 PinLin3770 + 登入失敗 | 喚醒 {{COMPUTER_NAME}} -

喚醒 PinLin3770

+

喚醒 {{COMPUTER_NAME}}

⚠️ 登入失敗

-

{{error}}

+

{{ERROR}}

回首頁 diff --git a/templates/login.html b/templates/login.html index 3bb1bcd..b25e501 100644 --- a/templates/login.html +++ b/templates/login.html @@ -3,7 +3,7 @@ - 登入 | 喚醒 PinLin3770 + 登入 | 喚醒 {{COMPUTER_NAME}} -

喚醒 PinLin3770

+

喚醒 {{COMPUTER_NAME}}

點此登入 diff --git a/templates/wakeup-fail.html b/templates/wakeup-fail.html index 69ce998..928939d 100644 --- a/templates/wakeup-fail.html +++ b/templates/wakeup-fail.html @@ -3,7 +3,7 @@ - 喚醒失敗 | 喚醒 PinLin3770 + 喚醒失敗 | 喚醒 {{COMPUTER_NAME}} -

喚醒 PinLin3770

+

喚醒 {{COMPUTER_NAME}}

⚠️ 發送魔法封包失敗

-

{{error}}

+

{{ERROR}}

回首頁 diff --git a/templates/wakeup-success.html b/templates/wakeup-success.html index 8da5c33..5c7d70e 100644 --- a/templates/wakeup-success.html +++ b/templates/wakeup-success.html @@ -3,7 +3,7 @@ - 喚醒成功 | 喚醒 PinLin3770 + 喚醒成功 | 喚醒 {{COMPUTER_NAME}} -

喚醒 PinLin3770

+

喚醒 {{COMPUTER_NAME}}

✅ 已經發送魔法封包

回首頁