| 97 | |
| 98 | /** 413 response when a synchronous CSV upload would exceed (and be truncated at) the proxy cap; `null` otherwise. */ |
| 99 | export function csvProxyBodyCapResponse(request: { headers: Headers }): NextResponse | null { |
| 100 | const contentLength = Number(request.headers.get('content-length') ?? 0) |
| 101 | if (contentLength > CSV_IMPORT_PROXY_BODY_CAP_BYTES) { |
| 102 | return NextResponse.json( |
| 103 | { |
| 104 | error: |
| 105 | 'File too large to import through the server. Files over 10MB import in the background.', |
| 106 | }, |
| 107 | { status: 413 } |
| 108 | ) |
| 109 | } |
| 110 | return null |
| 111 | } |
| 112 | |
| 113 | /** Maps a {@link MultipartError} from the streaming CSV parser to its HTTP response. */ |
| 114 | export function multipartErrorResponse(error: MultipartError): NextResponse { |