(options: DeleteFileOptions)
| 433 | * Delete a file from the configured storage provider |
| 434 | */ |
| 435 | export async function deleteFile(options: DeleteFileOptions): Promise<void> { |
| 436 | const { key, context } = options |
| 437 | |
| 438 | if (context) { |
| 439 | const config = getStorageConfig(context) |
| 440 | |
| 441 | if (USE_BLOB_STORAGE) { |
| 442 | const { deleteFromBlob } = await import('@/lib/uploads/providers/blob/client') |
| 443 | return deleteFromBlob(key, createBlobConfig(config)) |
| 444 | } |
| 445 | |
| 446 | if (USE_S3_STORAGE) { |
| 447 | const { deleteFromS3 } = await import('@/lib/uploads/providers/s3/client') |
| 448 | return deleteFromS3(key, createS3Config(config)) |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | const { unlink } = await import('fs/promises') |
| 453 | const { join } = await import('path') |
| 454 | const { UPLOAD_DIR_SERVER } = await import('./setup.server') |
| 455 | |
| 456 | const safeKey = sanitizeFileKey(key) |
| 457 | const filePath = join(UPLOAD_DIR_SERVER, safeKey) |
| 458 | |
| 459 | await unlink(filePath) |
| 460 | } |
| 461 | |
| 462 | /** AWS SDK v3 silently caps HTTP connections at 50/endpoint — stay well under. */ |
| 463 | const PER_FILE_DELETE_CONCURRENCY = 25 |
no test coverage detected