Files
Copilot b298456126 Increase request timeout for files.create to support large file uploads (#11570)
* Initial plan

* Add 30-minute timeout for files.create endpoint to handle large file uploads

Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>
2026-02-28 09:02:28 -05:00

26 lines
749 B
TypeScript

import type { Next } from "koa";
import type { AppContext } from "@server/types";
/**
* Middleware to extend the request timeout for specific routes.
*
* @param timeoutMs The timeout in milliseconds.
* @returns The middleware function.
*/
export default function timeout(timeoutMs: number) {
return async function timeoutMiddleware(ctx: AppContext, next: Next) {
// Store the original timeout so we can restore it later
const originalTimeout = ctx.req.socket.timeout || 0;
// Set the new timeout on the socket
ctx.req.socket.setTimeout(timeoutMs);
try {
await next();
} finally {
// Restore the original timeout after the request completes
ctx.req.socket.setTimeout(originalTimeout);
}
};
}