mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-21 17:37:29 -07:00
[backend] Improve JSON-LD context size limiter
This commit is contained in:
parent
d9d6dc1b60
commit
9a8b7efcd6
1 changed files with 7 additions and 5 deletions
|
@ -122,11 +122,12 @@ export class LdSignature {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async fetchDocument(url: string) {
|
private async fetchDocument(url: string) {
|
||||||
const json = await fetch(url, {
|
const ctrl = new AbortController();
|
||||||
|
return await fetch(url, {
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/ld+json, application/json",
|
Accept: "application/ld+json, application/json",
|
||||||
},
|
},
|
||||||
size: 1024 * 1024, // 1MiB
|
signal: ctrl.signal,
|
||||||
// TODO
|
// TODO
|
||||||
//timeout: this.loderTimeout,
|
//timeout: this.loderTimeout,
|
||||||
agent: (u) => (u.protocol === "http:" ? httpAgent : httpsAgent),
|
agent: (u) => (u.protocol === "http:" ? httpAgent : httpsAgent),
|
||||||
|
@ -134,11 +135,12 @@ export class LdSignature {
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
throw new Error(`${res.status} ${res.statusText}`);
|
throw new Error(`${res.status} ${res.statusText}`);
|
||||||
} else {
|
} else {
|
||||||
return res.json();
|
if (res.size < 1024 * 1024) // 1MiB
|
||||||
|
return res.json();
|
||||||
|
ctrl.abort();
|
||||||
|
throw new Error('Size exceeded 1MiB');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return json;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public sha256(data: string): string {
|
public sha256(data: string): string {
|
||||||
|
|
Loading…
Reference in a new issue