mirror of
https://github.com/karakeep-app/karakeep.git
synced 2026-02-28 18:25:55 +01:00
* fix: Stricter SSRF validation * skip dns resolution if running in proxy context * more fixes * Add LRU cache * change the env variable for internal hostnames * make dns resolution timeout configerable * upgrade ipaddr * handle ipv6 * handle proxy bypass for request interceptor
17 lines
397 B
TypeScript
17 lines
397 B
TypeScript
export function withTimeout<T, Ret>(
|
|
func: (param: T) => Promise<Ret>,
|
|
timeoutSec: number,
|
|
) {
|
|
return async (param: T): Promise<Ret> => {
|
|
return await Promise.race([
|
|
func(param),
|
|
new Promise<Ret>((_resolve, reject) =>
|
|
setTimeout(
|
|
() => reject(new Error(`Timed-out after ${timeoutSec} secs`)),
|
|
timeoutSec * 1000,
|
|
),
|
|
),
|
|
]);
|
|
};
|
|
}
|