Splits copyFileAsync into local vs s3 branches gated by the
TRACK_STORAGE_BACKEND flag (added in P0 d03232c8). Regular uploads
via TrackService.UploadTrack() now write to MinIO/S3 when the flag
is 's3' and a non-nil S3 service is configured, persisting the S3
object key + storage_backend='s3' on the track row atomically.
Changes:
- internal/core/track/service.go
- New S3StorageInterface (UploadStream + GetSignedURL + DeleteFile).
Narrow surface for testability; *services.S3StorageService satisfies.
- TrackService gains s3Service + storageBackend + s3Bucket fields
and a SetS3Storage setter.
- copyFileAsync is now a dispatcher; former body moved to
copyFileAsyncLocal, new copyFileAsyncS3 streams to S3 with key
tracks/<userID>/<trackID>.<ext>.
- mimeTypeForAudioExt helper.
- Stream server trigger deliberately skipped on S3 branch; wired
in Phase 2 with S3 read support.
- internal/api/routes_tracks.go: DI passes S3StorageService,
TrackStorageBackend, S3Bucket into TrackService.
- internal/core/track/service_async_test.go:
- fakeS3Storage stub (captures UploadStream payload).
- TestUploadTrack_S3Backend_UploadsToS3: end-to-end on key format,
content-type, DB row state.
- TestUploadTrack_S3Backend_NilS3Service_FallsBackToLocal:
defensive — backend='s3' + nil service must not panic.
Out of scope Phase 1: read path, transcoder. Enabling
TRACK_STORAGE_BACKEND=s3 in prod BEFORE Phase 2 ships makes S3-backed
tracks un-streamable. Keep flag 'local' until A4/A5 land.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>