Skip to content

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.

Refactor image path handling in PictureService

KrzysztofPajak34a69666a569
diff --git a/src/Business/Grand.Business.Storage/Services/PictureService.cs b/src/Business/Grand.Business.Storage/Services/PictureService.cs
index 680246bcc..145fc9c35 100644
--- a/src/Business/Grand.Business.Storage/Services/PictureService.cs
+++ b/src/Business/Grand.Business.Storage/Services/PictureService.cs
@@ -61,6 +61,8 @@ public class PictureService : IPictureService
private readonly MediaSettings _mediaSettings;
private readonly StorageSettings _storageSettings;
+ private static string ImagePath => Path.Combine("assets", "images");
+
#endregion
#region Utilities
@@ -166,7 +168,7 @@ public class PictureService : IPictureService
/// <returns>Physical picture path</returns>
protected virtual async Task<string> GetPicturePhysicalPath(string fileName)
{
- var fileInfo = await _mediaFileStore.GetFileInfo(_mediaFileStore.Combine(CommonPath.ImagePath, fileName));
+ var fileInfo = await _mediaFileStore.GetFileInfo(_mediaFileStore.Combine(ImagePath, fileName));
return fileInfo?.PhysicalPath;
}
@@ -255,11 +257,11 @@ public class PictureService : IPictureService
public virtual async Task<string> GetDefaultPictureUrl(int targetSize = 0, string storeLocation = null)
{
var filePath = await GetPicturePhysicalPath(_mediaSettings.DefaultImageName);
- if (string.IsNullOrEmpty(filePath)) return _mediaFileStore.Combine(CommonPath.ImagePath, "no-image.png");
+ if (string.IsNullOrEmpty(filePath)) return _mediaFileStore.Combine(ImagePath, "no-image.png");
if (targetSize == 0)
return !string.IsNullOrEmpty(storeLocation)
? storeLocation
- : _mediaFileStore.Combine(CommonPath.ImagePath, _mediaSettings.DefaultImageName);
+ : _mediaFileStore.Combine(ImagePath, _mediaSettings.DefaultImageName);
var fileExtension = Path.GetExtension(filePath);
var thumbFileName = $"{Path.GetFileNameWithoutExtension(filePath)}_{targetSize}{fileExtension}";
@@ -686,7 +688,7 @@ public class PictureService : IPictureService
{
var lastPart = GetFileExtensionFromMimeType(mimeType);
var fileName = $"{pictureId}_0.{lastPart}";
- var dirPath = _mediaFileStore.GetDirectoryInfo(CommonPath.ImagePath);
+ var dirPath = _mediaFileStore.GetDirectoryInfo(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.cs
index acaa6982e..4be23f134 100644
--- a/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs
+++ b/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs
@@ -21,12 +21,6 @@ public static class CommonPath
/// <returns>The physical path.</returns>
public static string PluginsPath => Path.Combine(BaseDirectory, "Plugins");
- /// <summary>
- /// Maps a image path.
- /// </summary>
- /// <returns>The path.</returns>
- public static string ImagePath => Path.Combine("assets", "images");
-
/// <summary>
/// Maps a image thumb path.
/// </summary>