Refactor code structure for improved readability and maintainability

This commit is contained in:
shuaiplus
2026-02-26 04:54:11 +08:00
committed by Shuai
parent 90da97c945
commit b21b031120
3 changed files with 4 additions and 1487 deletions
+2 -27
View File
@@ -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<Response> {
void request;
void env;
return htmlResponse(renderRegisterPageHTML(jwtState));
}
// GET / - Setup page
export async function handleSetupPage(request: Request, env: Env): Promise<Response> {
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<Response> {