Compare commits
2 commits
456a86af8d
...
b61e477c0c
Author | SHA1 | Date | |
---|---|---|---|
b61e477c0c | |||
75ab4de41f |
2 changed files with 21 additions and 5 deletions
|
@ -33,11 +33,26 @@ export async function getHtml(url: string, accept = 'text/html, */*', timeout =
|
|||
return await res.text();
|
||||
}
|
||||
|
||||
export async function getResponse(args: { url: string, method: string, body?: string, headers: Record<string, string>, timeout: number = 10 * SECOND, size?: number, redirect: 'follow' | 'manual' | 'error' = 'follow' }) {
|
||||
export async function getResponse(_args: {
|
||||
url: string,
|
||||
method: string,
|
||||
body?: string,
|
||||
headers: Record<string, string>,
|
||||
timeout?: number,
|
||||
size?: number,
|
||||
redirect?: 'follow' | 'manual' | 'error',
|
||||
}) {
|
||||
const args = {
|
||||
timeout: 10 * SECOND,
|
||||
size: 10 * 1024 * 1024, // 10 MiB
|
||||
redirect: 'follow',
|
||||
..._args,
|
||||
};
|
||||
|
||||
const controller = new AbortController();
|
||||
setTimeout(() => {
|
||||
controller.abort();
|
||||
}, timeout);
|
||||
}, args.timeout);
|
||||
|
||||
const res = await fetch(args.url, {
|
||||
method: args.method,
|
||||
|
@ -46,7 +61,7 @@ export async function getResponse(args: { url: string, method: string, body?: st
|
|||
}, args.headers),
|
||||
body: args.body,
|
||||
redirect: args.redirect,
|
||||
size: args.size || 10 * 1024 * 1024, // 10 MiB
|
||||
size: args.size,
|
||||
agent: getAgentByUrl,
|
||||
signal: controller.signal,
|
||||
});
|
||||
|
|
|
@ -5,6 +5,7 @@ import { UserPublickey } from '@/models/entities/user-publickey.js';
|
|||
import { uriPersonCache, userByIdCache } from '@/services/user-cache.js';
|
||||
import { createPerson } from '@/remote/activitypub/models/person.js';
|
||||
import { Resolver } from '@/remote/activitypub/resolver.js';
|
||||
import { HOUR } from '@/const.js';
|
||||
|
||||
export type AuthUser = {
|
||||
user: IRemoteUser;
|
||||
|
@ -12,11 +13,11 @@ export type AuthUser = {
|
|||
};
|
||||
|
||||
const publicKeyCache = new Cache<UserPublickey>(
|
||||
Infinity,
|
||||
2 * HOUR,
|
||||
(keyId) => UserPublickeys.findOneBy({ keyId }).then(x => x ?? undefined),
|
||||
);
|
||||
const publicKeyByUserIdCache = new Cache<UserPublickey>(
|
||||
Infinity,
|
||||
2 * HOUR,
|
||||
(userId) => UserPublickeys.findOneBy({ userId }).then(x => x ?? undefined),
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue