Restore PROMPT branding, rename waterfall-wiki, and add system tag workflows
waterfall-wiki CI and deployment / verify-and-deploy (push) Has been cancelled
studio CI and deployment / verify-and-deploy (push) Successful in 9m15s

This commit is contained in:
2026-10-27 00:35:59 +08:00
parent 0c1ed2d292
commit ad398db781
178 changed files with 585 additions and 365 deletions
+25
View File
@@ -0,0 +1,25 @@
import { NextResponse, type NextRequest } from 'next/server';
import { authConfig, SESSION_COOKIE, validSession } from './lib/auth';
export function proxy(request: NextRequest) {
const path = request.nextUrl.pathname;
const responseHeaders = {'Cache-Control':'private, no-store', 'Referrer-Policy':'same-origin'};
// Only login code assets and minimal health probes are public. Images, documents,
// rewrites and /_next/data are protected along with pages and API endpoints.
if (path === '/login' || path === '/api/auth/login' || path === '/api/auth/logout' || path === '/api/health' || path === '/api/ready' || path.startsWith('/_next/static/')) return NextResponse.next({headers:responseHeaders});
let config;
try { config = authConfig(); } catch { return NextResponse.json({error:'登录服务配置不可用'}, {status:503,headers:responseHeaders}); }
if (!config) return NextResponse.next();
const bearer = request.headers.get('authorization');
const token = bearer?.startsWith('Bearer ') ? bearer.slice(7) : request.cookies.get(SESSION_COOKIE)?.value;
if (validSession(token,config)) {
if (!['GET','HEAD','OPTIONS'].includes(request.method) && !bearer) {
const origin = request.headers.get('origin');
const host = request.headers.get('host');
try { if (!origin || new URL(origin).host !== host || request.headers.get('sec-fetch-site') === 'cross-site') return NextResponse.json({error:'请求来源不受信任'}, {status:403,headers:responseHeaders}); } catch { return NextResponse.json({error:'请求来源不受信任'}, {status:403,headers:responseHeaders}); }
}
return NextResponse.next({headers:responseHeaders});
}
if (path.startsWith('/api/') || path.startsWith('/studio/api/') || !['GET','HEAD'].includes(request.method)) return NextResponse.json({error:'请先使用动态码登录'}, {status:401,headers:responseHeaders});
const login = request.nextUrl.clone(); login.pathname = '/login'; login.search = ''; login.searchParams.set('next',path + request.nextUrl.search);
return NextResponse.redirect(login,{headers:responseHeaders});
}