Files
Radio/src/Radiosender/Controllers/UploadController.cs
T
fraujulianandClaude Opus 5.5 0a0d8e1d4c feat: combine upload and Openverse into one import page
Adding music took two navigation items that each did half the job.
The new Import page has both sources as tabs and one shared list of
what was added in this session, with the reason for every failure and
a link to the library.

From computer: drop several MP3 or WAV files or pick them with a
multi-select dialog. Files are imported one by one on a background
thread with a progress bar, and a failing file does not stop the rest.

Openverse: search and download show a progress ring with a status
text. Results that are already in the library or have no duration are
marked in their row and cannot be imported; a double-click imports.

To detect duplicates, songs now store the Openverse result id. The
repository adds the column to existing databases and a unique index
keeps one song per Openverse result.

Refs #13

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 11:34:35 +01:00

31 lines
1.1 KiB
C#

using Radiosender.Models;
using Radiosender.Services;
namespace Radiosender.Controllers;
/// <param name="Song">The saved song, or <c>null</c> when the upload failed.</param>
public record UploadResult(bool Success, string Message, Song? Song = null);
public class UploadController(SongImportService importService)
{
public static string FileDialogFilter { get; } = "Audio files (*.mp3;*.wav)|*.mp3;*.wav";
/// <summary>Imports one file; failures come back as a result, so a batch can go on with the next file.</summary>
public UploadResult Upload(string filePath)
{
try
{
var song = importService.Import(filePath);
return new UploadResult(true, $"\"{song.Title}\" ({(int)song.Duration.TotalMinutes}:{song.Duration.Seconds:00}) was added to the library.", song);
}
catch (SongImportException e)
{
return new UploadResult(false, e.Message);
}
catch (Exception e)
{
return new UploadResult(false, $"The song could not be saved: {e.Message}");
}
}
}