From 6bbc7554c17c7973c53122a6d94115a4a2e10f0e Mon Sep 17 00:00:00 2001 From: shuaiplus <2327005759@qq.com> Date: Thu, 26 Feb 2026 04:54:11 +0800 Subject: [PATCH] Refactor code structure for improved readability and maintainability --- src/handlers/setup.ts | 29 +- src/router.ts | 9 +- src/setup/pageTemplate.ts | 1453 ------------------------------------- 3 files changed, 4 insertions(+), 1487 deletions(-) delete mode 100644 src/setup/pageTemplate.ts diff --git a/src/handlers/setup.ts b/src/handlers/setup.ts index 517b1c1..b799903 100644 --- a/src/handlers/setup.ts +++ b/src/handlers/setup.ts @@ -1,31 +1,6 @@ -import { Env, DEFAULT_DEV_SECRET } from '../types'; +import { Env } from '../types'; import { StorageService } from '../services/storage'; -import { jsonResponse, htmlResponse } from '../utils/response'; -import { renderRegisterPageHTML } from '../setup/pageTemplate'; -import { LIMITS } from '../config/limits'; - -type JwtSecretState = 'missing' | 'default' | 'too_short'; - -function getJwtSecretState(env: Env): JwtSecretState | null { - const secret = (env.JWT_SECRET || '').trim(); - if (!secret) return 'missing'; - // Block common "forgot to change" sample value (matches .dev.vars.example) - if (secret === DEFAULT_DEV_SECRET) return 'default'; - if (secret.length < LIMITS.auth.jwtSecretMinLength) return 'too_short'; - return null; -} - -async function handleRegisterPage(request: Request, env: Env, jwtState: JwtSecretState | null): Promise { - void request; - void env; - return htmlResponse(renderRegisterPageHTML(jwtState)); -} - -// GET / - Setup page -export async function handleSetupPage(request: Request, env: Env): Promise { - const jwtState = getJwtSecretState(env); - return handleRegisterPage(request, env, jwtState); -} +import { jsonResponse } from '../utils/response'; // GET /setup/status export async function handleSetupStatus(request: Request, env: Env): Promise { diff --git a/src/router.ts b/src/router.ts index ddb24db..6a2b472 100644 --- a/src/router.ts +++ b/src/router.ts @@ -48,7 +48,7 @@ import { import { handleSync } from './handlers/sync'; // Setup handlers -import { handleSetupPage, handleSetupStatus } from './handlers/setup'; +import { handleSetupStatus } from './handlers/setup'; import { handleWebClientPage } from './handlers/web'; import { handleKnownDevice, handleGetDevices, handleUpdateDeviceToken } from './handlers/devices'; @@ -187,15 +187,10 @@ export async function handleRequest(request: Request, env: Env): Promise - - - - - NodeWarden - - - -
- - -
-
- -
-
- - - - - - -
-
- -
-
-
- - - -`; -}