Add endpoint to serve legacy Gooya audio files from PVC
build-and-deploy / deploy (push) Failing after 2m49s
build-and-deploy / deploy (push) Failing after 2m49s
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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user