Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Minor improvements - ImagePath/ImageThumbPath/ImageUploadedPath in one file
KrzysztofPajakbbc9053d6b99
diff --git a/src/Business/Grand.Business.Storage/Services/AmazonPictureService.cs b/src/Business/Grand.Business.Storage/Services/AmazonPictureService.csindex dc358167c..7ef56ccf8 100644--- a/src/Business/Grand.Business.Storage/Services/AmazonPictureService.cs+++ b/src/Business/Grand.Business.Storage/Services/AmazonPictureService.cs@@ -2,19 +2,18 @@using Amazon.Runtime;using Amazon.S3;using Amazon.S3.Model;+using Grand.Business.Common.Interfaces.Logging;+using Grand.Business.Storage.Interfaces;+using Grand.Domain.Data;+using Grand.Domain.Media;using Grand.Infrastructure;using Grand.Infrastructure.Caching;using Grand.Infrastructure.Configuration;-using Grand.Domain.Data;-using Grand.Domain.Media;using MediatR;-using Microsoft.AspNetCore.Hosting;using System;using System.IO;using System.Net;using System.Threading.Tasks;-using Grand.Business.Common.Interfaces.Logging;-using Grand.Business.Storage.Interfaces;namespace Grand.Business.Storage.Services{@@ -38,7 +37,6 @@ namespace Grand.Business.Storage.Servicespublic AmazonPictureService(IRepository<Picture> pictureRepository,ILogger logger,IMediator mediator,- IWebHostEnvironment hostingEnvironment,IWorkContext workContext,ICacheBase cacheBase,IMediaFileStore mediaFileStore,@@ -48,7 +46,6 @@ namespace Grand.Business.Storage.Services: base(pictureRepository,logger,mediator,- hostingEnvironment,workContext,cacheBase,mediaFileStore,@@ -93,8 +90,7 @@ namespace Grand.Business.Storage.Serviceswhile (_bucketExist == false){S3Region s3region = S3Region.FindValue(_config.AmazonRegion);- var putBucketRequest = new PutBucketRequest- {+ var putBucketRequest = new PutBucketRequest {BucketName = _bucketName,BucketRegion = s3region,};@@ -135,8 +131,7 @@ namespace Grand.Business.Storage.Services{await CheckBucketExists();- var listObjectsRequest = new ListObjectsV2Request()- {+ var listObjectsRequest = new ListObjectsV2Request() {BucketName = _bucketName,Prefix = picture.Id};@@ -193,8 +188,7 @@ namespace Grand.Business.Storage.Servicesusing (Stream stream = new MemoryStream(binary)){- var putObjectRequest = new PutObjectRequest()- {+ var putObjectRequest = new PutObjectRequest() {BucketName = _bucketName,InputStream = stream,Key = thumbFileName,@@ -213,8 +207,7 @@ namespace Grand.Business.Storage.Services{await CheckBucketExists();- var listObjectsRequest = new ListObjectsV2Request()- {+ var listObjectsRequest = new ListObjectsV2Request() {BucketName = _bucketName};var listObjectsResponse = await _s3Client.ListObjectsV2Async(listObjectsRequest);diff --git a/src/Business/Grand.Business.Storage/Services/AzurePictureService.cs b/src/Business/Grand.Business.Storage/Services/AzurePictureService.csindex e5f5b7cb9..a468621e8 100644--- a/src/Business/Grand.Business.Storage/Services/AzurePictureService.cs+++ b/src/Business/Grand.Business.Storage/Services/AzurePictureService.cs@@ -1,17 +1,15 @@using Azure.Storage.Blobs;+using Grand.Business.Common.Interfaces.Logging;+using Grand.Business.Storage.Interfaces;+using Grand.Domain.Data;+using Grand.Domain.Media;using Grand.Infrastructure;using Grand.Infrastructure.Caching;using Grand.Infrastructure.Configuration;-using Grand.Domain.Data;-using Grand.Domain.Media;using MediatR;-using Microsoft.AspNetCore.Hosting;using System;-using System.Diagnostics;using System.IO;using System.Threading.Tasks;-using Grand.Business.Common.Interfaces.Logging;-using Grand.Business.Storage.Interfaces;namespace Grand.Business.Storage.Services{@@ -32,7 +30,6 @@ namespace Grand.Business.Storage.Servicespublic AzurePictureService(IRepository<Picture> pictureRepository,ILogger logger,IMediator mediator,- IWebHostEnvironment hostingEnvironment,IWorkContext workContext,ICacheBase cacheBase,IMediaFileStore mediaFileStore,@@ -42,7 +39,6 @@ namespace Grand.Business.Storage.Services: base(pictureRepository,logger,mediator,- hostingEnvironment,workContext,cacheBase,mediaFileStore,diff --git a/src/Business/Grand.Business.Storage/Services/PictureService.cs b/src/Business/Grand.Business.Storage/Services/PictureService.csindex 14688d4fb..655d3117c 100644--- a/src/Business/Grand.Business.Storage/Services/PictureService.cs+++ b/src/Business/Grand.Business.Storage/Services/PictureService.cs@@ -11,7 +11,6 @@ using Grand.Infrastructure.Caching.Constants;using Grand.Infrastructure.Extensions;using Grand.SharedKernel.Extensions;using MediatR;-using Microsoft.AspNetCore.Hosting;using SkiaSharp;using System;using System.IO;@@ -33,22 +32,12 @@ namespace Grand.Business.Storage.Servicesprivate readonly IRepository<Picture> _pictureRepository;private readonly ILogger _logger;private readonly IMediator _mediator;- private readonly IWebHostEnvironment _hostingEnvironment;private readonly IWorkContext _workContext;private readonly ICacheBase _cacheBase;private readonly IMediaFileStore _mediaFileStore;private readonly MediaSettings _mediaSettings;private readonly StorageSettings _storageSettings;- //Used when images stored on file system- private readonly string _imagePath;-- //Used for thumb images- private readonly string _thumbPath;-- //path to the no image file- private readonly string _path_no_image = "assets/images/no-image.png";-#endregion#region Ctor@@ -59,7 +48,6 @@ namespace Grand.Business.Storage.Services/// <param name="pictureRepository">Picture repository</param>/// <param name="logger">Logger</param>/// <param name="mediator">Mediator</param>- /// <param name="hostingEnvironment">hostingEnvironment</param>/// <param name="workContext">Current context</param>/// <param name="cacheBase">Cache manager</param>/// <param name="mediaFileStore">Media file storage</param>@@ -67,7 +55,6 @@ namespace Grand.Business.Storage.Servicespublic PictureService(IRepository<Picture> pictureRepository,ILogger logger,IMediator mediator,- IWebHostEnvironment hostingEnvironment,IWorkContext workContext,ICacheBase cacheBase,IMediaFileStore mediaFileStore,@@ -77,15 +64,11 @@ namespace Grand.Business.Storage.Services_pictureRepository = pictureRepository;_logger = logger;_mediator = mediator;- _hostingEnvironment = hostingEnvironment;_workContext = workContext;_cacheBase = cacheBase;_mediaFileStore = mediaFileStore;_mediaSettings = mediaSettings;_storageSettings = storageSettings;-- _imagePath = _mediaFileStore.Combine("assets", "images");- _thumbPath = _mediaFileStore.Combine("assets", "images", "thumbs");}#endregion@@ -144,7 +127,7 @@ namespace Grand.Business.Storage.Servicesprotected virtual Task DeletePictureThumbs(Picture picture){string filter = string.Format("{0}*.*", picture.Id);- var thumbDirectoryPath = _mediaFileStore.GetDirectoryInfo(_thumbPath);+ var thumbDirectoryPath = _mediaFileStore.GetDirectoryInfo(CommonPath.ImageThumbPath);if (thumbDirectoryPath != null){string[] currentFiles = Directory.GetFiles(thumbDirectoryPath.PhysicalPath, filter, SearchOption.AllDirectories);@@ -171,7 +154,7 @@ namespace Grand.Business.Storage.Services/// <returns>Local picture physical path</returns>protected virtual async Task<string> GetThumbPhysicalPath(string thumbFileName){- var thumbFile = _mediaFileStore.Combine(_thumbPath, thumbFileName);+ var thumbFile = _mediaFileStore.Combine(CommonPath.ImageThumbPath, thumbFileName);var fileInfo = await _mediaFileStore.GetFileInfo(thumbFile);return fileInfo?.PhysicalPath;}@@ -190,7 +173,7 @@ namespace Grand.Business.Storage.Services_workContext.CurrentStore.SslEnabled ? _workContext.CurrentStore.SecureUrl : _workContext.CurrentStore.Url :_mediaSettings.StoreLocation;- return _mediaFileStore.Combine(storeLocation, CommonPath.Param, _thumbPath, thumbFileName);+ return _mediaFileStore.Combine(storeLocation, CommonPath.Param, CommonPath.ImageThumbPath, thumbFileName);}/// <summary>@@ -200,7 +183,7 @@ namespace Grand.Business.Storage.Services/// <returns>Physical picture path</returns>protected virtual async Task<string> GetPicturePhysicalPath(string fileName){- var fileinfo = await _mediaFileStore.GetFileInfo(_mediaFileStore.Combine(_imagePath, fileName));+ var fileinfo = await _mediaFileStore.GetFileInfo(_mediaFileStore.Combine(CommonPath.ImagePath, fileName));return fileinfo?.PhysicalPath;}@@ -231,12 +214,12 @@ namespace Grand.Business.Storage.Services{try{- var dirThumb = _mediaFileStore.GetDirectoryInfo(_thumbPath);+ var dirThumb = _mediaFileStore.GetDirectoryInfo(CommonPath.ImageThumbPath);if (dirThumb == null){- var result = _mediaFileStore.TryCreateDirectory(_thumbPath);+ var result = _mediaFileStore.TryCreateDirectory(CommonPath.ImageThumbPath);if (result)- dirThumb = _mediaFileStore.GetDirectoryInfo(_thumbPath);+ dirThumb = _mediaFileStore.GetDirectoryInfo(CommonPath.ImageThumbPath);}if (dirThumb != null)@@ -291,7 +274,7 @@ namespace Grand.Business.Storage.Servicesvar filePath = await GetPicturePhysicalPath(_mediaSettings.DefaultImageName);if (string.IsNullOrEmpty(filePath)){- return _path_no_image;+ return _mediaFileStore.Combine(CommonPath.ImagePath, "no-image.png");}if (targetSize == 0){@@ -299,7 +282,7 @@ namespace Grand.Business.Storage.Services? storeLocation: string.IsNullOrEmpty(_mediaSettings.StoreLocation) ?_workContext.CurrentStore.SslEnabled ? _workContext.CurrentStore.SecureUrl : _workContext.CurrentStore.Url :- _mediaFileStore.Combine(_mediaSettings.StoreLocation, _imagePath, _mediaSettings.DefaultImageName);+ _mediaFileStore.Combine(_mediaSettings.StoreLocation, CommonPath.ImagePath, _mediaSettings.DefaultImageName);}else{@@ -529,7 +512,7 @@ namespace Grand.Business.Storage.Servicespublic virtual async Task ClearThumbs(){const string searchPattern = "*.*";- var path = _mediaFileStore.GetDirectoryInfo(Path.Combine("assets", "images", "thumbs"))?.PhysicalPath;+ var path = _mediaFileStore.GetDirectoryInfo(CommonPath.ImageThumbPath)?.PhysicalPath;if (!Directory.Exists(path))return;@@ -726,7 +709,7 @@ namespace Grand.Business.Storage.Services{var lastPart = GetFileExtensionFromMimeType(mimeType);var fileName = string.Format("{0}_0.{1}", pictureId, lastPart);- var dirpath = _mediaFileStore.GetDirectoryInfo(_imagePath);+ var dirpath = _mediaFileStore.GetDirectoryInfo(CommonPath.ImagePath);if (dirpath != null){var filepath = _mediaFileStore.Combine(dirpath.PhysicalPath, fileName);diff --git a/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs b/src/Core/Grand.SharedKernel/Extensions/CommonPath.csindex 491cf9fac..384e3bcd0 100644--- a/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs+++ b/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs@@ -69,6 +69,37 @@ namespace Grand.SharedKernel.Extensions}}+ /// <summary>+ /// Maps a image path.+ /// </summary>+ /// <returns>The path.</returns>+ public static string ImagePath {+ get {+ return Path.Combine("assets", "images");+ }+ }++ /// <summary>+ /// Maps a image thumb path.+ /// </summary>+ /// <returns>The path.</returns>+ public static string ImageThumbPath {+ get {+ return Path.Combine("assets", "images", "thumbs");+ }+ }++ /// <summary>+ /// Maps a image upload path.+ /// </summary>+ /// <returns>The path.</returns>+ public static string ImageUploadedPath {+ get {+ return Path.Combine("assets", "images", "uploaded");+ }+ }++/// <summary>/// Maps a installled plugins path to a physical disk path./// </summary>diff --git a/src/Tests/Grand.Business.Storage.Tests/Services/PictureServiceTests.cs b/src/Tests/Grand.Business.Storage.Tests/Services/PictureServiceTests.csindex e652d7453..ac0e172b0 100644--- a/src/Tests/Grand.Business.Storage.Tests/Services/PictureServiceTests.cs+++ b/src/Tests/Grand.Business.Storage.Tests/Services/PictureServiceTests.cs@@ -36,13 +36,12 @@ namespace Grand.Business.Storage.Tests.Services_repoMock = new Mock<IRepository<Picture>>();_logerMock = new Mock<ILogger>();_mediatorMock = new Mock<IMediator>();- _webHostMock = new Mock<IWebHostEnvironment>();_workContextMock = new Mock<IWorkContext>();_cacheMock = new Mock<ICacheBase>();_mediaFileStoreMock = new Mock<IMediaFileStore>();_settings = new MediaSettings();_storagesettings = new StorageSettings();- _service = new PictureService(_repoMock.Object, _logerMock.Object, _mediatorMock.Object, _webHostMock.Object, _workContextMock.Object+ _service = new PictureService(_repoMock.Object, _logerMock.Object, _mediatorMock.Object, _workContextMock.Object, _cacheMock.Object, _mediaFileStoreMock.Object, _settings, _storagesettings);}diff --git a/src/Web/Grand.Web.Admin/Services/ElFinderViewModelService.cs b/src/Web/Grand.Web.Admin/Services/ElFinderViewModelService.csindex ed62da1ac..2b947470b 100644--- a/src/Web/Grand.Web.Admin/Services/ElFinderViewModelService.cs+++ b/src/Web/Grand.Web.Admin/Services/ElFinderViewModelService.cs@@ -50,22 +50,22 @@ namespace Grand.Web.Admin.Servicesif (!string.IsNullOrEmpty(_mediaSettings.FileManagerDisabledUICommands))_connector.Options.DisabledUICommands = _mediaSettings.FileManagerDisabledUICommands.Split(',').Select(x => x.Trim()).ToList();- var uploaded = _mediaFileStore.GetDirectoryInfo(Path.Combine("assets", "images", "uploaded"));+ var uploaded = _mediaFileStore.GetDirectoryInfo(CommonPath.ImageUploadedPath);if (uploaded == null){- _mediaFileStore.TryCreateDirectory(Path.Combine("assets", "images", "uploaded"));- uploaded = _mediaFileStore.GetDirectoryInfo(Path.Combine("assets", "images", "uploaded"));+ _mediaFileStore.TryCreateDirectory(CommonPath.ImageUploadedPath);+ uploaded = _mediaFileStore.GetDirectoryInfo(CommonPath.ImageUploadedPath);}_fullPathToUpload = uploaded.PhysicalPath;_urlpathUploded = (string.IsNullOrEmpty(CommonPath.Param) ? $"/": $"/{CommonPath.Param}/")+ uploaded.Path.Replace("\\", "/") + "/";- var thumbs = _mediaFileStore.GetDirectoryInfo(Path.Combine("assets", "images", "thumbs"));+ var thumbs = _mediaFileStore.GetDirectoryInfo(CommonPath.ImageThumbPath);if (thumbs == null){- _mediaFileStore.TryCreateDirectory(Path.Combine("assets", "images", "thumbs"));- thumbs = _mediaFileStore.GetDirectoryInfo(Path.Combine("assets", "images", "thumbs"));+ _mediaFileStore.TryCreateDirectory(CommonPath.ImageThumbPath);+ thumbs = _mediaFileStore.GetDirectoryInfo(CommonPath.ImageThumbPath);}_fullPathToThumbs = thumbs.PhysicalPath;