mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-20 19:03:25 +08:00
Storing local paths when possible in media
--HG-- branch : 1.x
This commit is contained in:
@@ -276,6 +276,11 @@ namespace Orchard.Tests.Modules.Media.Services {
|
|||||||
public string GetLocalPath(string url) {
|
public string GetLocalPath(string url) {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public string GetRelativePath(string path) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class StubStorageFolder : IStorageFolder {
|
private class StubStorageFolder : IStorageFolder {
|
||||||
|
@@ -54,7 +54,7 @@ namespace Orchard.MediaLibrary.Factories {
|
|||||||
_storageProvider.CreateFolder(BaseFolder);
|
_storageProvider.CreateFolder(BaseFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
part.Resource = _storageProvider.GetPublicUrl(_storageProvider.Combine(BaseFolder, uniquePath));
|
part.Resource = _storageProvider.GetRelativePath(_storageProvider.Combine(BaseFolder, uniquePath));
|
||||||
part.MimeType = mimeType;
|
part.MimeType = mimeType;
|
||||||
part.Title = Path.GetFileNameWithoutExtension(path);
|
part.Title = Path.GetFileNameWithoutExtension(path);
|
||||||
|
|
||||||
|
@@ -177,6 +177,10 @@ namespace Orchard.MediaProcessing.Shapes {
|
|||||||
// /OrchardLocal/images/my-image.jpg
|
// /OrchardLocal/images/my-image.jpg
|
||||||
if (Uri.IsWellFormedUriString(path, UriKind.Relative)) {
|
if (Uri.IsWellFormedUriString(path, UriKind.Relative)) {
|
||||||
path = storageProvider.Value.GetLocalPath(path);
|
path = storageProvider.Value.GetLocalPath(path);
|
||||||
|
|
||||||
|
// images/my-image.jpg
|
||||||
|
var file = storageProvider.Value.GetFile(path);
|
||||||
|
return file.OpenRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://blob.storage-provider.net/my-image.jpg
|
// http://blob.storage-provider.net/my-image.jpg
|
||||||
@@ -190,9 +194,7 @@ namespace Orchard.MediaProcessing.Shapes {
|
|||||||
return webClient.OpenRead(new Uri(request.Url, VirtualPathUtility.ToAbsolute(path)));
|
return webClient.OpenRead(new Uri(request.Url, VirtualPathUtility.ToAbsolute(path)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// images/my-image.jpg
|
throw new ArgumentException("invalid path");
|
||||||
var file = storageProvider.Value.GetFile(path);
|
|
||||||
return file.OpenRead();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string CreateDefaultFileName(string path) {
|
private static string CreateDefaultFileName(string path) {
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web;
|
|
||||||
using System.Web.Hosting;
|
using System.Web.Hosting;
|
||||||
using Orchard.Environment.Configuration;
|
using Orchard.Environment.Configuration;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
@@ -12,6 +11,7 @@ namespace Orchard.FileSystems.Media {
|
|||||||
public class FileSystemStorageProvider : IStorageProvider {
|
public class FileSystemStorageProvider : IStorageProvider {
|
||||||
private readonly string _storagePath;
|
private readonly string _storagePath;
|
||||||
private readonly string _publicPath;
|
private readonly string _publicPath;
|
||||||
|
private readonly string _relativePath;
|
||||||
|
|
||||||
public FileSystemStorageProvider(ShellSettings settings) {
|
public FileSystemStorageProvider(ShellSettings settings) {
|
||||||
var mediaPath = HostingEnvironment.IsHosted
|
var mediaPath = HostingEnvironment.IsHosted
|
||||||
@@ -29,6 +29,7 @@ namespace Orchard.FileSystems.Media {
|
|||||||
if (!appPath.StartsWith("/"))
|
if (!appPath.StartsWith("/"))
|
||||||
appPath = '/' + appPath;
|
appPath = '/' + appPath;
|
||||||
|
|
||||||
|
_relativePath = "~/Media/" + settings.Name + "/";
|
||||||
_publicPath = appPath + "Media/" + settings.Name + "/";
|
_publicPath = appPath + "Media/" + settings.Name + "/";
|
||||||
|
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
@@ -83,12 +84,20 @@ namespace Orchard.FileSystems.Media {
|
|||||||
return MapPublic(path);
|
return MapPublic(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetRelativePath(string path) {
|
||||||
|
return (_relativePath + path).Replace(Path.DirectorySeparatorChar, '/');
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves the local path for a given url within the storage provider.
|
/// Retrieves the local path for a given url within the storage provider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url">The public url of the media.</param>
|
/// <param name="url">The public url of the media.</param>
|
||||||
/// <returns>The local path.</returns>
|
/// <returns>The local path.</returns>
|
||||||
public string GetLocalPath(string url) {
|
public string GetLocalPath(string url) {
|
||||||
|
if (url.StartsWith(_relativePath)) {
|
||||||
|
return url.Substring(_relativePath.Length);
|
||||||
|
}
|
||||||
|
|
||||||
if (!url.StartsWith(_publicPath)) {
|
if (!url.StartsWith(_publicPath)) {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,13 @@ namespace Orchard.FileSystems.Media {
|
|||||||
/// <returns>The local path.</returns>
|
/// <returns>The local path.</returns>
|
||||||
string GetLocalPath(string url);
|
string GetLocalPath(string url);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves the relative path for a given url within the storage provider.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The relative path withing the storage provider.</param>
|
||||||
|
/// <returns>The relative path, or null if the .</returns>
|
||||||
|
string GetRelativePath(string path);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves a file within the storage provider.
|
/// Retrieves a file within the storage provider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Reference in New Issue
Block a user