mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Fixing profile folders logic
Keep filename unchanged for SEO purpose. Use hashcode hexadecimal version of folder names
This commit is contained in:
@@ -109,7 +109,7 @@ namespace Orchard.MediaProcessing.Services {
|
||||
|
||||
using (var image = GetImage(path)) {
|
||||
|
||||
var filterContext = new FilterContext { Media = image, FilePath = _storageProvider.Combine("_Profiles", _storageProvider.Combine(profileName, CreateDefaultFileName(path))) };
|
||||
var filterContext = new FilterContext { Media = image, FilePath = _storageProvider.Combine("_Profiles", FormatProfilePath(profileName, path)) };
|
||||
|
||||
if (image == null) {
|
||||
return filterContext.FilePath;
|
||||
@@ -134,7 +134,6 @@ namespace Orchard.MediaProcessing.Services {
|
||||
_fileNameProvider.UpdateFileName(profileName, path, filterContext.FilePath);
|
||||
|
||||
if (!filterContext.Saved) {
|
||||
_storageProvider.TryCreateFolder(_storageProvider.Combine("_Profiles", profilePart.Name));
|
||||
var newFile = _storageProvider.OpenOrCreate(filterContext.FilePath);
|
||||
using (var imageStream = newFile.OpenWrite()) {
|
||||
using (var sw = new BinaryWriter(imageStream)) {
|
||||
@@ -206,14 +205,14 @@ namespace Orchard.MediaProcessing.Services {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static string CreateDefaultFileName(string path) {
|
||||
var extention = Path.GetExtension(path);
|
||||
var utf8Bytes = System.Text.Encoding.UTF8.GetBytes(path);
|
||||
using (var provider = new MD5CryptoServiceProvider()) {
|
||||
var hash = provider.ComputeHash(utf8Bytes);
|
||||
var encodedHash = Convert.ToBase64String(hash);
|
||||
return encodedHash + extention;
|
||||
}
|
||||
private string FormatProfilePath(string profileName, string path) {
|
||||
|
||||
var filenameWithExtension = Path.GetFileName(path) ?? "";
|
||||
var fileLocation = path.Substring(0, path.Length - filenameWithExtension.Length);
|
||||
|
||||
return _storageProvider.Combine(
|
||||
_storageProvider.Combine(profileName.GetHashCode().ToString("x").ToLowerInvariant(), fileLocation.GetHashCode().ToString("x").ToLowerInvariant()),
|
||||
filenameWithExtension);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user