From 358f66d45bb825adefe046c8d3c37c5b2e63ec13 Mon Sep 17 00:00:00 2001 From: masoodafar-web Date: Sat, 10 Oct 2026 01:19:48 +0330 Subject: [PATCH] Add endpoint to serve legacy Gooya audio files from PVC Implement a new API endpoint to retrieve audio files based on episode ID, checking multiple potential file paths. This allows for serving existing audio files without re-downloading them, enhancing the efficiency of audio retrieval. --- .../Endpoints/TafsirEndpoints.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/TafsirQuran.Api/Endpoints/TafsirEndpoints.cs b/src/TafsirQuran.Api/Endpoints/TafsirEndpoints.cs index 8cc5c75..3a5cf0d 100644 --- a/src/TafsirQuran.Api/Endpoints/TafsirEndpoints.cs +++ b/src/TafsirQuran.Api/Endpoints/TafsirEndpoints.cs @@ -220,6 +220,31 @@ public static class TafsirEndpoints return Results.File(path, "audio/mpeg", enableRangeProcessing: true); }); + // Legacy Gooya files already on PVC + group.MapGet("/audio/{episodeId:guid}", async ( + Guid episodeId, AppDbContext db, IConfiguration config, IWebHostEnvironment env, CancellationToken ct) => + { + var episode = await db.Episodes.AsNoTracking().FirstOrDefaultAsync(e => e.Id == episodeId, ct); + if (episode is null) return Results.NotFound(); + + var audioRoot = config["AudioRoot"] ?? "/data/audio"; + var relative = episode.AudioUrl.TrimStart('/').Replace('\\', '/'); + var candidates = new[] + { + Path.Combine(audioRoot, relative), + Path.Combine(env.ContentRootPath, "wwwroot", relative), + Path.Combine(env.ContentRootPath, "wwwroot", "audio", Path.GetFileName(relative)) + }; + + foreach (var path in candidates) + { + if (File.Exists(path)) + return Results.File(path, "audio/mpeg", enableRangeProcessing: true); + } + + return Results.NotFound(); + }); + return group; } }