Return a file instead of just a CSV text
This commit is contained in:
@@ -9,6 +9,7 @@ using Microsoft.Extensions.Caching.Memory;
|
|||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace AS1024.GeoFeed.MinimalAPI
|
namespace AS1024.GeoFeed.MinimalAPI
|
||||||
{
|
{
|
||||||
@@ -48,7 +49,7 @@ namespace AS1024.GeoFeed.MinimalAPI
|
|||||||
app.Run();
|
app.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static async Task<string> GeoFeedDataRunner(IGeoFeedProvider provider,
|
protected static async Task<IResult> GeoFeedDataRunner(IGeoFeedProvider provider,
|
||||||
ILogger<Program> logger,
|
ILogger<Program> logger,
|
||||||
IGeoFeedPersistentCacheProvider cacheProvider,
|
IGeoFeedPersistentCacheProvider cacheProvider,
|
||||||
IMemoryCache memoryCache,
|
IMemoryCache memoryCache,
|
||||||
@@ -67,20 +68,26 @@ namespace AS1024.GeoFeed.MinimalAPI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return feed.ToGeoFeedCsv();
|
return Results.File(Encoding.UTF8.GetBytes(feed.ToGeoFeedCsv()),
|
||||||
|
"text/csv",
|
||||||
|
"geofeed.csv");
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (HttpRequestException ex)
|
catch (HttpRequestException ex)
|
||||||
{
|
{
|
||||||
logger.LogWarning($"Temporary failure of retrieving GeoData from upstream. {ex}");
|
logger.LogWarning($"Temporary failure of retrieving GeoData from upstream. {ex}");
|
||||||
string geoFeedData = cacheProvider.GetGeoFeed();
|
string geoFeedData = cacheProvider.GetGeoFeed();
|
||||||
return geoFeedData;
|
|
||||||
|
return Results.File(Encoding.UTF8.GetBytes(geoFeedData),
|
||||||
|
"text/csv",
|
||||||
|
"geofeed.csv");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.LogError($"Error: {ex}");
|
logger.LogError($"Error: {ex}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return Results.NoContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user