Skip to content

Commit

Permalink
Merge branch 'issue-3959-RoxyFileman-image-size-init-from-media-setti…
Browse files Browse the repository at this point in the history
…ngs' into develop
  • Loading branch information
holydk committed Oct 25, 2019
2 parents aae1577 + c9f7e89 commit 65f357b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using Nop.Core;
using Nop.Core.Domain.Media;
using Nop.Core.Infrastructure;

namespace Nop.Services.Media.RoxyFileman
Expand All @@ -23,6 +24,7 @@ public abstract partial class BaseRoxyFilemanService
protected readonly INopFileProvider _fileProvider;
protected readonly IWebHelper _webHelper;
protected readonly IWorkContext _workContext;
protected readonly MediaSettings _mediaSettings;

#endregion

Expand All @@ -32,13 +34,15 @@ protected BaseRoxyFilemanService(IHostingEnvironment hostingEnvironment,
IHttpContextAccessor httpContextAccessor,
INopFileProvider fileProvider,
IWebHelper webHelper,
IWorkContext workContext)
IWorkContext workContext,
MediaSettings mediaSettings)
{
_hostingEnvironment = hostingEnvironment;
_httpContextAccessor = httpContextAccessor;
_fileProvider = fileProvider;
_webHelper = webHelper;
_workContext = workContext;
_mediaSettings = mediaSettings;
}

#endregion
Expand Down Expand Up @@ -360,8 +364,8 @@ public virtual void CreateConfiguration()
THUMBS_VIEW_HEIGHT = existingConfiguration?.THUMBS_VIEW_HEIGHT ?? "120",
PREVIEW_THUMB_WIDTH = existingConfiguration?.PREVIEW_THUMB_WIDTH ?? "300",
PREVIEW_THUMB_HEIGHT = existingConfiguration?.PREVIEW_THUMB_HEIGHT ?? "200",
MAX_IMAGE_WIDTH = existingConfiguration?.MAX_IMAGE_WIDTH ?? "1000",
MAX_IMAGE_HEIGHT = existingConfiguration?.MAX_IMAGE_HEIGHT ?? "1000",
MAX_IMAGE_WIDTH = existingConfiguration?.MAX_IMAGE_WIDTH ?? _mediaSettings.MaximumImageSize.ToString(),
MAX_IMAGE_HEIGHT = existingConfiguration?.MAX_IMAGE_HEIGHT ?? _mediaSettings.MaximumImageSize.ToString(),
DEFAULTVIEW = existingConfiguration?.DEFAULTVIEW ?? "list",
FORBIDDEN_UPLOADS = existingConfiguration?.FORBIDDEN_UPLOADS ?? "zip js jsp jsb mhtml mht xhtml xht php phtml " +
"php3 php4 php5 phps shtml jhtml pl sh py cgi exe application gadget hta cpl msc jar vb jse ws wsf wsc wsh " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class DatabaseRoxyFilemanService : FileRoxyFilemanService

private readonly IPictureService _pictureService;
private readonly IRepository<Picture> _pictureRepository;
private readonly MediaSettings _mediaSettings;

#endregion

Expand All @@ -46,11 +45,10 @@ public DatabaseRoxyFilemanService(IPictureService pictureService,
INopFileProvider fileProvider,
IWebHelper webHelper,
IWorkContext workContext,
MediaSettings mediaSettings) : base(hostingEnvironment, httpContextAccessor, fileProvider, webHelper, workContext)
MediaSettings mediaSettings) : base(hostingEnvironment, httpContextAccessor, fileProvider, webHelper, workContext, mediaSettings)
{
_pictureService = pictureService;
_pictureRepository = pictureRepository;
_mediaSettings = mediaSettings;
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using Nop.Core;
using Nop.Core.Domain.Media;
using Nop.Core.Infrastructure;

namespace Nop.Services.Media.RoxyFileman
Expand All @@ -33,7 +34,8 @@ public FileRoxyFilemanService(IHostingEnvironment hostingEnvironment,
IHttpContextAccessor httpContextAccessor,
INopFileProvider fileProvider,
IWebHelper webHelper,
IWorkContext workContext) : base(hostingEnvironment, httpContextAccessor, fileProvider, webHelper, workContext)
IWorkContext workContext,
MediaSettings mediaSettings) : base(hostingEnvironment, httpContextAccessor, fileProvider, webHelper, workContext, mediaSettings)
{
_fileRootPath = null;
}
Expand Down Expand Up @@ -77,7 +79,7 @@ protected virtual void CopyDirectory(string sourcePath, string destinationPath)
/// <returns>List of paths to the files</returns>
protected virtual List<string> GetFiles(string directoryPath, string type)
{
if(!IsPathAllowed(directoryPath))
if (!IsPathAllowed(directoryPath))
return new List<string>();

if (type == "#")
Expand Down Expand Up @@ -180,9 +182,9 @@ protected virtual bool IsPathAllowed(string path)
{
var absp = _fileProvider.GetAbsolutePath(path);

if(string.IsNullOrEmpty(_fileRootPath))
if (string.IsNullOrEmpty(_fileRootPath))
Configure();

return new DirectoryInfo(absp).FullName.StartsWith(_fileRootPath);
}

Expand All @@ -198,7 +200,7 @@ protected virtual bool IsPathAllowed(string path)
public virtual void Configure()
{
CreateConfiguration();

var existingText = _fileProvider.ReadAllText(GetConfigurationFilePath(), Encoding.UTF8);
var config = JsonConvert.DeserializeObject<Dictionary<string, string>>(existingText);
_fileRootPath = _fileProvider.GetAbsolutePath(config["FILES_ROOT"]);
Expand Down

0 comments on commit 65f357b

Please sign in to comment.