Add AzureStorageEnabled environment variable to get the origin of the product image from PicBaseUrl environment variable
This commit is contained in:
parent
45ed8a60ad
commit
1a385a2179
@ -2,10 +2,12 @@
|
||||
{
|
||||
public class CatalogSettings
|
||||
{
|
||||
public string ExternalCatalogBaseUrl {get;set;}
|
||||
public string PicBaseUrl { get;set;}
|
||||
|
||||
public string EventBusConnection { get; set; }
|
||||
|
||||
public string ServiceBusConnectionString { get; set; }
|
||||
|
||||
public bool AzureStorageEnabled { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
CatalogTypeId = product.CatalogTypeId,
|
||||
Description = product.Description,
|
||||
Name = product.Name,
|
||||
PictureUri = product.PictureUri,
|
||||
PictureFileName = product.PictureFileName,
|
||||
Price = product.Price
|
||||
};
|
||||
_catalogContext.CatalogItems.Add(item);
|
||||
@ -231,11 +231,14 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
|
||||
private List<CatalogItem> ChangeUriPlaceholder(List<CatalogItem> items)
|
||||
{
|
||||
var baseUri = _settings.ExternalCatalogBaseUrl;
|
||||
|
||||
items.ForEach(x =>
|
||||
var baseUri = _settings.PicBaseUrl;
|
||||
|
||||
items.ForEach(catalogItem =>
|
||||
{
|
||||
x.PictureUri = x.PictureUri.Replace("http://externalcatalogbaseurltobereplaced", baseUri);
|
||||
catalogItem.PictureUri = _settings.AzureStorageEnabled
|
||||
? baseUri + catalogItem.PictureFileName
|
||||
: baseUri + catalogItem.Id;
|
||||
|
||||
});
|
||||
|
||||
return items;
|
||||
|
@ -1,6 +1,9 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
|
||||
|
||||
@ -10,21 +13,38 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
public class PicController : Controller
|
||||
{
|
||||
private readonly IHostingEnvironment _env;
|
||||
public PicController(IHostingEnvironment env)
|
||||
private readonly CatalogContext _catalogContext;
|
||||
|
||||
public PicController(IHostingEnvironment env,
|
||||
CatalogContext catalogContext)
|
||||
{
|
||||
_env = env;
|
||||
_catalogContext = catalogContext;
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
// GET: /<controller>/
|
||||
public IActionResult GetImage(int id)
|
||||
public async Task<IActionResult> GetImage(int id)
|
||||
{
|
||||
var webRoot = _env.WebRootPath;
|
||||
var path = Path.Combine(webRoot, id + ".png");
|
||||
if (id <= 0)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
var buffer = System.IO.File.ReadAllBytes(path);
|
||||
|
||||
return File(buffer, "image/png");
|
||||
var item = await _catalogContext.CatalogItems
|
||||
.SingleOrDefaultAsync(ci => ci.Id == id);
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
var webRoot = _env.WebRootPath;
|
||||
var path = Path.Combine(webRoot, item.PictureFileName);
|
||||
|
||||
var buffer = System.IO.File.ReadAllBytes(path);
|
||||
|
||||
return File(buffer, "image/png");
|
||||
}
|
||||
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"ConnectionString": "Server=tcp:127.0.0.1,5433;Initial Catalog=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word",
|
||||
"ExternalCatalogBaseUrl": "http://localhost:5101",
|
||||
"PicBaseUrl": "http://localhost:5101",
|
||||
"Logging": {
|
||||
"IncludeScopes": false,
|
||||
"LogLevel": {
|
||||
@ -11,5 +11,6 @@
|
||||
},
|
||||
"ServiceBusConnectionString": "Endpoint=sb://eshopsbez55a72p6wm62.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=oA6WpfCfCbScZbQa/DBOLfwl6oi5ezPsCYL7QsTb4PY=;EntityPath=eshop_event_bus",
|
||||
"AzureServiceBusEnabled": "true",
|
||||
"AzureStorageEnabled": false,
|
||||
"SubscriptionClientName": "Catalog"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user