mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-24 05:23:33 +08:00
Adjusting Orchard.Media module for storage path conventions
IMediaService no longer calculates root path as physical folder Public urls are provided by IStorageProvider --HG-- branch : dev
This commit is contained in:
25
src/Orchard.Specs/Media.feature
Normal file
25
src/Orchard.Specs/Media.feature
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
Feature: Media management
|
||||||
|
In order to reference images and such from content
|
||||||
|
As an author
|
||||||
|
I want to upload and manage files in a media folder
|
||||||
|
|
||||||
|
Scenario: Media admin is available
|
||||||
|
Given I have installed Orchard
|
||||||
|
And I have installed "Orchard.Media"
|
||||||
|
When I go to "admin/media"
|
||||||
|
Then I should see "Manage Media Folders"
|
||||||
|
And the status should be 200 OK
|
||||||
|
|
||||||
|
Scenario: Creating a folder
|
||||||
|
Given I have installed Orchard
|
||||||
|
And I have installed "Orchard.Media"
|
||||||
|
When I go to "admin/media/create"
|
||||||
|
And I fill in
|
||||||
|
| name | value |
|
||||||
|
| Name | Hello World |
|
||||||
|
And I hit "Save"
|
||||||
|
And I am redirected
|
||||||
|
Then I should see "Manage Media Folders"
|
||||||
|
And I should see "Hello World"
|
||||||
|
And the status should be 200 OK
|
||||||
|
|
110
src/Orchard.Specs/Media.feature.cs
generated
Normal file
110
src/Orchard.Specs/Media.feature.cs
generated
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
// ------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// This code was generated by SpecFlow (http://www.specflow.org/).
|
||||||
|
// SpecFlow Version:1.2.0.0
|
||||||
|
// Runtime Version:2.0.50727.4927
|
||||||
|
//
|
||||||
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
|
// the code is regenerated.
|
||||||
|
// </auto-generated>
|
||||||
|
// ------------------------------------------------------------------------------
|
||||||
|
namespace Orchard.Specs
|
||||||
|
{
|
||||||
|
using TechTalk.SpecFlow;
|
||||||
|
|
||||||
|
|
||||||
|
[NUnit.Framework.TestFixtureAttribute()]
|
||||||
|
[NUnit.Framework.DescriptionAttribute("Media management")]
|
||||||
|
public partial class MediaManagementFeature
|
||||||
|
{
|
||||||
|
|
||||||
|
private static TechTalk.SpecFlow.ITestRunner testRunner;
|
||||||
|
|
||||||
|
#line 1 "Media.feature"
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
[NUnit.Framework.TestFixtureSetUpAttribute()]
|
||||||
|
public virtual void FeatureSetup()
|
||||||
|
{
|
||||||
|
testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner();
|
||||||
|
TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Media management", "In order to reference images and such from content\r\nAs an author\r\nI want to uploa" +
|
||||||
|
"d and manage files in a media folder", ((string[])(null)));
|
||||||
|
testRunner.OnFeatureStart(featureInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
[NUnit.Framework.TestFixtureTearDownAttribute()]
|
||||||
|
public virtual void FeatureTearDown()
|
||||||
|
{
|
||||||
|
testRunner.OnFeatureEnd();
|
||||||
|
testRunner = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo)
|
||||||
|
{
|
||||||
|
testRunner.OnScenarioStart(scenarioInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
[NUnit.Framework.TearDownAttribute()]
|
||||||
|
public virtual void ScenarioTearDown()
|
||||||
|
{
|
||||||
|
testRunner.OnScenarioEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
[NUnit.Framework.TestAttribute()]
|
||||||
|
[NUnit.Framework.DescriptionAttribute("Media admin is available")]
|
||||||
|
public virtual void MediaAdminIsAvailable()
|
||||||
|
{
|
||||||
|
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Media admin is available", ((string[])(null)));
|
||||||
|
#line 6
|
||||||
|
this.ScenarioSetup(scenarioInfo);
|
||||||
|
#line 7
|
||||||
|
testRunner.Given("I have installed Orchard");
|
||||||
|
#line 8
|
||||||
|
testRunner.And("I have installed \"Orchard.Media\"");
|
||||||
|
#line 9
|
||||||
|
testRunner.When("I go to \"admin/media\"");
|
||||||
|
#line 10
|
||||||
|
testRunner.Then("I should see \"Manage Media Folders\"");
|
||||||
|
#line 11
|
||||||
|
testRunner.And("the status should be 200 OK");
|
||||||
|
#line hidden
|
||||||
|
testRunner.CollectScenarioErrors();
|
||||||
|
}
|
||||||
|
|
||||||
|
[NUnit.Framework.TestAttribute()]
|
||||||
|
[NUnit.Framework.DescriptionAttribute("Creating a folder")]
|
||||||
|
public virtual void CreatingAFolder()
|
||||||
|
{
|
||||||
|
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Creating a folder", ((string[])(null)));
|
||||||
|
#line 13
|
||||||
|
this.ScenarioSetup(scenarioInfo);
|
||||||
|
#line 14
|
||||||
|
testRunner.Given("I have installed Orchard");
|
||||||
|
#line 15
|
||||||
|
testRunner.And("I have installed \"Orchard.Media\"");
|
||||||
|
#line 16
|
||||||
|
testRunner.When("I go to \"admin/media/create\"");
|
||||||
|
#line hidden
|
||||||
|
TechTalk.SpecFlow.Table table1 = new TechTalk.SpecFlow.Table(new string[] {
|
||||||
|
"name",
|
||||||
|
"value"});
|
||||||
|
table1.AddRow(new string[] {
|
||||||
|
"Name",
|
||||||
|
"Hello World"});
|
||||||
|
#line 17
|
||||||
|
testRunner.And("I fill in", ((string)(null)), table1);
|
||||||
|
#line 20
|
||||||
|
testRunner.And("I hit \"Save\"");
|
||||||
|
#line 21
|
||||||
|
testRunner.And("I am redirected");
|
||||||
|
#line 22
|
||||||
|
testRunner.Then("I should see \"Manage Media Folders\"");
|
||||||
|
#line 23
|
||||||
|
testRunner.And("I should see \"Hello World\"");
|
||||||
|
#line 24
|
||||||
|
testRunner.And("the status should be 200 OK");
|
||||||
|
#line hidden
|
||||||
|
testRunner.CollectScenarioErrors();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -112,6 +112,11 @@
|
|||||||
<Compile Include="Hosting\RequestExtensions.cs" />
|
<Compile Include="Hosting\RequestExtensions.cs" />
|
||||||
<Compile Include="Hosting\RequestDetails.cs" />
|
<Compile Include="Hosting\RequestDetails.cs" />
|
||||||
<Compile Include="Hosting\Simple.Web\Global.asax.cs" />
|
<Compile Include="Hosting\Simple.Web\Global.asax.cs" />
|
||||||
|
<Compile Include="Media.feature.cs">
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
<DependentUpon>Media.feature</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="Modules.feature.cs">
|
<Compile Include="Modules.feature.cs">
|
||||||
<AutoGen>True</AutoGen>
|
<AutoGen>True</AutoGen>
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
@@ -171,6 +176,10 @@
|
|||||||
<Content Include="Hosting\Orchard.Web\Config\Host.config">
|
<Content Include="Hosting\Orchard.Web\Config\Host.config">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
<None Include="Media.feature">
|
||||||
|
<Generator>SpecFlowSingleFileGenerator</Generator>
|
||||||
|
<LastGenOutput>Media.feature.cs</LastGenOutput>
|
||||||
|
</None>
|
||||||
<None Include="Modules.feature">
|
<None Include="Modules.feature">
|
||||||
<Generator>SpecFlowSingleFileGenerator</Generator>
|
<Generator>SpecFlowSingleFileGenerator</Generator>
|
||||||
<LastGenOutput>Modules.feature.cs</LastGenOutput>
|
<LastGenOutput>Modules.feature.cs</LastGenOutput>
|
||||||
|
@@ -186,9 +186,9 @@ namespace Orchard.Media.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var file = Request.Files[0];
|
var file = Request.Files[0];
|
||||||
_mediaService.UploadMediaFile(viewModel.MediaPath, file);
|
var publicUrl = _mediaService.UploadMediaFile(viewModel.MediaPath, file);
|
||||||
|
|
||||||
return Content(string.Format("<script type=\"text/javascript\">var result = {{ url: \"{0}\" }};</script>", Path.Combine(_mediaService.GetRootUrl(), string.Format("{0}/{1}", viewModel.MediaPath, Path.GetFileName(file.FileName)).Replace("//", "/")).Replace("\\", "/")));
|
return Content(string.Format("<script type=\"text/javascript\">var result = {{ url: \"{0}\" }};</script>", publicUrl));
|
||||||
}
|
}
|
||||||
catch (Exception exception) {
|
catch (Exception exception) {
|
||||||
return Content(string.Format("<script type=\"text/javascript\">var result = {{ error: \"{0}\" }};</script>", T("ERROR: Uploading media file failed: {0}", exception.Message)));
|
return Content(string.Format("<script type=\"text/javascript\">var result = {{ error: \"{0}\" }};</script>", T("ERROR: Uploading media file failed: {0}", exception.Message)));
|
||||||
@@ -203,6 +203,7 @@ namespace Orchard.Media.Controllers {
|
|||||||
model.Size = size;
|
model.Size = size;
|
||||||
model.FolderName = folderName;
|
model.FolderName = folderName;
|
||||||
model.MediaPath = mediaPath;
|
model.MediaPath = mediaPath;
|
||||||
|
model.PublicUrl = _mediaService.GetPublicUrl(Path.Combine(mediaPath, name));
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@ using Orchard.Media.Models;
|
|||||||
|
|
||||||
namespace Orchard.Media.Services {
|
namespace Orchard.Media.Services {
|
||||||
public interface IMediaService : IDependency {
|
public interface IMediaService : IDependency {
|
||||||
string GetRootUrl();
|
string GetPublicUrl(string path);
|
||||||
IEnumerable<MediaFolder> GetMediaFolders(string path);
|
IEnumerable<MediaFolder> GetMediaFolders(string path);
|
||||||
IEnumerable<MediaFile> GetMediaFiles(string path);
|
IEnumerable<MediaFile> GetMediaFiles(string path);
|
||||||
void CreateFolder(string path, string name);
|
void CreateFolder(string path, string name);
|
||||||
@@ -12,6 +12,6 @@ namespace Orchard.Media.Services {
|
|||||||
void RenameFolder(string path, string newName);
|
void RenameFolder(string path, string newName);
|
||||||
void DeleteFile(string name, string folderName);
|
void DeleteFile(string name, string folderName);
|
||||||
void RenameFile(string name, string newName, string folderName);
|
void RenameFile(string name, string newName, string folderName);
|
||||||
void UploadMediaFile(string folderName, HttpPostedFileBase postedFile);
|
string UploadMediaFile(string folderName, HttpPostedFileBase postedFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -13,38 +13,29 @@ namespace Orchard.Media.Services {
|
|||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public class MediaService : IMediaService {
|
public class MediaService : IMediaService {
|
||||||
private readonly IStorageProvider _storageProvider;
|
private readonly IStorageProvider _storageProvider;
|
||||||
private readonly string _rootPath;
|
|
||||||
private readonly string _rootUrl;
|
|
||||||
|
|
||||||
public MediaService (
|
public MediaService(
|
||||||
IStorageProvider storageProvider) {
|
IStorageProvider storageProvider) {
|
||||||
_storageProvider = storageProvider;
|
_storageProvider = storageProvider;
|
||||||
_rootPath = HttpContext.Current.Server.MapPath("~/Media");
|
|
||||||
_rootUrl = Path.Combine(HttpContext.Current.Request.ApplicationPath, "Media").Replace("\\", "/");
|
|
||||||
Logger = NullLogger.Instance;
|
Logger = NullLogger.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ILogger Logger { get; set; }
|
public ILogger Logger { get; set; }
|
||||||
|
|
||||||
public string GetRootUrl() {
|
public string GetPublicUrl(string path) {
|
||||||
return _rootUrl;
|
return _storageProvider.GetPublicUrl(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<MediaFolder> GetMediaFolders(string path) {
|
public IEnumerable<MediaFolder> GetMediaFolders(string path) {
|
||||||
var mediaFolders = new List<MediaFolder>();
|
var mediaFolders = new List<MediaFolder>();
|
||||||
var folders = (
|
var folders = _storageProvider.ListFolders(path);
|
||||||
path == null ?
|
|
||||||
_storageProvider.ListFolders(_rootPath) :
|
|
||||||
_storageProvider.ListFolders(_rootPath + "\\" + path));
|
|
||||||
|
|
||||||
foreach (var folder in folders) {
|
foreach (var folder in folders) {
|
||||||
var parentHierarchy = GetParentHierarchy(folder);
|
|
||||||
var mediaPath = GetMediaPath(parentHierarchy, folder.GetName());
|
|
||||||
var mediaFolder = new MediaFolder {
|
var mediaFolder = new MediaFolder {
|
||||||
Name = folder.GetName(),
|
Name = folder.GetName(),
|
||||||
Size = folder.GetSize(),
|
Size = folder.GetSize(),
|
||||||
LastUpdated = folder.GetLastUpdated(),
|
LastUpdated = folder.GetLastUpdated(),
|
||||||
MediaPath = mediaPath
|
MediaPath = folder.GetPath(),
|
||||||
};
|
};
|
||||||
mediaFolders.Add(mediaFolder);
|
mediaFolders.Add(mediaFolder);
|
||||||
}
|
}
|
||||||
@@ -54,13 +45,13 @@ namespace Orchard.Media.Services {
|
|||||||
public IEnumerable<MediaFile> GetMediaFiles(string path) {
|
public IEnumerable<MediaFile> GetMediaFiles(string path) {
|
||||||
var mediaFiles = new List<MediaFile>();
|
var mediaFiles = new List<MediaFile>();
|
||||||
|
|
||||||
var files = _storageProvider.ListFiles(_rootPath + "\\" + path);
|
var files = _storageProvider.ListFiles(path);
|
||||||
foreach (var file in files) {
|
foreach (var file in files) {
|
||||||
var mediaFile = new MediaFile {
|
var mediaFile = new MediaFile {
|
||||||
Name = file.GetName(),
|
Name = file.GetName(),
|
||||||
Size = file.GetSize(),
|
Size = file.GetSize(),
|
||||||
LastUpdated = file.GetLastUpdated(),
|
LastUpdated = file.GetLastUpdated(),
|
||||||
Type = file.GetFileType(),
|
Type = file.GetFileType(),
|
||||||
FolderName = path
|
FolderName = path
|
||||||
};
|
};
|
||||||
mediaFiles.Add(mediaFile);
|
mediaFiles.Add(mediaFile);
|
||||||
@@ -71,44 +62,63 @@ namespace Orchard.Media.Services {
|
|||||||
//TODO: Use Path.Combine.
|
//TODO: Use Path.Combine.
|
||||||
public void CreateFolder(string mediaPath, string name) {
|
public void CreateFolder(string mediaPath, string name) {
|
||||||
if (String.IsNullOrEmpty(mediaPath)) {
|
if (String.IsNullOrEmpty(mediaPath)) {
|
||||||
_storageProvider.CreateFolder(_rootPath + "\\" + name);
|
_storageProvider.CreateFolder(name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_storageProvider.CreateFolder(_rootPath + "\\" + mediaPath + "\\" + name);
|
_storageProvider.CreateFolder(mediaPath + "\\" + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteFolder(string name) {
|
public void DeleteFolder(string name) {
|
||||||
_storageProvider.DeleteFolder(_rootPath + "\\" + name);
|
_storageProvider.DeleteFolder(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RenameFolder(string path, string newName) {
|
public void RenameFolder(string path, string newName) {
|
||||||
var newPath = RenameFolderPath(path, newName);
|
var newPath = RenameFolderPath(path, newName);
|
||||||
_storageProvider.RenameFolder(_rootPath + "\\" + path, _rootPath + "\\" + newPath);
|
_storageProvider.RenameFolder(path, newPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteFile(string name, string folderName) {
|
public void DeleteFile(string name, string folderName) {
|
||||||
_storageProvider.DeleteFile(_rootPath + "\\" + folderName + "\\" + name);
|
_storageProvider.DeleteFile(folderName + "\\" + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RenameFile(string name, string newName, string folderName) {
|
public void RenameFile(string name, string newName, string folderName) {
|
||||||
_storageProvider.RenameFile(_rootPath + "\\" + folderName + "\\" + name, _rootPath + "\\" + folderName + "\\" + newName);
|
_storageProvider.RenameFile(folderName + "\\" + name, folderName + "\\" + newName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UploadMediaFile(string folderName, HttpPostedFileBase postedFile) {
|
public string UploadMediaFile(string folderName, HttpPostedFileBase postedFile) {
|
||||||
var targetFolder = HttpContext.Current.Server.MapPath("~/Media/" + folderName);
|
|
||||||
if (postedFile.FileName.EndsWith(".zip")) {
|
if (postedFile.FileName.EndsWith(".zip")) {
|
||||||
UnzipMediaFileArchive(targetFolder, postedFile);
|
UnzipMediaFileArchive(folderName, postedFile);
|
||||||
// Don't save the zip file.
|
// Don't save the zip file.
|
||||||
return;
|
return _storageProvider.GetPublicUrl(folderName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (postedFile.ContentLength > 0) {
|
if (postedFile.ContentLength > 0) {
|
||||||
string filePath = Path.Combine(targetFolder,
|
var filePath = Path.Combine(folderName, Path.GetFileName(postedFile.FileName));
|
||||||
Path.GetFileName(postedFile.FileName));
|
var inputStream = postedFile.InputStream;
|
||||||
postedFile.SaveAs(filePath);
|
|
||||||
|
SaveStream(filePath, inputStream);
|
||||||
|
return _storageProvider.GetPublicUrl(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UnzipMediaFileArchive(string targetFolder, HttpPostedFileBase postedFile) {
|
private void SaveStream(string filePath, Stream inputStream) {
|
||||||
|
var file = _storageProvider.CreateFile(filePath);
|
||||||
|
var outputStream = file.OpenWrite();
|
||||||
|
var buffer = new byte[8192];
|
||||||
|
for (; ; ) {
|
||||||
|
|
||||||
|
var length = inputStream.Read(buffer, 0, buffer.Length);
|
||||||
|
if (length <= 0)
|
||||||
|
break;
|
||||||
|
outputStream.Write(buffer, 0, length);
|
||||||
|
}
|
||||||
|
outputStream.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UnzipMediaFileArchive(string targetFolder, HttpPostedFileBase postedFile) {
|
||||||
var postedFileLength = postedFile.ContentLength;
|
var postedFileLength = postedFile.ContentLength;
|
||||||
var postedFileStream = postedFile.InputStream;
|
var postedFileStream = postedFile.InputStream;
|
||||||
var postedFileData = new byte[postedFileLength];
|
var postedFileData = new byte[postedFileLength];
|
||||||
@@ -124,46 +134,22 @@ namespace Orchard.Media.Services {
|
|||||||
// before the directories that contain them, so we create directories as soon as first
|
// before the directories that contain them, so we create directories as soon as first
|
||||||
// file below their path is encountered.
|
// file below their path is encountered.
|
||||||
while ((entry = fileInflater.GetNextEntry()) != null) {
|
while ((entry = fileInflater.GetNextEntry()) != null) {
|
||||||
var directoryName = Path.GetDirectoryName(entry.Name);
|
|
||||||
if (!Directory.Exists(Path.Combine(targetFolder, directoryName))) {
|
|
||||||
Directory.CreateDirectory(Path.Combine(targetFolder, directoryName));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!entry.IsDirectory && entry.Name.Length > 0) {
|
if (!entry.IsDirectory && entry.Name.Length > 0) {
|
||||||
var len = Convert.ToInt32(entry.Size);
|
var entryName = Path.Combine(targetFolder, entry.Name);
|
||||||
var extractedBytes = new byte[len];
|
var directoryName = Path.GetDirectoryName(entryName);
|
||||||
fileInflater.Read(extractedBytes, 0, len);
|
|
||||||
File.WriteAllBytes(Path.Combine(targetFolder, entry.Name), extractedBytes);
|
try { _storageProvider.CreateFolder(directoryName); }
|
||||||
|
catch {
|
||||||
|
// no handling needed - this is to force the folder to exist if it doesn't
|
||||||
|
}
|
||||||
|
|
||||||
|
SaveStream(entryName, fileInflater);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<string> GetParentHierarchy(IStorageFolder folder) {
|
|
||||||
var parentHierarchy = new List<string>();
|
|
||||||
do {
|
|
||||||
IStorageFolder parentFolder = folder.GetParent();
|
|
||||||
string parentName = parentFolder.GetName();
|
|
||||||
if (String.Equals(parentName, "Media", StringComparison.OrdinalIgnoreCase)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
parentHierarchy.Insert(0, parentName);
|
|
||||||
folder = parentFolder;
|
|
||||||
} while (true);
|
|
||||||
|
|
||||||
return parentHierarchy;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string GetMediaPath(IEnumerable<string> parentHierarchy, string folderName) {
|
|
||||||
var mediaPath = new StringBuilder();
|
|
||||||
foreach (string parent in parentHierarchy) {
|
|
||||||
mediaPath.Append(parent);
|
|
||||||
mediaPath.Append("\\");
|
|
||||||
}
|
|
||||||
mediaPath.Append(folderName);
|
|
||||||
return mediaPath.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string RenameFolderPath(string path, string newName) {
|
private static string RenameFolderPath(string path, string newName) {
|
||||||
var lastIndex = path.LastIndexOf("\\");
|
var lastIndex = path.LastIndexOf("\\");
|
||||||
|
|
||||||
|
@@ -14,5 +14,7 @@ namespace Orchard.Media.ViewModels {
|
|||||||
return MediaPath.Replace("\\", "/");
|
return MediaPath.Replace("\\", "/");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string PublicUrl { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
<%= Html.ValidationSummary() %>
|
<%= Html.ValidationSummary() %>
|
||||||
<div class="primary">
|
<div class="primary">
|
||||||
<div>
|
<div>
|
||||||
<img src="<%=ResolveUrl("~/Media/" + Html.Encode(Model.RelativePath + "/" + Model.Name))%>" class="previewImage" alt="<%=Html.Encode(Model.Caption) %>" />
|
<img src="<%=Model.PublicUrl%>" class="previewImage" alt="<%=Html.Encode(Model.Caption) %>" />
|
||||||
</div>
|
</div>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<%-- todo: make these real (including markup) --%>
|
<%-- todo: make these real (including markup) --%>
|
||||||
|
@@ -82,7 +82,7 @@ namespace Orchard.Setup.Controllers {
|
|||||||
"Orchard.Themes",
|
"Orchard.Themes",
|
||||||
"Orchard.MultiTenancy",
|
"Orchard.MultiTenancy",
|
||||||
"Orchard.Pages",
|
"Orchard.Pages",
|
||||||
"Orchard.Comments" };
|
"Orchard.Comments"};
|
||||||
|
|
||||||
var setupContext = new SetupContext {
|
var setupContext = new SetupContext {
|
||||||
SiteName = model.SiteName,
|
SiteName = model.SiteName,
|
||||||
|
@@ -7,30 +7,47 @@ using Orchard.Environment.Configuration;
|
|||||||
|
|
||||||
namespace Orchard.Storage {
|
namespace Orchard.Storage {
|
||||||
public class FileSystemStorageProvider : IStorageProvider {
|
public class FileSystemStorageProvider : IStorageProvider {
|
||||||
private readonly ShellSettings _settings;
|
private readonly string _storagePath;
|
||||||
private string _storagePath;
|
private readonly string _publicPath;
|
||||||
|
|
||||||
public FileSystemStorageProvider(ShellSettings settings) {
|
public FileSystemStorageProvider(ShellSettings settings) {
|
||||||
_settings = settings;
|
|
||||||
|
|
||||||
var mediaPath = HostingEnvironment.IsHosted
|
var mediaPath = HostingEnvironment.IsHosted
|
||||||
? HostingEnvironment.MapPath("~/Media/")
|
? HostingEnvironment.MapPath("~/Media/") ?? ""
|
||||||
: Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Media");
|
: Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Media");
|
||||||
|
|
||||||
_storagePath = Path.Combine(mediaPath, settings.Name);
|
_storagePath = Path.Combine(mediaPath, settings.Name);
|
||||||
|
|
||||||
|
var appPath = "";
|
||||||
|
if (HostingEnvironment.IsHosted) {
|
||||||
|
appPath = HostingEnvironment.ApplicationVirtualPath;
|
||||||
|
}
|
||||||
|
if (!appPath.EndsWith("/"))
|
||||||
|
appPath = appPath + '/';
|
||||||
|
if (!appPath.StartsWith("/"))
|
||||||
|
appPath = '/' + appPath;
|
||||||
|
|
||||||
|
_publicPath = appPath + "Media/" + settings.Name + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
string Map(string path) {
|
string Map(string path) {
|
||||||
return Path.Combine(_storagePath, path);
|
return string.IsNullOrEmpty(path) ? _storagePath : Path.Combine(_storagePath, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static string Fix(string path) {
|
static string Fix(string path) {
|
||||||
return Path.DirectorySeparatorChar != '/'
|
return string.IsNullOrEmpty(path)
|
||||||
? path.Replace('/', Path.DirectorySeparatorChar)
|
? ""
|
||||||
|
: Path.DirectorySeparatorChar != '/'
|
||||||
|
? path.Replace('/', Path.DirectorySeparatorChar)
|
||||||
: path;
|
: path;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Implementation of IStorageProvider
|
#region Implementation of IStorageProvider
|
||||||
|
|
||||||
|
public string GetPublicUrl(string path) {
|
||||||
|
|
||||||
|
return _publicPath + path.Replace(Path.DirectorySeparatorChar, '/');
|
||||||
|
}
|
||||||
|
|
||||||
public IStorageFile GetFile(string path) {
|
public IStorageFile GetFile(string path) {
|
||||||
if (!File.Exists(Map(path))) {
|
if (!File.Exists(Map(path))) {
|
||||||
throw new ArgumentException("File " + path + " does not exist");
|
throw new ArgumentException("File " + path + " does not exist");
|
||||||
@@ -105,9 +122,8 @@ namespace Orchard.Storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var fileInfo = new FileInfo(Map(path));
|
var fileInfo = new FileInfo(Map(path));
|
||||||
using (var stream = fileInfo.Create()) {
|
File.WriteAllBytes(Map(path), new byte[0]);
|
||||||
|
|
||||||
}
|
|
||||||
return new FileSystemStorageFile(Fix(path), fileInfo);
|
return new FileSystemStorageFile(Fix(path), fileInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Orchard.Storage {
|
namespace Orchard.Storage {
|
||||||
public interface IStorageProvider : IDependency {
|
public interface IStorageProvider : IDependency {
|
||||||
|
string GetPublicUrl(string path);
|
||||||
IStorageFile GetFile(string path);
|
IStorageFile GetFile(string path);
|
||||||
IEnumerable<IStorageFile> ListFiles(string path);
|
IEnumerable<IStorageFile> ListFiles(string path);
|
||||||
IEnumerable<IStorageFolder> ListFolders(string path);
|
IEnumerable<IStorageFolder> ListFolders(string path);
|
||||||
|
Reference in New Issue
Block a user