feat: implement protocol parity and harden upstream handling (#88)

* feat: implement protocol parity and harden upstream handling

* docs(agents): add lodash-es utility method and named import guideline
This commit is contained in:
vin authored and GitHub committed 2026-02-11 00:42:39 +08:00
1 parent 0f7a629a47
commit 13f10fe32f
23 files changed
+4408 -654

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
import { CanActivate, ExecutionContext, Injectable, UnauthorizedException } from '@nestjs/common';
import { getServerConfig } from '../server-config';
import { extractApiKeyToken, hasConfiguredApiKey, RequestHeaders } from './api-key-auth.util';
@Injectable()
export class AdminGuard implements CanActivate {
canActivate(context: ExecutionContext): boolean {
const config = getServerConfig();
const apiKey = config?.api_key;
if (!hasConfiguredApiKey(apiKey)) {
return true;
}
const request = context.switchToHttp().getRequest();
const headers = request.headers as RequestHeaders;
const clientToken = extractApiKeyToken(headers);
if (clientToken && clientToken === apiKey) {
return true;
}
throw new UnauthorizedException('API key validation failed');
}
}