mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-19 05:55:34 +09:00
perf(api): compile the phrase blocklist into one matcher (#2164)
This commit is contained in:
1 parent
9f620e8c4b
commit
d43d242b16
7 files changed
+790
-50
No files matched your search
@@ -0,0 +1,26 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import type {HonoRequest} from 'hono';
|
||||
import {parseJsonPreservingLargeIntegers} from './LosslessJsonParser';
|
||||
|
||||
interface RequestJsonBody {
|
||||
parsed: boolean;
|
||||
value: unknown;
|
||||
}
|
||||
|
||||
const bodyCache = new WeakMap<Request, RequestJsonBody>();
|
||||
|
||||
export async function readRequestJsonBody(req: HonoRequest): Promise<RequestJsonBody> {
|
||||
const raw = req.raw;
|
||||
const cached = bodyCache.get(raw);
|
||||
if (cached) return cached;
|
||||
let body: RequestJsonBody;
|
||||
try {
|
||||
const text = await req.text();
|
||||
body = {parsed: true, value: text.trim().length === 0 ? {} : parseJsonPreservingLargeIntegers(text)};
|
||||
} catch {
|
||||
body = {parsed: false, value: {}};
|
||||
}
|
||||
bodyCache.set(raw, body);
|
||||
return body;
|
||||
}
|
||||
Reference in new issue
Block a user