feat(audio): add MP3 and FLAC upload support via format-routed processors

AudioProcessorRouter dispatches by extension; vault stores original bytes with correct MIME type.
This commit is contained in:
daniel-c-harvey
2026-06-11 05:49:17 -04:00
parent f8186fb7c7
commit 3bb8104967
8 changed files with 725 additions and 30 deletions
+27 -11
View File
@@ -12,18 +12,20 @@ namespace DeepDrftContent;
public class TrackContentService
{
private readonly FileDatabase.Services.FileDatabase _fileDatabase;
private readonly AudioProcessor _audioProcessor;
private readonly AudioProcessorRouter _audioProcessorRouter;
public TrackContentService(FileDatabase.Services.FileDatabase fileDatabase, AudioProcessor audioProcessor)
public TrackContentService(FileDatabase.Services.FileDatabase fileDatabase, AudioProcessorRouter audioProcessorRouter)
{
_fileDatabase = fileDatabase;
_audioProcessor = audioProcessor;
_audioProcessorRouter = audioProcessorRouter;
}
/// <summary>
/// Adds a new track from a WAV file to both databases
/// Adds a new track from a supported audio file (.wav, .mp3, .flac) to both databases. The
/// router selects the processor by extension; original bytes are stored for mp3/flac (no
/// transcoding), while EXTENSIBLE WAVs are normalized to standard PCM at storage time.
/// </summary>
/// <param name="wavFilePath">Path to the WAV file</param>
/// <param name="audioFilePath">Path to the audio file</param>
/// <param name="trackName">Name of the track</param>
/// <param name="artist">Artist name</param>
/// <param name="album">Optional album name</param>
@@ -31,8 +33,8 @@ public class TrackContentService
/// <param name="releaseDate">Optional release date</param>
/// <param name="originalFileName">Optional original browser filename captured at upload time</param>
/// <returns>The track entity with generated ID and media path</returns>
public async Task<TrackEntity?> AddTrackFromWavAsync(
string wavFilePath,
public async Task<TrackEntity?> AddTrackAsync(
string audioFilePath,
string trackName,
string artist,
string? album = null,
@@ -42,11 +44,11 @@ public class TrackContentService
{
try
{
// Process the WAV file
var audioBinary = await _audioProcessor.ProcessWavFileAsync(wavFilePath);
// Process the audio file (routed by extension)
var audioBinary = await _audioProcessorRouter.ProcessAudioFileAsync(audioFilePath);
if (audioBinary == null)
{
throw new InvalidOperationException("Failed to process WAV file");
throw new InvalidOperationException("Failed to process audio file");
}
// Generate a unique track ID
@@ -81,11 +83,25 @@ public class TrackContentService
}
catch (Exception ex) when (ex is not OperationCanceledException)
{
Console.WriteLine($"TrackContentService.AddTrackFromWavAsync failed: {ex.Message}");
Console.WriteLine($"TrackContentService.AddTrackAsync failed: {ex.Message}");
return null;
}
}
/// <summary>
/// Backward-compatible shim — delegates to <see cref="AddTrackAsync"/>. The router accepts WAV
/// alongside MP3 and FLAC, so this carries no WAV-specific logic of its own.
/// </summary>
public Task<TrackEntity?> AddTrackFromWavAsync(
string wavFilePath,
string trackName,
string artist,
string? album = null,
string? genre = null,
DateOnly? releaseDate = null,
string? originalFileName = null) =>
AddTrackAsync(wavFilePath, trackName, artist, album, genre, releaseDate, originalFileName);
/// <summary>
/// Retrieves audio binary from FileDatabase
/// </summary>