* Server-only function to ensure uploads directory exists
()
| 23 | * Server-only function to ensure uploads directory exists |
| 24 | */ |
| 25 | async function ensureUploadsDirectory() { |
| 26 | if (USE_S3_STORAGE) { |
| 27 | logger.info('Using S3 storage, skipping local uploads directory creation') |
| 28 | return true |
| 29 | } |
| 30 | |
| 31 | if (USE_BLOB_STORAGE) { |
| 32 | logger.info('Using Azure Blob storage, skipping local uploads directory creation') |
| 33 | return true |
| 34 | } |
| 35 | |
| 36 | try { |
| 37 | if (!existsSync(UPLOAD_DIR_SERVER)) { |
| 38 | await mkdir(UPLOAD_DIR_SERVER, { recursive: true }) |
| 39 | } else { |
| 40 | logger.info(`Uploads directory already exists at ${UPLOAD_DIR_SERVER}`) |
| 41 | } |
| 42 | return true |
| 43 | } catch (error) { |
| 44 | logger.error('Failed to create uploads directory:', error) |
| 45 | return false |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | // Immediately invoke on server startup |
| 50 | if (typeof process !== 'undefined') { |
no test coverage detected