3bb8104967
AudioProcessorRouter dispatches by extension; vault stores original bytes with correct MIME type.
43 lines
1.6 KiB
C#
43 lines
1.6 KiB
C#
using DeepDrftContent.FileDatabase.Models;
|
|
|
|
namespace DeepDrftContent.Processors;
|
|
|
|
/// <summary>
|
|
/// Dispatches an audio file to the correct format processor by extension. The single seam through
|
|
/// which <see cref="TrackContentService"/> processes uploads, so callers depend on one abstraction
|
|
/// rather than three concrete processors.
|
|
/// </summary>
|
|
public class AudioProcessorRouter
|
|
{
|
|
private readonly AudioProcessor _wavProcessor;
|
|
private readonly Mp3AudioProcessor _mp3Processor;
|
|
private readonly FlacAudioProcessor _flacProcessor;
|
|
|
|
public AudioProcessorRouter(
|
|
AudioProcessor wavProcessor,
|
|
Mp3AudioProcessor mp3Processor,
|
|
FlacAudioProcessor flacProcessor)
|
|
{
|
|
_wavProcessor = wavProcessor;
|
|
_mp3Processor = mp3Processor;
|
|
_flacProcessor = flacProcessor;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Processes <paramref name="filePath"/> with the processor matching its extension, returning an
|
|
/// <see cref="AudioBinary"/> carrying the stored bytes and extracted metadata. Throws
|
|
/// <see cref="ArgumentException"/> for unsupported extensions.
|
|
/// </summary>
|
|
public async Task<AudioBinary?> ProcessAudioFileAsync(string filePath)
|
|
{
|
|
var ext = Path.GetExtension(filePath).ToLowerInvariant();
|
|
return ext switch
|
|
{
|
|
".wav" => await _wavProcessor.ProcessWavFileAsync(filePath),
|
|
".mp3" => await _mp3Processor.ProcessMp3FileAsync(filePath),
|
|
".flac" => await _flacProcessor.ProcessFlacFileAsync(filePath),
|
|
_ => throw new ArgumentException($"Unsupported audio format: {ext}", nameof(filePath)),
|
|
};
|
|
}
|
|
}
|