( cloudKey: string, context: StorageContext )
| 285 | } |
| 286 | |
| 287 | async function handleCloudProxyPublic( |
| 288 | cloudKey: string, |
| 289 | context: StorageContext |
| 290 | ): Promise<NextResponse> { |
| 291 | try { |
| 292 | let fileBuffer: Buffer |
| 293 | |
| 294 | if (context === 'copilot') { |
| 295 | fileBuffer = await CopilotFiles.downloadCopilotFile(cloudKey) |
| 296 | } else { |
| 297 | fileBuffer = await downloadFile({ |
| 298 | key: cloudKey, |
| 299 | context, |
| 300 | }) |
| 301 | } |
| 302 | |
| 303 | const filename = cloudKey.split('/').pop() || 'download' |
| 304 | const contentType = getContentType(filename) |
| 305 | |
| 306 | logger.info('Public cloud file served', { |
| 307 | key: cloudKey, |
| 308 | size: fileBuffer.length, |
| 309 | context, |
| 310 | }) |
| 311 | |
| 312 | return createFileResponse({ |
| 313 | buffer: fileBuffer, |
| 314 | contentType, |
| 315 | filename, |
| 316 | }) |
| 317 | } catch (error) { |
| 318 | logger.error('Error serving public cloud file:', error) |
| 319 | throw error |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | async function handleLocalFilePublic(filename: string): Promise<NextResponse> { |
| 324 | try { |
no test coverage detected