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 class CatalogSettings
|
||||||
{
|
{
|
||||||
public string ExternalCatalogBaseUrl {get;set;}
|
public string PicBaseUrl { get;set;}
|
||||||
|
|
||||||
public string EventBusConnection { get; set; }
|
public string EventBusConnection { get; set; }
|
||||||
|
|
||||||
public string ServiceBusConnectionString { 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,
|
CatalogTypeId = product.CatalogTypeId,
|
||||||
Description = product.Description,
|
Description = product.Description,
|
||||||
Name = product.Name,
|
Name = product.Name,
|
||||||
PictureUri = product.PictureUri,
|
PictureFileName = product.PictureFileName,
|
||||||
Price = product.Price
|
Price = product.Price
|
||||||
};
|
};
|
||||||
_catalogContext.CatalogItems.Add(item);
|
_catalogContext.CatalogItems.Add(item);
|
||||||
@ -231,11 +231,14 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
|||||||
|
|
||||||
private List<CatalogItem> ChangeUriPlaceholder(List<CatalogItem> items)
|
private List<CatalogItem> ChangeUriPlaceholder(List<CatalogItem> items)
|
||||||
{
|
{
|
||||||
var baseUri = _settings.ExternalCatalogBaseUrl;
|
var baseUri = _settings.PicBaseUrl;
|
||||||
|
|
||||||
items.ForEach(x =>
|
items.ForEach(catalogItem =>
|
||||||
{
|
{
|
||||||
x.PictureUri = x.PictureUri.Replace("http://externalcatalogbaseurltobereplaced", baseUri);
|
catalogItem.PictureUri = _settings.AzureStorageEnabled
|
||||||
|
? baseUri + catalogItem.PictureFileName
|
||||||
|
: baseUri + catalogItem.Id;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
|
// 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
|
public class PicController : Controller
|
||||||
{
|
{
|
||||||
private readonly IHostingEnvironment _env;
|
private readonly IHostingEnvironment _env;
|
||||||
public PicController(IHostingEnvironment env)
|
private readonly CatalogContext _catalogContext;
|
||||||
|
|
||||||
|
public PicController(IHostingEnvironment env,
|
||||||
|
CatalogContext catalogContext)
|
||||||
{
|
{
|
||||||
_env = env;
|
_env = env;
|
||||||
|
_catalogContext = catalogContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
// GET: /<controller>/
|
// GET: /<controller>/
|
||||||
public IActionResult GetImage(int id)
|
public async Task<IActionResult> GetImage(int id)
|
||||||
{
|
{
|
||||||
var webRoot = _env.WebRootPath;
|
if (id <= 0)
|
||||||
var path = Path.Combine(webRoot, id + ".png");
|
{
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
|
||||||
var buffer = System.IO.File.ReadAllBytes(path);
|
var item = await _catalogContext.CatalogItems
|
||||||
|
.SingleOrDefaultAsync(ci => ci.Id == id);
|
||||||
return File(buffer, "image/png");
|
|
||||||
|
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",
|
"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": {
|
"Logging": {
|
||||||
"IncludeScopes": false,
|
"IncludeScopes": false,
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
@ -11,5 +11,6 @@
|
|||||||
},
|
},
|
||||||
"ServiceBusConnectionString": "Endpoint=sb://eshopsbez55a72p6wm62.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=oA6WpfCfCbScZbQa/DBOLfwl6oi5ezPsCYL7QsTb4PY=;EntityPath=eshop_event_bus",
|
"ServiceBusConnectionString": "Endpoint=sb://eshopsbez55a72p6wm62.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=oA6WpfCfCbScZbQa/DBOLfwl6oi5ezPsCYL7QsTb4PY=;EntityPath=eshop_event_bus",
|
||||||
"AzureServiceBusEnabled": "true",
|
"AzureServiceBusEnabled": "true",
|
||||||
|
"AzureStorageEnabled": false,
|
||||||
"SubscriptionClientName": "Catalog"
|
"SubscriptionClientName": "Catalog"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user