mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Refactoring the Media Library
- Removed dependency on Orchard.Taxonomies - Removed dependency on Orchard.Media You will need to remove the Orchard_MediaLibrary tables and also the Data Migration record corresponding to this module if you want to upgrade from 1.x. You can also apply the database changes by hand, remove all the records then use the Upgrade module to import all media. --HG-- branch : 1.x extra : rebase_source : 46100428d9546c3082bf65ce85d8d891543dc0a9
This commit is contained in:
parent
c0161b595d
commit
2889d29498
@ -44,7 +44,7 @@ namespace Orchard.Azure.FileSystems.Media {
|
||||
/// </summary>
|
||||
/// <param name="url">The public url of the media.</param>
|
||||
/// <returns>The local path.</returns>
|
||||
public string GetLocalPath(string url) {
|
||||
public string GetStoragePath(string url) {
|
||||
if (url.StartsWith(_absoluteRoot)) {
|
||||
return url.Substring(_absoluteRoot.Length);
|
||||
}
|
||||
|
@ -218,6 +218,10 @@ namespace Orchard.Tests.Modules.Media.Services {
|
||||
return FileSystemStorageProvider.GetPublicUrl(path);
|
||||
}
|
||||
|
||||
public string GetStoragePath(string url) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IStorageFile GetFile(string path) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.FileSystems.Media;
|
||||
using Orchard.ImageEditor.Models;
|
||||
using Orchard.MediaLibrary.Models;
|
||||
using Orchard.MediaLibrary.Services;
|
||||
using Orchard.Mvc;
|
||||
using Orchard.Themes;
|
||||
using Orchard.UI.Admin;
|
||||
@ -13,10 +13,10 @@ using Orchard.UI.Admin;
|
||||
namespace Orchard.ImageEditor.Controllers {
|
||||
[Admin]
|
||||
public class AdminController : Controller {
|
||||
private readonly IStorageProvider _storageProvider;
|
||||
private readonly IMediaLibraryService _mediaLibraryService;
|
||||
|
||||
public AdminController(IOrchardServices orchardServices, IStorageProvider storageProvider) {
|
||||
_storageProvider = storageProvider;
|
||||
public AdminController(IOrchardServices orchardServices, IMediaLibraryService mediaLibraryService) {
|
||||
_mediaLibraryService = mediaLibraryService;
|
||||
Services = orchardServices;
|
||||
}
|
||||
|
||||
@ -41,27 +41,8 @@ namespace Orchard.ImageEditor.Controllers {
|
||||
}
|
||||
|
||||
[Themed(false)]
|
||||
public ActionResult Touch(string src) {
|
||||
var localPath = _storageProvider.GetLocalPath(src);
|
||||
|
||||
if (_storageProvider.GetFile(localPath) == null) {
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
var media = Services.ContentManager.Query<MediaPart, MediaPartRecord>().Where(x => x.Resource == src).Slice(0, 1).FirstOrDefault();
|
||||
|
||||
return Json(media != null);
|
||||
}
|
||||
|
||||
[Themed(false)]
|
||||
public ActionResult Edit(string src) {
|
||||
var localPath = _storageProvider.GetLocalPath(src);
|
||||
|
||||
if (_storageProvider.GetFile(localPath) == null) {
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
var media = Services.ContentManager.Query<MediaPart, MediaPartRecord>().Where(x => x.Resource == src).Slice(0, 1).FirstOrDefault();
|
||||
public ActionResult Edit(string folderPath, string filename) {
|
||||
var media = Services.ContentManager.Query<MediaPart, MediaPartRecord>().Where(x => x.FolderPath == folderPath && x.FileName == filename).Slice(0, 1).FirstOrDefault();
|
||||
|
||||
if (media == null) {
|
||||
return HttpNotFound();
|
||||
@ -97,10 +78,11 @@ namespace Orchard.ImageEditor.Controllers {
|
||||
content = content.Substring(signature.Length);
|
||||
|
||||
var buffer = Convert.FromBase64String(content);
|
||||
var localPath = _storageProvider.GetLocalPath(media.Resource);
|
||||
_storageProvider.DeleteFile(localPath);
|
||||
|
||||
_mediaLibraryService.DeleteFile(media.FolderPath, media.FileName);
|
||||
|
||||
using (var stream = new MemoryStream(buffer)) {
|
||||
_storageProvider.SaveStream(localPath, stream);
|
||||
_mediaLibraryService.UploadMediaFile(media.FolderPath, media.FileName, stream);
|
||||
}
|
||||
|
||||
image.Width = width;
|
||||
|
@ -19,7 +19,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
<input type="hidden" id="image-editor-url" value="@Url.Content(mediaPart.Resource)"/>
|
||||
<input type="hidden" id="image-editor-url" value="@Url.Content(mediaPart.MediaPath)"/>
|
||||
<input type="hidden" id="image-editor-callback" value="@Model.CallBack"/>
|
||||
|
||||
<div id="image-editor">
|
||||
@ -41,7 +41,7 @@
|
||||
<div id="image-editor-container" class="editor-shadow">
|
||||
<div id="image-editor-image-wrapper" >
|
||||
@*<canvas id="image-editor-image" class="canvas-shadow"></canvas>*@
|
||||
<img id="image-editor-image" class="canvas-shadow" src="@Url.Content(mediaPart.Resource)">
|
||||
<img id="image-editor-image" class="canvas-shadow" src="@Url.Content(mediaPart.MediaUrl)">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
ImagePart imagePart = Model.ContentPart;
|
||||
|
||||
// do not show the editor if the image is not local
|
||||
if (!imagePart.As<MediaPart>().Resource.StartsWith("~/")) {
|
||||
if (String.IsNullOrEmpty(imagePart.As<MediaPart>().MediaPath)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +73,14 @@ namespace Orchard.Media.Services {
|
||||
/// <param name="newFileName">The new file name.</param>
|
||||
void RenameFile(string folderPath, string currentFileName, string newFileName);
|
||||
|
||||
/// <summary>
|
||||
/// Moves a media file.
|
||||
/// </summary>
|
||||
/// <param name="fileName">The file name.</param>
|
||||
/// <param name="currentPath">The path to the file's parent folder.</param>
|
||||
/// <param name="newPath">The path where the file will be moved to.</param>
|
||||
void MoveFile(string fileName, string currentPath, string newPath);
|
||||
|
||||
/// <summary>
|
||||
/// Uploads a media file based on a posted file.
|
||||
/// </summary>
|
||||
|
@ -160,6 +160,20 @@ namespace Orchard.Media.Services {
|
||||
_storageProvider.RenameFile(_storageProvider.Combine(folderPath, currentFileName), _storageProvider.Combine(folderPath, newFileName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves a media file.
|
||||
/// </summary>
|
||||
/// <param name="fileName">The file name.</param>
|
||||
/// <param name="currentPath">The path to the file's parent folder.</param>
|
||||
/// <param name="newPath">The path where the file will be moved to.</param>
|
||||
public void MoveFile(string fileName, string currentPath, string newPath) {
|
||||
Argument.ThrowIfNullOrEmpty(currentPath, "currentPath");
|
||||
Argument.ThrowIfNullOrEmpty(newPath, "newPath");
|
||||
Argument.ThrowIfNullOrEmpty(fileName, "fileName");
|
||||
|
||||
_storageProvider.RenameFile(_storageProvider.Combine(currentPath, fileName), _storageProvider.Combine(newPath, fileName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uploads a media file based on a posted file.
|
||||
/// </summary>
|
||||
|
@ -12,7 +12,7 @@ namespace Orchard.MediaLibrary {
|
||||
public string MenuName { get { return "admin"; } }
|
||||
|
||||
public void GetNavigation(NavigationBuilder builder) {
|
||||
builder.AddImageSet("media")
|
||||
builder.AddImageSet("media-library")
|
||||
.Add(T("Media"), "6",
|
||||
menu => menu.Add(T("Media"), "0", item => item.Action("Index", "Admin", new { area = "Orchard.MediaLibrary", id = (int?)null })
|
||||
.Permission(Permissions.ManageMediaContent)));
|
||||
|
@ -10,9 +10,9 @@ using Orchard.MediaLibrary.ViewModels;
|
||||
using Orchard.Mvc;
|
||||
using Orchard.Themes;
|
||||
using Orchard.UI.Navigation;
|
||||
using Orchard.Utility.Extensions;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Validation;
|
||||
|
||||
namespace Orchard.MediaLibrary.Controllers {
|
||||
[ValidateInput(false)]
|
||||
@ -39,46 +39,42 @@ namespace Orchard.MediaLibrary.Controllers {
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public ActionResult Index(int? id, bool dialog = false) {
|
||||
string stereotype;
|
||||
public ActionResult Index(string folderPath = "", bool dialog = false) {
|
||||
var mediaTypes = new List<string>();
|
||||
|
||||
foreach(var contentTypeDefinition in _contentDefinitionManager.ListTypeDefinitions()) {
|
||||
string stereotype;
|
||||
if (contentTypeDefinition.Settings.TryGetValue("Stereotype", out stereotype) && stereotype == "Media")
|
||||
mediaTypes.Add(contentTypeDefinition.Name);
|
||||
}
|
||||
|
||||
var viewModel = new MediaManagerIndexViewModel {
|
||||
DialogMode = dialog,
|
||||
Folders = _mediaLibraryService.GetMediaFolders(),
|
||||
Folder = id,
|
||||
Hierarchy = id.HasValue ? _mediaLibraryService.GetMediaFolderHierarchy(id.Value) : Enumerable.Empty<MediaFolder>(),
|
||||
Folders = _mediaLibraryService.GetMediaFolders(null).Select(GetFolderHierarchy),
|
||||
FolderPath = folderPath,
|
||||
MediaTypes = mediaTypes.ToArray()
|
||||
};
|
||||
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
public ActionResult Import(int id) {
|
||||
public ActionResult Import(string folderPath) {
|
||||
var mediaProviderMenu = _navigationManager.BuildMenu("mediaproviders");
|
||||
var imageSets = _navigationManager.BuildImageSets("mediaproviders");
|
||||
|
||||
var hierarchy = _mediaLibraryService.GetMediaFolderHierarchy(id);
|
||||
|
||||
|
||||
var viewModel = new MediaManagerImportViewModel {
|
||||
Menu = mediaProviderMenu,
|
||||
Hierarchy = hierarchy.ToReadOnlyCollection(),
|
||||
ImageSets = imageSets,
|
||||
FolderPath = folderPath
|
||||
};
|
||||
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[Themed(false)]
|
||||
public ActionResult MediaItems(int id, int skip = 0, int count = 0, string order = "created", string mediaType = "") {
|
||||
var mediaParts = _mediaLibraryService.GetMediaContentItems(id, skip, count, order, mediaType);
|
||||
var mediaPartsCount = _mediaLibraryService.GetMediaContentItemsCount(id, mediaType);
|
||||
public ActionResult MediaItems(string folderPath, int skip = 0, int count = 0, string order = "created", string mediaType = "") {
|
||||
var mediaParts = _mediaLibraryService.GetMediaContentItems(folderPath, skip, count, order, mediaType);
|
||||
var mediaPartsCount = _mediaLibraryService.GetMediaContentItemsCount(folderPath, mediaType);
|
||||
|
||||
var mediaItems = mediaParts.Select(x => new MediaManagerMediaItemViewModel {
|
||||
MediaPart = x,
|
||||
@ -145,5 +141,10 @@ namespace Orchard.MediaLibrary.Controllers {
|
||||
return Json(false);
|
||||
}
|
||||
}
|
||||
|
||||
private FolderHierarchy GetFolderHierarchy(MediaFolder root) {
|
||||
Argument.ThrowIfNull(root, "root");
|
||||
return new FolderHierarchy(root) {Children = _mediaLibraryService.GetMediaFolders(root.MediaPath).Select(GetFolderHierarchy)};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.MediaLibrary.Services;
|
||||
@ -15,13 +14,13 @@ namespace Orchard.MediaLibrary.Controllers {
|
||||
_mediaLibraryService = mediaManagerService;
|
||||
}
|
||||
|
||||
public ActionResult Index(int id) {
|
||||
public ActionResult Index(string folderPath) {
|
||||
|
||||
return View(id);
|
||||
return View((object)folderPath);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Upload(int id) {
|
||||
public ActionResult Upload(string folderPath) {
|
||||
var statuses = new List<object>();
|
||||
|
||||
// Loop through each file in the request
|
||||
@ -34,8 +33,8 @@ namespace Orchard.MediaLibrary.Controllers {
|
||||
if (filename == "blob") {
|
||||
filename = "clipboard.png";
|
||||
}
|
||||
|
||||
var mediaPart = _mediaLibraryService.ImportStream(id, file.InputStream, filename);
|
||||
|
||||
var mediaPart = _mediaLibraryService.ImportMedia(file.InputStream, folderPath, filename);
|
||||
|
||||
statuses.Add(new {
|
||||
id = mediaPart.Id,
|
||||
@ -43,7 +42,7 @@ namespace Orchard.MediaLibrary.Controllers {
|
||||
type = mediaPart.MimeType,
|
||||
size = file.ContentLength,
|
||||
progress = 1.0,
|
||||
url= mediaPart.Resource,
|
||||
url= mediaPart.FileName,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,10 @@ namespace Orchard.MediaLibrary.Controllers {
|
||||
public class FolderController : Controller {
|
||||
private readonly IMediaLibraryService _mediaLibraryService;
|
||||
|
||||
public FolderController(IOrchardServices services, IMediaLibraryService mediaManagerService) {
|
||||
public FolderController(
|
||||
IOrchardServices services,
|
||||
IMediaLibraryService mediaManagerService
|
||||
) {
|
||||
_mediaLibraryService = mediaManagerService;
|
||||
|
||||
Services = services;
|
||||
@ -27,13 +30,13 @@ namespace Orchard.MediaLibrary.Controllers {
|
||||
public ILogger Logger { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ActionResult Create(int? id) {
|
||||
public ActionResult Create(string folderPath) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent, T("Couldn't create media folder")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var viewModel = new MediaManagerFolderCreateViewModel {
|
||||
Hierarchy = id.HasValue ? _mediaLibraryService.GetMediaFolderHierarchy(id.Value) : Enumerable.Empty<MediaFolder>(),
|
||||
ParentFolderId = id
|
||||
Hierarchy = _mediaLibraryService.GetMediaFolders(folderPath),
|
||||
FolderPath = folderPath
|
||||
};
|
||||
|
||||
return View(viewModel);
|
||||
@ -48,7 +51,7 @@ namespace Orchard.MediaLibrary.Controllers {
|
||||
UpdateModel(viewModel);
|
||||
|
||||
try {
|
||||
_mediaLibraryService.CreateFolder(viewModel.ParentFolderId, viewModel.Name);
|
||||
_mediaLibraryService.CreateFolder(viewModel.FolderPath, viewModel.Name);
|
||||
Services.Notifier.Information(T("Media folder created"));
|
||||
}
|
||||
catch (ArgumentException argumentException) {
|
||||
@ -61,16 +64,14 @@ namespace Orchard.MediaLibrary.Controllers {
|
||||
|
||||
}
|
||||
|
||||
public ActionResult Edit(int id) {
|
||||
public ActionResult Edit(string folderPath) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent, T("Couldn't edit media folder")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var folder = _mediaLibraryService.GetMediaFolder(id);
|
||||
|
||||
|
||||
var viewModel = new MediaManagerFolderEditViewModel {
|
||||
Hierarchy = _mediaLibraryService.GetMediaFolderHierarchy(id),
|
||||
FolderId = id,
|
||||
Name = folder.Name
|
||||
Hierarchy = _mediaLibraryService.GetMediaFolders(folderPath),
|
||||
FolderPath = folderPath,
|
||||
Name = folderPath.Split('/').LastOrDefault()
|
||||
};
|
||||
|
||||
return View(viewModel);
|
||||
@ -86,7 +87,7 @@ namespace Orchard.MediaLibrary.Controllers {
|
||||
UpdateModel(viewModel);
|
||||
|
||||
try {
|
||||
_mediaLibraryService.RenameFolder(viewModel.FolderId, viewModel.Name);
|
||||
_mediaLibraryService.RenameFolder(viewModel.FolderPath, viewModel.Name);
|
||||
Services.Notifier.Information(T("Media folder renamed"));
|
||||
}
|
||||
catch (ArgumentException argumentException) {
|
||||
@ -108,7 +109,7 @@ namespace Orchard.MediaLibrary.Controllers {
|
||||
UpdateModel(viewModel);
|
||||
|
||||
try {
|
||||
_mediaLibraryService.DeleteFolder(viewModel.FolderId);
|
||||
_mediaLibraryService.DeleteFolder(viewModel.FolderPath);
|
||||
Services.Notifier.Information(T("Media folder deleted"));
|
||||
}
|
||||
catch (ArgumentException argumentException) {
|
||||
@ -121,22 +122,17 @@ namespace Orchard.MediaLibrary.Controllers {
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Move(int targetId, int[] mediaItemIds) {
|
||||
public ActionResult Move(string folderPath, int[] mediaItemIds) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent, T("Couldn't move media items")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var targetFolder = _mediaLibraryService.GetMediaFolder(targetId);
|
||||
|
||||
if (targetFolder == null) {
|
||||
return Json(false);
|
||||
foreach (var media in Services.ContentManager.Query().ForPart<MediaPart>().ForContentItems(mediaItemIds).List()) {
|
||||
var uniqueFilename = _mediaLibraryService.GetUniqueFilename(folderPath, media.FileName);
|
||||
_mediaLibraryService.MoveFile(media.FolderPath, media.FileName, folderPath, uniqueFilename);
|
||||
media.FolderPath = folderPath;
|
||||
media.FileName = uniqueFilename;
|
||||
}
|
||||
|
||||
if (mediaItemIds == null || mediaItemIds.Length == 0) {
|
||||
return Json(false);
|
||||
}
|
||||
|
||||
_mediaLibraryService.MoveMedia(targetId, mediaItemIds);
|
||||
|
||||
return Json(true);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ using System.Xml.Linq;
|
||||
using Orchard.MediaLibrary.Models;
|
||||
using Orchard.MediaLibrary.Services;
|
||||
using Orchard.MediaLibrary.ViewModels;
|
||||
using Orchard.Taxonomies.Services;
|
||||
using Orchard.Themes;
|
||||
using Orchard.UI.Admin;
|
||||
using Orchard.ContentManagement;
|
||||
@ -14,30 +13,30 @@ using Orchard.ContentManagement;
|
||||
namespace Orchard.MediaLibrary.Controllers {
|
||||
[Admin, Themed(false)]
|
||||
public class OEmbedController : Controller {
|
||||
private readonly ITaxonomyService _taxonomyService;
|
||||
private readonly IMediaLibraryService _mediaLibraryService;
|
||||
|
||||
public OEmbedController(
|
||||
ITaxonomyService taxonomyService,
|
||||
IMediaLibraryService mediaManagerService,
|
||||
IOrchardServices services) {
|
||||
_taxonomyService = taxonomyService;
|
||||
_mediaLibraryService = mediaManagerService;
|
||||
Services = services;
|
||||
}
|
||||
|
||||
public IOrchardServices Services { get; set; }
|
||||
|
||||
public ActionResult Index(int id) {
|
||||
var viewModel = new OEmbedViewModel();
|
||||
public ActionResult Index(string folderPath) {
|
||||
var viewModel = new OEmbedViewModel {
|
||||
FolderPath = folderPath
|
||||
};
|
||||
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Index(int id, string url) {
|
||||
public ActionResult Index(string folderPath, string url) {
|
||||
var viewModel = new OEmbedViewModel {
|
||||
Url = url,
|
||||
Id = id
|
||||
FolderPath = folderPath
|
||||
};
|
||||
|
||||
try {
|
||||
@ -72,20 +71,13 @@ namespace Orchard.MediaLibrary.Controllers {
|
||||
}
|
||||
|
||||
[HttpPost, ValidateInput(false)]
|
||||
public ActionResult MediaPost(int id, string url, string document) {
|
||||
var termPart = _taxonomyService.GetTerm(id);
|
||||
|
||||
if (termPart == null) {
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
public ActionResult MediaPost(string folderPath, string url, string document) {
|
||||
var content = XDocument.Parse(document);
|
||||
var oembed = content.Root;
|
||||
|
||||
var part = Services.ContentManager.New<MediaPart>("OEmbed");
|
||||
part.TermPart = _taxonomyService.GetTerm(id);
|
||||
|
||||
part.Resource = url;
|
||||
part.FileName = url;
|
||||
part.MimeType = "text/html";
|
||||
part.Title = oembed.Element("title").Value;
|
||||
if (oembed.Element("description") != null) {
|
||||
@ -101,7 +93,7 @@ namespace Orchard.MediaLibrary.Controllers {
|
||||
Services.ContentManager.Create(oembedPart);
|
||||
|
||||
var viewModel = new OEmbedViewModel {
|
||||
Id = id
|
||||
FolderPath = folderPath
|
||||
};
|
||||
|
||||
return View("Index", viewModel);
|
||||
|
@ -1,9 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.MediaLibrary.Services;
|
||||
using Orchard.Themes;
|
||||
@ -18,22 +15,22 @@ namespace Orchard.MediaLibrary.Controllers {
|
||||
_mediaLibraryService = mediaManagerService;
|
||||
}
|
||||
|
||||
public ActionResult Index(int id) {
|
||||
public ActionResult Index(string folderPath) {
|
||||
|
||||
return View(id);
|
||||
return View((object)folderPath);
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public JsonResult ImagePost(int id, string url) {
|
||||
public JsonResult ImagePost(string folderPath, string url) {
|
||||
|
||||
try {
|
||||
var buffer = new WebClient().DownloadData(url);
|
||||
var stream = new MemoryStream(buffer);
|
||||
var mediaPart = _mediaLibraryService.ImportStream(id, stream, Path.GetFileName(url));
|
||||
var mediaPart = _mediaLibraryService.ImportMedia(stream, folderPath, Path.GetFileName(url));
|
||||
|
||||
return new JsonResult {
|
||||
Data = new {id, mediaPart.Resource}
|
||||
Data = new {folderPath, MediaPath = mediaPart.FileName}
|
||||
};
|
||||
}
|
||||
catch(Exception e) {
|
||||
|
@ -1,17 +1,14 @@
|
||||
using System.IO;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.FileSystems.Media;
|
||||
using Orchard.MediaLibrary.Models;
|
||||
|
||||
namespace Orchard.MediaLibrary.Factories {
|
||||
|
||||
public class AudioFactorySelector : IMediaFactorySelector {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IStorageProvider _storageProvider;
|
||||
|
||||
public AudioFactorySelector(IContentManager contentManager, IStorageProvider storageProvider) {
|
||||
public AudioFactorySelector(IContentManager contentManager) {
|
||||
_contentManager = contentManager;
|
||||
_storageProvider = storageProvider;
|
||||
}
|
||||
|
||||
public MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType) {
|
||||
@ -21,7 +18,7 @@ namespace Orchard.MediaLibrary.Factories {
|
||||
|
||||
return new MediaFactorySelectorResult {
|
||||
Priority = -5,
|
||||
MediaFactory = new AudioFactory(_contentManager, _storageProvider)
|
||||
MediaFactory = new AudioFactory(_contentManager)
|
||||
};
|
||||
|
||||
}
|
||||
@ -29,31 +26,16 @@ namespace Orchard.MediaLibrary.Factories {
|
||||
|
||||
public class AudioFactory : IMediaFactory {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IStorageProvider _storageProvider;
|
||||
|
||||
public const string BaseFolder = "Audio";
|
||||
|
||||
public AudioFactory(IContentManager contentManager, IStorageProvider storageProvider) {
|
||||
public AudioFactory(IContentManager contentManager) {
|
||||
_contentManager = contentManager;
|
||||
_storageProvider = storageProvider;
|
||||
}
|
||||
|
||||
public MediaPart CreateMedia(Stream stream, string path, string mimeType) {
|
||||
var uniquePath = path;
|
||||
var index = 1;
|
||||
while (_storageProvider.FileExists(_storageProvider.Combine(BaseFolder, uniquePath))) {
|
||||
uniquePath = Path.GetFileNameWithoutExtension(path) + "-" + index++ + Path.GetExtension(path);
|
||||
}
|
||||
|
||||
_storageProvider.SaveStream(_storageProvider.Combine(BaseFolder, uniquePath), stream);
|
||||
|
||||
var part = _contentManager.New<MediaPart>("Audio");
|
||||
|
||||
if (!_storageProvider.FolderExists(BaseFolder)) {
|
||||
_storageProvider.CreateFolder(BaseFolder);
|
||||
}
|
||||
|
||||
part.Resource = _storageProvider.GetPublicUrl(_storageProvider.Combine(BaseFolder, uniquePath));
|
||||
part.MimeType = mimeType;
|
||||
part.Title = Path.GetFileNameWithoutExtension(path);
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System.IO;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.FileSystems.Media;
|
||||
using Orchard.MediaLibrary.Models;
|
||||
|
||||
namespace Orchard.MediaLibrary.Factories {
|
||||
@ -11,48 +10,30 @@ namespace Orchard.MediaLibrary.Factories {
|
||||
/// </summary>
|
||||
public class DocumentFactorySelector : IMediaFactorySelector {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IStorageProvider _storageProvider;
|
||||
|
||||
public DocumentFactorySelector(IContentManager contentManager, IStorageProvider storageProvider) {
|
||||
public DocumentFactorySelector(IContentManager contentManager) {
|
||||
_contentManager = contentManager;
|
||||
_storageProvider = storageProvider;
|
||||
}
|
||||
|
||||
public MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType) {
|
||||
return new MediaFactorySelectorResult {
|
||||
Priority = -10,
|
||||
MediaFactory = new DocumentFactory(_contentManager, _storageProvider)
|
||||
MediaFactory = new DocumentFactory(_contentManager)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class DocumentFactory : IMediaFactory {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IStorageProvider _storageProvider;
|
||||
|
||||
public const string BaseFolder = "Documents";
|
||||
|
||||
public DocumentFactory(IContentManager contentManager, IStorageProvider storageProvider) {
|
||||
public DocumentFactory(IContentManager contentManager) {
|
||||
_contentManager = contentManager;
|
||||
_storageProvider = storageProvider;
|
||||
}
|
||||
|
||||
public MediaPart CreateMedia(Stream stream, string path, string mimeType) {
|
||||
var uniquePath = path;
|
||||
var index = 1;
|
||||
while (_storageProvider.FileExists(_storageProvider.Combine(BaseFolder, uniquePath))) {
|
||||
uniquePath = Path.GetFileNameWithoutExtension(path) + "-" + index++ + Path.GetExtension(path);
|
||||
}
|
||||
|
||||
_storageProvider.SaveStream(_storageProvider.Combine(BaseFolder, uniquePath), stream);
|
||||
|
||||
var part = _contentManager.New<MediaPart>("Document");
|
||||
|
||||
if (!_storageProvider.FolderExists(BaseFolder)) {
|
||||
_storageProvider.CreateFolder(BaseFolder);
|
||||
}
|
||||
|
||||
part.Resource = _storageProvider.GetPublicUrl(_storageProvider.Combine(BaseFolder, uniquePath));
|
||||
part.MimeType = mimeType;
|
||||
part.Title = Path.GetFileNameWithoutExtension(path);
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System.IO;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.MediaLibrary.Models;
|
||||
|
||||
namespace Orchard.MediaLibrary.Factories {
|
||||
|
@ -1,18 +1,15 @@
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.FileSystems.Media;
|
||||
using Orchard.MediaLibrary.Models;
|
||||
|
||||
namespace Orchard.MediaLibrary.Factories {
|
||||
|
||||
public class ImageFactorySelector : IMediaFactorySelector {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IStorageProvider _storageProvider;
|
||||
|
||||
public ImageFactorySelector(IContentManager contentManager, IStorageProvider storageProvider) {
|
||||
public ImageFactorySelector(IContentManager contentManager) {
|
||||
_contentManager = contentManager;
|
||||
_storageProvider = storageProvider;
|
||||
}
|
||||
|
||||
public MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType) {
|
||||
@ -22,7 +19,7 @@ namespace Orchard.MediaLibrary.Factories {
|
||||
|
||||
return new MediaFactorySelectorResult {
|
||||
Priority = -5,
|
||||
MediaFactory = new ImageFactory(_contentManager, _storageProvider)
|
||||
MediaFactory = new ImageFactory(_contentManager)
|
||||
};
|
||||
|
||||
}
|
||||
@ -30,31 +27,15 @@ namespace Orchard.MediaLibrary.Factories {
|
||||
|
||||
public class ImageFactory : IMediaFactory {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IStorageProvider _storageProvider;
|
||||
|
||||
public const string BaseFolder = "Images";
|
||||
|
||||
public ImageFactory(IContentManager contentManager, IStorageProvider storageProvider) {
|
||||
public ImageFactory(IContentManager contentManager) {
|
||||
_contentManager = contentManager;
|
||||
_storageProvider = storageProvider;
|
||||
}
|
||||
|
||||
public MediaPart CreateMedia(Stream stream, string path, string mimeType) {
|
||||
var uniquePath = path;
|
||||
var index = 1;
|
||||
while (_storageProvider.FileExists(_storageProvider.Combine(BaseFolder, uniquePath))) {
|
||||
uniquePath = Path.GetFileNameWithoutExtension(path) + "-" + index++ + Path.GetExtension(path);
|
||||
}
|
||||
|
||||
_storageProvider.SaveStream(_storageProvider.Combine(BaseFolder, uniquePath), stream);
|
||||
|
||||
var part = _contentManager.New<MediaPart>("Image");
|
||||
|
||||
if (!_storageProvider.FolderExists(BaseFolder)) {
|
||||
_storageProvider.CreateFolder(BaseFolder);
|
||||
}
|
||||
|
||||
part.Resource = _storageProvider.GetRelativePath(_storageProvider.Combine(BaseFolder, uniquePath));
|
||||
part.MimeType = mimeType;
|
||||
part.Title = Path.GetFileNameWithoutExtension(path);
|
||||
|
||||
|
@ -1,18 +1,14 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.FileSystems.Media;
|
||||
using Orchard.MediaLibrary.Models;
|
||||
|
||||
namespace Orchard.MediaLibrary.Factories {
|
||||
|
||||
public class VideoFactorySelector : IMediaFactorySelector {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IStorageProvider _storageProvider;
|
||||
|
||||
public VideoFactorySelector(IContentManager contentManager, IStorageProvider storageProvider) {
|
||||
public VideoFactorySelector(IContentManager contentManager) {
|
||||
_contentManager = contentManager;
|
||||
_storageProvider = storageProvider;
|
||||
}
|
||||
|
||||
public MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType) {
|
||||
@ -22,7 +18,7 @@ namespace Orchard.MediaLibrary.Factories {
|
||||
|
||||
return new MediaFactorySelectorResult {
|
||||
Priority = -5,
|
||||
MediaFactory = new VideoFactory(_contentManager, _storageProvider)
|
||||
MediaFactory = new VideoFactory(_contentManager)
|
||||
};
|
||||
|
||||
}
|
||||
@ -30,31 +26,14 @@ namespace Orchard.MediaLibrary.Factories {
|
||||
|
||||
public class VideoFactory : IMediaFactory {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IStorageProvider _storageProvider;
|
||||
|
||||
public const string BaseFolder = "Videos";
|
||||
|
||||
public VideoFactory(IContentManager contentManager, IStorageProvider storageProvider) {
|
||||
public VideoFactory(IContentManager contentManager) {
|
||||
_contentManager = contentManager;
|
||||
_storageProvider = storageProvider;
|
||||
}
|
||||
|
||||
public MediaPart CreateMedia(Stream stream, string path, string mimeType) {
|
||||
var uniquePath = path;
|
||||
var index = 1;
|
||||
while (_storageProvider.FileExists(_storageProvider.Combine(BaseFolder, uniquePath))) {
|
||||
uniquePath = Path.GetFileNameWithoutExtension(path) + "-" + index++ + Path.GetExtension(path);
|
||||
}
|
||||
|
||||
_storageProvider.SaveStream(_storageProvider.Combine(BaseFolder, uniquePath), stream);
|
||||
|
||||
var part = _contentManager.New<MediaPart>("Video");
|
||||
|
||||
if (!_storageProvider.FolderExists(BaseFolder)) {
|
||||
_storageProvider.CreateFolder(BaseFolder);
|
||||
}
|
||||
|
||||
part.Resource = _storageProvider.GetPublicUrl(_storageProvider.Combine(BaseFolder, uniquePath));
|
||||
part.MimeType = mimeType;
|
||||
part.Title = Path.GetFileNameWithoutExtension(path);
|
||||
|
||||
|
@ -1,37 +1,34 @@
|
||||
using Orchard.ContentManagement;
|
||||
using System;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Data;
|
||||
using Orchard.FileSystems.Media;
|
||||
using Orchard.MediaLibrary.Services;
|
||||
using Orchard.MediaLibrary.Models;
|
||||
using Orchard.Taxonomies.Models;
|
||||
|
||||
namespace Orchard.MediaLibrary.Handlers {
|
||||
public class MediaPartHandler : ContentHandler {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IMediaLibraryService _mediaLibraryService;
|
||||
private readonly IStorageProvider _storageProvider;
|
||||
|
||||
public MediaPartHandler(
|
||||
IContentManager contentManager,
|
||||
IMediaLibraryService mediaLibraryService,
|
||||
IRepository<MediaPartRecord> repository,
|
||||
IStorageProvider storageProvider) {
|
||||
|
||||
_contentManager = contentManager;
|
||||
_mediaLibraryService = mediaLibraryService;
|
||||
_storageProvider = storageProvider;
|
||||
|
||||
Filters.Add(StorageFilter.For(repository));
|
||||
OnLoading<MediaPart>((context, part) => LazyLoadHandlers(part));
|
||||
OnVersioning<MediaPart>((context, part, newVersionPart) => LazyLoadHandlers(newVersionPart));
|
||||
OnRemoving<MediaPart>((context, part) => RemoveMedia(part));
|
||||
}
|
||||
|
||||
protected void LazyLoadHandlers(MediaPart part) {
|
||||
// add handlers that will load content for id's just-in-time
|
||||
part.TermPartField.Loader(() => part.Record.TermPartRecord == null ? null : _contentManager.Get<TermPart>(part.Record.TermPartRecord.Id));
|
||||
OnLoading<MediaPart>((context, part) => {
|
||||
if (!String.IsNullOrEmpty(part.FileName)) {
|
||||
part._publicUrl.Loader(x => _mediaLibraryService.GetMediaPublicUrl(part.FolderPath, part.FileName));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void RemoveMedia(MediaPart part) {
|
||||
if (part.Resource.StartsWith("~/")) {
|
||||
var path = _storageProvider.GetLocalPath(part.Resource);
|
||||
if (!string.IsNullOrEmpty(part.FileName)) {
|
||||
var path = _storageProvider.Combine(part.FolderPath, part.FileName);
|
||||
_storageProvider.DeleteFile(path);
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,8 @@
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.Data.Migration;
|
||||
using Orchard.MediaLibrary.Services;
|
||||
using Orchard.Taxonomies.Models;
|
||||
|
||||
namespace Orchard.MediaLibrary {
|
||||
public class MediaDataMigration : DataMigrationImpl {
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public MediaDataMigration(IContentManager contentManager) {
|
||||
_contentManager = contentManager;
|
||||
}
|
||||
|
||||
public int Create() {
|
||||
|
||||
@ -19,26 +11,10 @@ namespace Orchard.MediaLibrary {
|
||||
.Column<string>("MimeType")
|
||||
.Column<string>("Caption", c => c.Unlimited())
|
||||
.Column<string>("AlternateText", c => c.Unlimited())
|
||||
.Column<int>("TermPartRecord_id")
|
||||
.Column<string>("Resource", c => c.WithLength(2048))
|
||||
.Column<string>("FolderPath", c => c.WithLength(2048))
|
||||
.Column<string>("FileName", c => c.WithLength(2048))
|
||||
);
|
||||
|
||||
// create the "Media Location" taxonomy
|
||||
var taxonomy = _contentManager.New<TaxonomyPart>("Taxonomy");
|
||||
taxonomy.IsInternal = true;
|
||||
taxonomy.Name = MediaLibraryService.MediaLocation;
|
||||
|
||||
_contentManager.Create(taxonomy);
|
||||
|
||||
// create the "Media" term
|
||||
var term = _contentManager.New<TermPart>(taxonomy.TermTypeName);
|
||||
term.TaxonomyId = taxonomy.Id;
|
||||
term.Container = taxonomy;
|
||||
term.Name = "Media";
|
||||
term.Path = "/";
|
||||
|
||||
_contentManager.Create(term, VersionOptions.Published);
|
||||
|
||||
ContentDefinitionManager.AlterTypeDefinition("Image", td => td
|
||||
.DisplayedAs("Image")
|
||||
.WithSetting("Stereotype", "Media")
|
||||
|
@ -0,0 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Orchard.MediaLibrary.Models {
|
||||
public class FolderHierarchy {
|
||||
public FolderHierarchy(MediaFolder root) {
|
||||
Root = root;
|
||||
Children = new List<FolderHierarchy>();
|
||||
}
|
||||
|
||||
public MediaFolder Root { get; set; }
|
||||
public IEnumerable<FolderHierarchy> Children { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace Orchard.MediaLibrary.Models {
|
||||
public class MediaFile {
|
||||
public string Name { get; set; }
|
||||
public string User { get; set; }
|
||||
public string Type { get; set; }
|
||||
public long Size { get; set; }
|
||||
public string FolderName { get; set; }
|
||||
public DateTime LastUpdated { get; set; }
|
||||
public string MediaPath { get; set; }
|
||||
}
|
||||
}
|
@ -1,17 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
|
||||
namespace Orchard.MediaLibrary.Models {
|
||||
public class MediaFolder {
|
||||
public MediaFolder() {
|
||||
Folders = new List<MediaFolder>();
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public string MediaPath { get; set; }
|
||||
public int TermId { get; set; }
|
||||
public int? ParentTermId { get; set; }
|
||||
|
||||
public IList<MediaFolder> Folders { get; set; }
|
||||
public string User { get; set; }
|
||||
public long Size { get; set; }
|
||||
public DateTime LastUpdated { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +1,67 @@
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Common.Utilities;
|
||||
using Orchard.ContentManagement.Utilities;
|
||||
using Orchard.Core.Title.Models;
|
||||
using Orchard.Taxonomies.Models;
|
||||
|
||||
namespace Orchard.MediaLibrary.Models {
|
||||
public class MediaPart : ContentPart<MediaPartRecord> {
|
||||
|
||||
private readonly LazyField<TermPart> _termPartField = new LazyField<TermPart>();
|
||||
|
||||
public LazyField<TermPart> TermPartField { get { return _termPartField; } }
|
||||
internal LazyField<string> _publicUrl = new LazyField<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the media.
|
||||
/// </summary>
|
||||
public string Title {
|
||||
get { return ContentItem.As<TitlePart>().Title; }
|
||||
set { ContentItem.As<TitlePart>().Title = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the mime type of the media.
|
||||
/// </summary>
|
||||
public string MimeType {
|
||||
get { return Record.MimeType; }
|
||||
set { Record.MimeType = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the caption of the media.
|
||||
/// </summary>
|
||||
public string Caption {
|
||||
get { return Record.Caption; }
|
||||
set { Record.Caption = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the alternate text of the media.
|
||||
/// </summary>
|
||||
public string AlternateText {
|
||||
get { return Record.AlternateText; }
|
||||
set { Record.AlternateText = value; }
|
||||
}
|
||||
|
||||
public TermPart TermPart {
|
||||
get { return _termPartField.Value; }
|
||||
set { Record.TermPartRecord = value.Record; }
|
||||
/// <summary>
|
||||
/// Gets or sets the hierarchical location of the media.
|
||||
/// </summary>
|
||||
public string FolderPath {
|
||||
get { return Record.FolderPath; }
|
||||
set { Record.FolderPath = value; }
|
||||
}
|
||||
|
||||
public string Resource {
|
||||
get { return Record.Resource; }
|
||||
set { Record.Resource = value; }
|
||||
/// <summary>
|
||||
/// Gets or set the name of the media when <see cref="IMediaService"/> is used
|
||||
/// to store the physical media. If <value>null</value> then the media is not associated
|
||||
/// with a local file.
|
||||
/// </summary>
|
||||
public string FileName {
|
||||
get { return Record.FileName; }
|
||||
set { Record.FileName = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the public Url of the media if stored locally.
|
||||
/// </summary>
|
||||
public string MediaUrl {
|
||||
get { return _publicUrl.Value; }
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,12 @@
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Taxonomies.Models;
|
||||
|
||||
namespace Orchard.MediaLibrary.Models {
|
||||
public class MediaPartRecord : ContentPartRecord {
|
||||
public virtual string MimeType { get; set; }
|
||||
public virtual string Caption { get; set; }
|
||||
public virtual string AlternateText { get; set; }
|
||||
public virtual TermPartRecord TermPartRecord { get; set; }
|
||||
public virtual string Resource { get; set; }
|
||||
public virtual string FolderPath { get; set; }
|
||||
public virtual string FileName { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -9,5 +9,5 @@ Features:
|
||||
Orchard.MediaLibrary:
|
||||
Name: Media Library
|
||||
Description: Provides enhanced Media management tools.
|
||||
Dependencies: Orchard.Taxonomies, Orchard.MediaProcessing, Title
|
||||
Dependencies: Title, Orchard.MediaProcessing
|
||||
Category: Media
|
@ -72,6 +72,8 @@
|
||||
<Content Include="Scripts\modal-window.js" />
|
||||
<Content Include="Scripts\history.js" />
|
||||
<Content Include="Scripts\knockout-2.2.1.js" />
|
||||
<Content Include="Styles\Images\menu.media.png" />
|
||||
<Content Include="Styles\menu.media-library-admin.css" />
|
||||
<Content Include="Styles\menu.oembed-mediaproviders.css" />
|
||||
<Content Include="Styles\orchard-oembed-admin.css" />
|
||||
<Content Include="Styles\menu.websearch-mediaproviders.css" />
|
||||
@ -104,14 +106,6 @@
|
||||
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
|
||||
<Name>Orchard.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.MediaProcessing\Orchard.MediaProcessing.csproj">
|
||||
<Project>{08191fcd-7258-4f19-95fb-aec3de77b2eb}</Project>
|
||||
<Name>Orchard.MediaProcessing</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Taxonomies\Orchard.Taxonomies.csproj">
|
||||
<Project>{E649EA64-D213-461B-87F7-D67035801443}</Project>
|
||||
<Name>Orchard.Taxonomies</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ModalAdminFilter.cs" />
|
||||
@ -141,12 +135,14 @@
|
||||
<Compile Include="Handlers\WebSearchSettingsPartHandler.cs" />
|
||||
<Compile Include="Migrations.cs" />
|
||||
<Compile Include="Models\AudioPart.cs" />
|
||||
<Compile Include="Models\FolderHierarchy.cs" />
|
||||
<Compile Include="Models\MediaFile.cs" />
|
||||
<Compile Include="Models\MediaFolder.cs" />
|
||||
<Compile Include="Models\WebSearchSettingsPart.cs" />
|
||||
<Compile Include="Models\ImagePart.cs" />
|
||||
<Compile Include="Models\DocumentPart.cs" />
|
||||
<Compile Include="Models\VideoPart.cs" />
|
||||
<Compile Include="Models\OEmbedPart.cs" />
|
||||
<Compile Include="Models\MediaFolder.cs" />
|
||||
<Compile Include="Models\MediaPart.cs" />
|
||||
<Compile Include="Models\MediaPartRecord.cs" />
|
||||
<Compile Include="Permissions.cs" />
|
||||
|
@ -1,34 +1,120 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.MediaLibrary.Factories;
|
||||
using Orchard.MediaLibrary.Models;
|
||||
|
||||
namespace Orchard.MediaLibrary.Services {
|
||||
public interface IMediaLibraryService : IDependency {
|
||||
/// <summary>
|
||||
/// Returns the whole hierarchy of media folders
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IEnumerable<MediaFolder> GetMediaFolders();
|
||||
|
||||
MediaFolder GetMediaFolder(int id);
|
||||
IEnumerable<MediaFolder> GetMediaFolderHierarchy(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the list of all Media Content Types
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IEnumerable<string> GetMediaTypes();
|
||||
|
||||
IContentQuery<MediaPart, MediaPartRecord> GetMediaContentItems();
|
||||
IEnumerable<MediaPart> GetMediaContentItems(string folderPath, int skip, int count, string order, string mediaType);
|
||||
IEnumerable<MediaPart> GetMediaContentItems(int skip, int count, string order, string mediaType);
|
||||
IEnumerable<MediaPart> GetMediaContentItems(int folder, int skip, int count, string order, string mediaType);
|
||||
int GetMediaContentItemsCount(string folderPath, string mediaType);
|
||||
int GetMediaContentItemsCount(string mediaType);
|
||||
int GetMediaContentItemsCount(int folder, string mediaType);
|
||||
MediaPart ImportMedia(string relativePath, string filename);
|
||||
MediaPart ImportMedia(Stream stream, string relativePath, string filename);
|
||||
IMediaFactory GetMediaFactory(Stream stream, string mimeType);
|
||||
|
||||
MediaPart ImportStream(int termId, Stream stream, string filename);
|
||||
/// <summary>
|
||||
/// Creates a unique filename to prevent filename collisions.
|
||||
/// </summary>
|
||||
/// <param name="folderPath">The relative where collisions will be checked.</param>
|
||||
/// <param name="filename">The desired filename.</param>
|
||||
/// <returns>A string representing a unique filename.</returns>
|
||||
string GetUniqueFilename(string folderPath, string filename);
|
||||
|
||||
MediaFolder CreateFolder(int? parentFolderId, string name);
|
||||
void RenameFolder(int folderId, string name);
|
||||
void DeleteFolder(int folderId);
|
||||
void MoveMedia(int targetId, int[] mediaItemIds);
|
||||
/// <summary>
|
||||
/// Returns the public URL for a media file.
|
||||
/// </summary>
|
||||
/// <param name="mediaPath">The relative path of the media folder containing the media.</param>
|
||||
/// <param name="fileName">The media file name.</param>
|
||||
/// <returns>The public URL for the media.</returns>
|
||||
string GetMediaPublicUrl(string mediaPath, string fileName);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the media folders within a given relative path.
|
||||
/// </summary>
|
||||
/// <param name="relativePath">The path where to retrieve the media folder from. null means root.</param>
|
||||
/// <returns>The media folder in the given path.</returns>
|
||||
IEnumerable<MediaFolder> GetMediaFolders(string relativePath);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the media files within a given relative path.
|
||||
/// </summary>
|
||||
/// <param name="relativePath">The path where to retrieve the media files from. null means root.</param>
|
||||
/// <returns>The media files in the given path.</returns>
|
||||
IEnumerable<MediaFile> GetMediaFiles(string relativePath);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a media folder.
|
||||
/// </summary>
|
||||
/// <param name="relativePath">The path where to create the new folder. null means root.</param>
|
||||
/// <param name="folderName">The name of the folder to be created.</param>
|
||||
void CreateFolder(string relativePath, string folderName);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a media folder.
|
||||
/// </summary>
|
||||
/// <param name="folderPath">The path to the folder to be deleted.</param>
|
||||
void DeleteFolder(string folderPath);
|
||||
|
||||
/// <summary>
|
||||
/// Renames a media folder.
|
||||
/// </summary>
|
||||
/// <param name="folderPath">The path to the folder to be renamed.</param>
|
||||
/// <param name="newFolderName">The new folder name.</param>
|
||||
void RenameFolder(string folderPath, string newFolderName);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a media file.
|
||||
/// </summary>
|
||||
/// <param name="folderPath">The folder path.</param>
|
||||
/// <param name="fileName">The file name.</param>
|
||||
void DeleteFile(string folderPath, string fileName);
|
||||
|
||||
/// <summary>
|
||||
/// Renames a media file.
|
||||
/// </summary>
|
||||
/// <param name="folderPath">The path to the file's parent folder.</param>
|
||||
/// <param name="currentFileName">The current file name.</param>
|
||||
/// <param name="newFileName">The new file name.</param>
|
||||
void RenameFile(string folderPath, string currentFileName, string newFileName);
|
||||
|
||||
/// <summary>
|
||||
/// Moves a media file.
|
||||
/// </summary>
|
||||
/// <param name="currentPath">The path to the file's parent folder.</param>
|
||||
/// <param name="filename">The file name.</param>
|
||||
/// <param name="newPath">The path where the file will be moved to.</param>
|
||||
/// <param name="newFilename">The new file name.</param>
|
||||
void MoveFile(string currentPath, string filename, string newPath, string newFilename);
|
||||
|
||||
/// <summary>
|
||||
/// Uploads a media file based on a posted file.
|
||||
/// </summary>
|
||||
/// <param name="folderPath">The path to the folder where to upload the file.</param>
|
||||
/// <param name="postedFile">The file to upload.</param>
|
||||
/// <returns>The path to the uploaded file.</returns>
|
||||
string UploadMediaFile(string folderPath, HttpPostedFileBase postedFile);
|
||||
|
||||
/// <summary>
|
||||
/// Uploads a media file based on an array of bytes.
|
||||
/// </summary>
|
||||
/// <param name="folderPath">The path to the folder where to upload the file.</param>
|
||||
/// <param name="fileName">The file name.</param>
|
||||
/// <param name="bytes">The array of bytes with the file's contents.</param>
|
||||
/// <returns>The path to the uploaded file.</returns>
|
||||
string UploadMediaFile(string folderPath, string fileName, byte[] bytes);
|
||||
|
||||
/// <summary>
|
||||
/// Uploads a media file based on a stream.
|
||||
/// </summary>
|
||||
/// <param name="folderPath">The folder path to where to upload the file.</param>
|
||||
/// <param name="fileName">The file name.</param>
|
||||
/// <param name="inputStream">The stream with the file's contents.</param>
|
||||
/// <returns>The path to the uploaded file.</returns>
|
||||
string UploadMediaFile(string folderPath, string fileName, Stream inputStream);
|
||||
}
|
||||
}
|
@ -2,106 +2,57 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.FileSystems.Media;
|
||||
using Orchard.Localization;
|
||||
using Orchard.MediaLibrary.Factories;
|
||||
using Orchard.MediaLibrary.Models;
|
||||
using Orchard.Taxonomies.Models;
|
||||
using Orchard.Taxonomies.Services;
|
||||
using Orchard.Core.Title.Models;
|
||||
using Orchard.Validation;
|
||||
|
||||
namespace Orchard.MediaLibrary.Services {
|
||||
public class MediaLibraryService : IMediaLibraryService {
|
||||
private readonly ITaxonomyService _taxonomyService;
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
private readonly IMimeTypeProvider _mimeTypeProvider;
|
||||
private readonly IStorageProvider _storageProvider;
|
||||
private readonly IEnumerable<IMediaFactorySelector> _mediaFactorySelectors;
|
||||
public const string MediaLocation = "Media Location";
|
||||
|
||||
public MediaLibraryService(
|
||||
ITaxonomyService taxonomyService,
|
||||
IContentManager contentManager,
|
||||
IOrchardServices orchardServices,
|
||||
IMimeTypeProvider mimeTypeProvider,
|
||||
IEnumerable<IMediaFactorySelector> mediaFactorySelectors ) {
|
||||
_taxonomyService = taxonomyService;
|
||||
_contentManager = contentManager;
|
||||
IStorageProvider storageProvider,
|
||||
IEnumerable<IMediaFactorySelector> mediaFactorySelectors) {
|
||||
_orchardServices = orchardServices;
|
||||
_mimeTypeProvider = mimeTypeProvider;
|
||||
_storageProvider = storageProvider;
|
||||
_mediaFactorySelectors = mediaFactorySelectors;
|
||||
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
private TaxonomyPart GetMediaLocationTaxonomy() {
|
||||
return _taxonomyService.GetTaxonomyByName(MediaLocation);
|
||||
}
|
||||
|
||||
public IEnumerable<MediaFolder> GetMediaFolders() {
|
||||
var taxonomy = GetMediaLocationTaxonomy();
|
||||
|
||||
var terms = _taxonomyService.GetTerms(taxonomy.Id);
|
||||
var rootFolders = new List<MediaFolder>();
|
||||
var index = new Dictionary<int, MediaFolder>();
|
||||
|
||||
_taxonomyService.CreateHierarchy(terms, (parent, child) => {
|
||||
MediaFolder parentFolder;
|
||||
MediaFolder childFolder = CreateMediaFolder(child.TermPart);
|
||||
index.Add(child.TermPart.Id, childFolder);
|
||||
|
||||
// adding to root
|
||||
if (parent.TermPart != null) {
|
||||
parentFolder = index.ContainsKey(parent.TermPart.Id) ? index[parent.TermPart.Id] : null;
|
||||
parentFolder.Folders.Add(childFolder);
|
||||
}
|
||||
else {
|
||||
rootFolders.Add(childFolder);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return rootFolders;
|
||||
}
|
||||
|
||||
public MediaFolder GetMediaFolder(int id) {
|
||||
return CreateMediaFolder(_taxonomyService.GetTerm(id));
|
||||
}
|
||||
|
||||
public IEnumerable<MediaFolder> GetMediaFolderHierarchy(int id) {
|
||||
var target = CreateMediaFolder(_taxonomyService.GetTerm(id));
|
||||
if (target == null) {
|
||||
yield break;
|
||||
}
|
||||
|
||||
yield return target;
|
||||
|
||||
while (target.ParentTermId.HasValue) {
|
||||
target = CreateMediaFolder(_taxonomyService.GetTerm(target.ParentTermId.Value));
|
||||
|
||||
if (target == null) {
|
||||
yield break;
|
||||
}
|
||||
|
||||
yield return target;
|
||||
}
|
||||
}
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public IEnumerable<string> GetMediaTypes() {
|
||||
return _contentManager.GetContentTypeDefinitions()
|
||||
return _orchardServices.ContentManager.GetContentTypeDefinitions()
|
||||
.Where(contentTypeDefinition => contentTypeDefinition.Settings.ContainsKey("Stereotype") && contentTypeDefinition.Settings["Stereotype"] == "Widget")
|
||||
.Select(contentTypeDefinition => contentTypeDefinition.Name);
|
||||
}
|
||||
|
||||
public IContentQuery<MediaPart, MediaPartRecord> GetMediaContentItems() {
|
||||
return _contentManager.Query<MediaPart, MediaPartRecord>();
|
||||
return _orchardServices.ContentManager.Query<MediaPart, MediaPartRecord>();
|
||||
}
|
||||
|
||||
public IEnumerable<MediaPart> GetMediaContentItems(int folder, int skip, int count, string order, string mediaType) {
|
||||
var query = _contentManager.Query<MediaPart>();
|
||||
public IEnumerable<MediaPart> GetMediaContentItems(string folderPath, int skip, int count, string order, string mediaType) {
|
||||
var query = _orchardServices.ContentManager.Query<MediaPart>();
|
||||
|
||||
if (!String.IsNullOrEmpty(mediaType)) {
|
||||
query = query.ForType(new[] { mediaType });
|
||||
}
|
||||
|
||||
if (folder > 0) {
|
||||
query = query.Join<MediaPartRecord>().Where(m => m.TermPartRecord.Id == folder);
|
||||
if (!String.IsNullOrEmpty(folderPath)) {
|
||||
query = query.Join<MediaPartRecord>().Where(m => m.FolderPath == folderPath);
|
||||
}
|
||||
|
||||
switch(order) {
|
||||
@ -132,38 +83,67 @@ namespace Orchard.MediaLibrary.Services {
|
||||
}
|
||||
|
||||
public IEnumerable<MediaPart> GetMediaContentItems(int skip, int count, string order, string mediaType) {
|
||||
return GetMediaContentItems(-1, skip, count, order, mediaType);
|
||||
return GetMediaContentItems(null, skip, count, order, mediaType);
|
||||
}
|
||||
|
||||
public int GetMediaContentItemsCount(int folder, string mediaType) {
|
||||
var query = _contentManager.Query<MediaPart>();
|
||||
public int GetMediaContentItemsCount(string folderPath, string mediaType) {
|
||||
var query = _orchardServices.ContentManager.Query<MediaPart>();
|
||||
|
||||
if (!String.IsNullOrEmpty(mediaType)) {
|
||||
query = query.ForType(new[] { mediaType });
|
||||
}
|
||||
|
||||
if (folder > 0) {
|
||||
query = query.Join<MediaPartRecord>().Where(m => m.TermPartRecord.Id == folder);
|
||||
if (!String.IsNullOrEmpty(folderPath)) {
|
||||
query = query.Join<MediaPartRecord>().Where(m => m.FolderPath == folderPath);
|
||||
}
|
||||
|
||||
return query.Count();
|
||||
}
|
||||
|
||||
public int GetMediaContentItemsCount(string mediaType) {
|
||||
return GetMediaContentItemsCount(-1, mediaType);
|
||||
return GetMediaContentItemsCount(null, mediaType);
|
||||
}
|
||||
|
||||
public MediaPart ImportStream(int termId, Stream stream, string filename) {
|
||||
var mimeType = _mimeTypeProvider.GetMimeType(filename);
|
||||
public MediaPart ImportMedia(Stream stream, string relativePath, string filename) {
|
||||
var uniqueFilename = GetUniqueFilename(relativePath, filename);
|
||||
|
||||
var mediaFactory = GetMediaFactory(stream, mimeType);
|
||||
var mediaPart = mediaFactory.CreateMedia(stream, filename, mimeType);
|
||||
if (mediaPart != null) {
|
||||
mediaPart.TermPart = _taxonomyService.GetTerm(termId);
|
||||
_contentManager.Create(mediaPart);
|
||||
UploadMediaFile(relativePath, uniqueFilename, stream);
|
||||
return ImportMedia(relativePath, uniqueFilename);
|
||||
}
|
||||
|
||||
public string GetUniqueFilename(string folderPath, string filename) {
|
||||
// compute a unique filename
|
||||
var uniqueFilename = filename;
|
||||
var index = 1;
|
||||
while (_storageProvider.FileExists(_storageProvider.Combine(folderPath, uniqueFilename))) {
|
||||
uniqueFilename = Path.GetFileNameWithoutExtension(filename) + "-" + index++ + Path.GetExtension(filename);
|
||||
}
|
||||
|
||||
return mediaPart;
|
||||
return uniqueFilename;
|
||||
}
|
||||
|
||||
public MediaPart ImportMedia(string relativePath, string filename) {
|
||||
|
||||
var mimeType = _mimeTypeProvider.GetMimeType(filename);
|
||||
|
||||
if (!_storageProvider.FileExists(_storageProvider.Combine(relativePath, filename))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var storageFile = _storageProvider.GetFile(_storageProvider.Combine(relativePath, filename));
|
||||
var mediaFile = BuildMediaFile(relativePath, storageFile);
|
||||
|
||||
using (var stream = storageFile.OpenRead()) {
|
||||
var mediaFactory = GetMediaFactory(stream, mimeType);
|
||||
var mediaPart = mediaFactory.CreateMedia(stream, mediaFile.Name, mimeType);
|
||||
if (mediaPart != null) {
|
||||
mediaPart.FolderPath = relativePath;
|
||||
mediaPart.FileName = filename;
|
||||
_orchardServices.ContentManager.Create(mediaPart);
|
||||
}
|
||||
|
||||
return mediaPart;
|
||||
}
|
||||
}
|
||||
|
||||
public IMediaFactory GetMediaFactory(Stream stream, string mimeType) {
|
||||
@ -173,59 +153,198 @@ namespace Orchard.MediaLibrary.Services {
|
||||
.OrderByDescending(x => x.Priority);
|
||||
|
||||
if (!requestMediaFactoryResults.Any() )
|
||||
return NullMediaFactory.Instance;
|
||||
return null;
|
||||
|
||||
return requestMediaFactoryResults.First().MediaFactory;
|
||||
}
|
||||
|
||||
public MediaFolder CreateFolder(int? parentFolderId, string name) {
|
||||
var taxonomy = GetMediaLocationTaxonomy();
|
||||
TermPart parentTerm = parentFolderId.HasValue ? _taxonomyService.GetTerm(parentFolderId.Value) : null;
|
||||
var term = _taxonomyService.NewTerm(taxonomy);
|
||||
term.Container = parentTerm == null ? taxonomy.ContentItem : parentTerm.ContentItem;
|
||||
/// <summary>
|
||||
/// Retrieves the public path based on the relative path within the media directory.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// "/Media/Default/InnerDirectory/Test.txt" based on the input "InnerDirectory/Test.txt"
|
||||
/// </example>
|
||||
/// <param name="relativePath">The relative path within the media directory.</param>
|
||||
/// <returns>The public path relative to the application url.</returns>
|
||||
public string GetPublicUrl(string relativePath) {
|
||||
Argument.ThrowIfNullOrEmpty(relativePath, "relativePath");
|
||||
|
||||
term.Name = name;
|
||||
|
||||
_taxonomyService.ProcessPath(term);
|
||||
_contentManager.Create(term, VersionOptions.Published);
|
||||
|
||||
return CreateMediaFolder(term);
|
||||
return _storageProvider.GetPublicUrl(relativePath);
|
||||
}
|
||||
|
||||
public void RenameFolder(int folderId, string name) {
|
||||
var term = _taxonomyService.GetTerm(folderId);
|
||||
term.Name = name;
|
||||
/// <summary>
|
||||
/// Returns the public URL for a media file.
|
||||
/// </summary>
|
||||
/// <param name="mediaPath">The relative path of the media folder containing the media.</param>
|
||||
/// <param name="fileName">The media file name.</param>
|
||||
/// <returns>The public URL for the media.</returns>
|
||||
public string GetMediaPublicUrl(string mediaPath, string fileName) {
|
||||
return GetPublicUrl(Path.Combine(mediaPath, fileName));
|
||||
}
|
||||
|
||||
public void DeleteFolder(int folderId) {
|
||||
var term = _taxonomyService.GetTerm(folderId);
|
||||
_taxonomyService.DeleteTerm(term);
|
||||
/// <summary>
|
||||
/// Retrieves the media folders within a given relative path.
|
||||
/// </summary>
|
||||
/// <param name="relativePath">The path where to retrieve the media folder from. null means root.</param>
|
||||
/// <returns>The media folder in the given path.</returns>
|
||||
public IEnumerable<MediaFolder> GetMediaFolders(string relativePath) {
|
||||
return _storageProvider
|
||||
.ListFolders(relativePath)
|
||||
.Select(BuildMediaFolder)
|
||||
.Where(f => !f.Name.Equals("RecipeJournal", StringComparison.OrdinalIgnoreCase))
|
||||
.Where(f => !f.Name.StartsWith("_"))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private MediaFolder CreateMediaFolder(TermPart termPart) {
|
||||
if (termPart == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new MediaFolder{
|
||||
Name = termPart.Name,
|
||||
MediaPath = termPart.FullPath,
|
||||
TermId = termPart.Id,
|
||||
ParentTermId = termPart.Container != null ? termPart.Container.Id : default(int?)
|
||||
private static MediaFolder BuildMediaFolder(IStorageFolder folder) {
|
||||
return new MediaFolder {
|
||||
Name = folder.GetName(),
|
||||
Size = folder.GetSize(),
|
||||
LastUpdated = folder.GetLastUpdated(),
|
||||
MediaPath = folder.GetPath()
|
||||
};
|
||||
}
|
||||
|
||||
public void MoveMedia(int targetId, int[] mediaItemIds) {
|
||||
var targetFolder = _taxonomyService.GetTerm(targetId);
|
||||
if (targetFolder == null) {
|
||||
throw new ArgumentException("Target folder doesn't exist");
|
||||
}
|
||||
/// <summary>
|
||||
/// Retrieves the media files within a given relative path.
|
||||
/// </summary>
|
||||
/// <param name="relativePath">The path where to retrieve the media files from. null means root.</param>
|
||||
/// <returns>The media files in the given path.</returns>
|
||||
public IEnumerable<MediaFile> GetMediaFiles(string relativePath) {
|
||||
return _storageProvider.ListFiles(relativePath).Select(file =>
|
||||
BuildMediaFile(relativePath, file)).ToList();
|
||||
}
|
||||
|
||||
var mediaItems = GetMediaContentItems().Where<MediaPartRecord>(x => mediaItemIds.Contains(x.Id)).List();
|
||||
private MediaFile BuildMediaFile(string relativePath, IStorageFile file) {
|
||||
return new MediaFile {
|
||||
Name = file.GetName(),
|
||||
Size = file.GetSize(),
|
||||
LastUpdated = file.GetLastUpdated(),
|
||||
Type = file.GetFileType(),
|
||||
FolderName = relativePath,
|
||||
MediaPath = GetMediaPublicUrl(relativePath, file.GetName())
|
||||
};
|
||||
}
|
||||
|
||||
foreach (var mediaItem in mediaItems) {
|
||||
mediaItem.TermPart = targetFolder;
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a media folder.
|
||||
/// </summary>
|
||||
/// <param name="relativePath">The path where to create the new folder. null means root.</param>
|
||||
/// <param name="folderName">The name of the folder to be created.</param>
|
||||
public void CreateFolder(string relativePath, string folderName) {
|
||||
Argument.ThrowIfNullOrEmpty(folderName, "folderName");
|
||||
|
||||
_storageProvider.CreateFolder(relativePath == null ? folderName : _storageProvider.Combine(relativePath, folderName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a media folder.
|
||||
/// </summary>
|
||||
/// <param name="folderPath">The path to the folder to be deleted.</param>
|
||||
public void DeleteFolder(string folderPath) {
|
||||
Argument.ThrowIfNullOrEmpty(folderPath, "folderPath");
|
||||
|
||||
_storageProvider.DeleteFolder(folderPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renames a media folder.
|
||||
/// </summary>
|
||||
/// <param name="folderPath">The path to the folder to be renamed.</param>
|
||||
/// <param name="newFolderName">The new folder name.</param>
|
||||
public void RenameFolder(string folderPath, string newFolderName) {
|
||||
Argument.ThrowIfNullOrEmpty(folderPath, "folderPath");
|
||||
Argument.ThrowIfNullOrEmpty(newFolderName, "newFolderName");
|
||||
|
||||
_storageProvider.RenameFolder(folderPath, _storageProvider.Combine(Path.GetDirectoryName(folderPath), newFolderName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a media file.
|
||||
/// </summary>
|
||||
/// <param name="folderPath">The folder path.</param>
|
||||
/// <param name="fileName">The file name.</param>
|
||||
public void DeleteFile(string folderPath, string fileName) {
|
||||
Argument.ThrowIfNullOrEmpty(folderPath, "folderPath");
|
||||
Argument.ThrowIfNullOrEmpty(fileName, "fileName");
|
||||
|
||||
_storageProvider.DeleteFile(_storageProvider.Combine(folderPath, fileName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renames a media file.
|
||||
/// </summary>
|
||||
/// <param name="folderPath">The path to the file's parent folder.</param>
|
||||
/// <param name="currentFileName">The current file name.</param>
|
||||
/// <param name="newFileName">The new file name.</param>
|
||||
public void RenameFile(string folderPath, string currentFileName, string newFileName) {
|
||||
Argument.ThrowIfNullOrEmpty(folderPath, "folderPath");
|
||||
Argument.ThrowIfNullOrEmpty(currentFileName, "currentFileName");
|
||||
Argument.ThrowIfNullOrEmpty(newFileName, "newFileName");
|
||||
|
||||
_storageProvider.RenameFile(_storageProvider.Combine(folderPath, currentFileName), _storageProvider.Combine(folderPath, newFileName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves a media file.
|
||||
/// </summary>
|
||||
/// <param name="currentPath">The path to the file's parent folder.</param>
|
||||
/// <param name="filename">The file name.</param>
|
||||
/// <param name="newPath">The path where the file will be moved to.</param>
|
||||
/// <param name="newFilename">The new file name.</param>
|
||||
public void MoveFile(string currentPath, string filename, string newPath, string newFilename) {
|
||||
Argument.ThrowIfNullOrEmpty(currentPath, "currentPath");
|
||||
Argument.ThrowIfNullOrEmpty(newPath, "newPath");
|
||||
Argument.ThrowIfNullOrEmpty(filename, "filename");
|
||||
Argument.ThrowIfNullOrEmpty(newFilename, "newFilename");
|
||||
|
||||
_storageProvider.RenameFile(_storageProvider.Combine(currentPath, filename), _storageProvider.Combine(newPath, newFilename));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uploads a media file based on a posted file.
|
||||
/// </summary>
|
||||
/// <param name="folderPath">The path to the folder where to upload the file.</param>
|
||||
/// <param name="postedFile">The file to upload.</param>
|
||||
/// <returns>The path to the uploaded file.</returns>
|
||||
public string UploadMediaFile(string folderPath, HttpPostedFileBase postedFile) {
|
||||
Argument.ThrowIfNullOrEmpty(folderPath, "folderPath");
|
||||
Argument.ThrowIfNull(postedFile, "postedFile");
|
||||
|
||||
return UploadMediaFile(folderPath, Path.GetFileName(postedFile.FileName), postedFile.InputStream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uploads a media file based on an array of bytes.
|
||||
/// </summary>
|
||||
/// <param name="folderPath">The path to the folder where to upload the file.</param>
|
||||
/// <param name="fileName">The file name.</param>
|
||||
/// <param name="bytes">The array of bytes with the file's contents.</param>
|
||||
/// <returns>The path to the uploaded file.</returns>
|
||||
public string UploadMediaFile(string folderPath, string fileName, byte[] bytes) {
|
||||
Argument.ThrowIfNullOrEmpty(folderPath, "folderPath");
|
||||
Argument.ThrowIfNullOrEmpty(fileName, "fileName");
|
||||
Argument.ThrowIfNull(bytes, "bytes");
|
||||
|
||||
return UploadMediaFile(folderPath, fileName, new MemoryStream(bytes));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uploads a media file based on a stream.
|
||||
/// </summary>
|
||||
/// <param name="folderPath">The folder path to where to upload the file.</param>
|
||||
/// <param name="fileName">The file name.</param>
|
||||
/// <param name="inputStream">The stream with the file's contents.</param>
|
||||
/// <returns>The path to the uploaded file.</returns>
|
||||
public string UploadMediaFile(string folderPath, string fileName, Stream inputStream) {
|
||||
Argument.ThrowIfNullOrEmpty(folderPath, "folderPath");
|
||||
Argument.ThrowIfNullOrEmpty(fileName, "fileName");
|
||||
Argument.ThrowIfNull(inputStream, "inputStream");
|
||||
|
||||
string filePath = _storageProvider.Combine(folderPath, fileName);
|
||||
_storageProvider.SaveStream(filePath, inputStream);
|
||||
|
||||
return _storageProvider.GetPublicUrl(filePath);
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 360 B |
@ -0,0 +1,6 @@
|
||||
.navicon-media {
|
||||
background-image:url(images/menu.media.png) !important;
|
||||
}
|
||||
.navicon-media:hover {
|
||||
background-position:0 -30px !important;
|
||||
}
|
@ -4,7 +4,7 @@ using Orchard.MediaLibrary.Models;
|
||||
namespace Orchard.MediaLibrary.ViewModels {
|
||||
public class MediaManagerFolderCreateViewModel {
|
||||
public string Name { get; set; }
|
||||
public int? ParentFolderId { get; set; }
|
||||
public string FolderPath { get; set; }
|
||||
public IEnumerable<MediaFolder> Hierarchy { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ namespace Orchard.MediaLibrary.ViewModels {
|
||||
public class MediaManagerFolderEditViewModel {
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
public int FolderId { get; set; }
|
||||
public string FolderPath { get; set; }
|
||||
public IEnumerable<MediaFolder> Hierarchy { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.MediaLibrary.Models;
|
||||
using Orchard.UI.Navigation;
|
||||
|
||||
namespace Orchard.MediaLibrary.ViewModels {
|
||||
public class MediaManagerImportViewModel {
|
||||
public IEnumerable<MenuItem> Menu { get; set; }
|
||||
public IEnumerable<string> ImageSets { get; set; }
|
||||
public ICollection<MediaFolder> Hierarchy { get; set; }
|
||||
public string FolderPath { get; set; }
|
||||
}
|
||||
}
|
@ -3,9 +3,8 @@ using Orchard.MediaLibrary.Models;
|
||||
|
||||
namespace Orchard.MediaLibrary.ViewModels {
|
||||
public class MediaManagerIndexViewModel {
|
||||
public IEnumerable<MediaFolder> Folders { get; set; }
|
||||
public IEnumerable<MediaFolder> Hierarchy { get; set; }
|
||||
public int? Folder { get; set; }
|
||||
public IEnumerable<FolderHierarchy> Folders { get; set; }
|
||||
public string FolderPath { get; set; }
|
||||
public bool DialogMode { get; set; }
|
||||
public string[] MediaTypes { get; set; }
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Orchard.MediaLibrary.ViewModels {
|
||||
public class OEmbedViewModel {
|
||||
public int Id { get; set; }
|
||||
public string FolderPath { get; set; }
|
||||
public string Url { get; set; }
|
||||
public XDocument Content { get; set; }
|
||||
public bool Success { get; set; }
|
||||
|
@ -19,10 +19,10 @@
|
||||
<div id="media-library-toolbar">
|
||||
|
||||
<div id="media-library-toolbar-actions">
|
||||
<a href="@Url.Action("Index", "Admin", new { id = Model.Hierarchy.First().TermId})" class="button">@T("Close")</a>
|
||||
<a href="@Url.Action("Index", "Admin", new { folderPath = Model.FolderPath})" class="button">@T("Close")</a>
|
||||
</div>
|
||||
|
||||
@T("Media Folders") @foreach (var folder in Model.Hierarchy.Reverse()) {<text> > </text>@folder.Name}
|
||||
@T("Media Folders") @foreach (var folder in Model.FolderPath.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar}, StringSplitOptions.RemoveEmptyEntries)) {<text> > </text>@folder}
|
||||
|
||||
</div>
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
string sectionHeaderTextHint = menuItem.Text.TextHint;
|
||||
var itemClassName = "navicon-" + sectionHeaderTextHint.HtmlClassify();
|
||||
|
||||
<div class="import-provider"><a class="navicon @itemClassName" href="@menuItem.Href/Index/@Model.Hierarchy.First().TermId">@menuItem.Text</a></div>
|
||||
<div class="import-provider"><a class="navicon @itemClassName" href="@menuItem.Href/Index?folderPath=@HttpUtility.UrlEncode(Model.FolderPath)">@menuItem.Text</a></div>
|
||||
}
|
||||
</div>
|
||||
<div id="media-library-main-list-wrapper">
|
||||
|
@ -17,8 +17,8 @@
|
||||
<div id="media-library">
|
||||
<div id="media-library-toolbar">
|
||||
<a href="#" data-bind="visible: displayed(), click: importMedia" class="button" id="button-import">@T("Import")</a>
|
||||
<a href="#" data-bind="visible: displayed(), attr: { href: '@HttpUtility.JavaScriptStringEncode(Url.Action("Create", "Folder", new { area = "Orchard.MediaLibrary"}))/' + displayed() }" class="button" id="button-create-folder">@T("Create Folder")</a>
|
||||
<a href="#" data-bind="visible: displayed(), attr: { href: '@HttpUtility.JavaScriptStringEncode(Url.Action("Edit", "Folder", new { area = "Orchard.MediaLibrary"}))/' + displayed() }" class="button" id="button-edit-folder">@T("Edit Folder")</a>
|
||||
<a href="#" data-bind="visible: displayed(), attr: { href: '@HttpUtility.JavaScriptStringEncode(Url.Action("Edit", "Folder", new { area = "Orchard.MediaLibrary"}))/folderPath=' + encodeURIComponent(displayed()) }" class="button" id="button-edit-folder">@T("Edit Folder")</a>
|
||||
<a href="#" data-bind="attr: { href: '@HttpUtility.JavaScriptStringEncode(Url.Action("Create", "Folder", new { area = "Orchard.MediaLibrary"}))?folderPath=' + encodeURIComponent(displayed() ? displayed() : '') }" class="button" id="button-create-folder">@T("Create Folder")</a>
|
||||
|
||||
<label for="filterMediaType">@T("Show")</label>
|
||||
<select id="filterMediaType" name="FilteredMediaType" data-bind="selectedOptions: mediaType">
|
||||
@ -162,20 +162,19 @@
|
||||
self.orderMedia = ko.observableArray(['created']);
|
||||
self.mediaType = ko.observableArray([]);
|
||||
|
||||
self.getMediaItems = function (id, max) {
|
||||
self.getMediaItems = function (folderPath, max) {
|
||||
if (self.pendingRequest()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.results().length > 0 && self.results().length >= self.mediaItemsCount) {
|
||||
// console.log('no more content, mediaItemsCount: ' + self.mediaItemsCount);
|
||||
return;
|
||||
}
|
||||
|
||||
self.pendingRequest(true);
|
||||
|
||||
var url = id
|
||||
? '@HttpUtility.JavaScriptStringEncode(Url.Action("MediaItems", "Admin"))/' + id + '?skip=' + self.results().length + '&count=' + max + '&order=' + self.orderMedia() + '&mediaType=' + self.mediaType()
|
||||
var url = folderPath
|
||||
? '@HttpUtility.JavaScriptStringEncode(Url.Action("MediaItems", "Admin"))?folderPath=' + encodeURIComponent(folderPath) + '&skip=' + self.results().length + '&count=' + max + '&order=' + self.orderMedia() + '&mediaType=' + self.mediaType()
|
||||
: '@HttpUtility.JavaScriptStringEncode(Url.Action("RecentMediaItems", "Admin"))?skip=' + self.results().length + '&count=' + max + '&order=' + self.orderMedia() + '&mediaType=' + self.mediaType();
|
||||
|
||||
$.ajax({
|
||||
@ -238,17 +237,17 @@
|
||||
}
|
||||
});
|
||||
|
||||
self.displayFolder = function (id) {
|
||||
self.displayFolder = function (folderPath) {
|
||||
|
||||
self.results([]);
|
||||
|
||||
self.getMediaItems(id, 20);
|
||||
self.displayed(id);
|
||||
self.getMediaItems(folderPath, 20);
|
||||
self.displayed(folderPath);
|
||||
};
|
||||
|
||||
self.selectFolder = function (id) {
|
||||
window.history.pushState({ action: 'displayFolder', folder: id }, '', '?folder=' + id);
|
||||
self.displayFolder(id);
|
||||
self.selectFolder = function (folderPath) {
|
||||
window.history.pushState({ action: 'displayFolder', folderPath: folderPath }, '', '?folderPath=' + folderPath);
|
||||
self.displayFolder(folderPath);
|
||||
};
|
||||
|
||||
self.selectRecent = function () {
|
||||
@ -335,7 +334,7 @@
|
||||
};
|
||||
|
||||
self.importMedia = function() {
|
||||
var url = '@HttpUtility.JavaScriptStringEncode(Url.Action("Import", "Admin"))/' + self.displayed();
|
||||
var url = '@HttpUtility.JavaScriptStringEncode(Url.Action("Import", "Admin"))?folderPath=' + encodeURIComponent(self.displayed());
|
||||
window.location = url;
|
||||
};
|
||||
|
||||
@ -361,10 +360,10 @@
|
||||
var viewModel = new MediaIndexViewModel();
|
||||
ko.applyBindings(viewModel);
|
||||
|
||||
@if (viewModel.Folder.HasValue) {
|
||||
@if (viewModel.FolderPath != null) {
|
||||
<text>
|
||||
viewModel.displayFolder(@viewModel.Folder.Value);
|
||||
window.history.pushState({ action: 'displayFolder', folder: @viewModel.Folder.Value }, '', '?folder=@viewModel.Folder.Value');
|
||||
viewModel.displayFolder('@HttpUtility.JavaScriptStringEncode(viewModel.FolderPath)');
|
||||
window.history.pushState({ action: 'displayFolder', folderPath: '@HttpUtility.JavaScriptStringEncode(viewModel.FolderPath)' }, '', '?folderPath=@HttpUtility.UrlEncode(viewModel.FolderPath)');
|
||||
</text>
|
||||
}
|
||||
else {
|
||||
@ -437,24 +436,25 @@
|
||||
tolerance: "pointer",
|
||||
drop: function(event, ui) {
|
||||
$(this).removeClass('dropping');
|
||||
var targetId = $(this).data('term-id');
|
||||
var folderPath = $(this).data('media-path');
|
||||
|
||||
if (targetId == viewModel.displayed()) {
|
||||
if (folderPath == viewModel.displayed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var ids = [];
|
||||
viewModel.selection().forEach(function(item) { ids.push(item.data.id); });
|
||||
var url = '@Url.Action("Move", "Folder", new { area = "Orchard.MediaLibrary" })';
|
||||
|
||||
|
||||
console.log(folderPath);
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: url,
|
||||
dataType: "json",
|
||||
traditional: true,
|
||||
data: {
|
||||
targetId: targetId,
|
||||
folderPath: folderPath,
|
||||
mediaItemIds: ids,
|
||||
__RequestVerificationToken: '@Html.AntiForgeryTokenValueOrchard()'
|
||||
},
|
||||
|
@ -12,7 +12,7 @@
|
||||
title = x.MediaPart.Title,
|
||||
alternateText = x.MediaPart.AlternateText,
|
||||
caption = x.MediaPart.Caption,
|
||||
resource = x.MediaPart.Resource,
|
||||
resource = x.MediaPart.MediaUrl,
|
||||
mimeType = x.MediaPart.MimeType,
|
||||
mimeTypeClass = x.MediaPart.MimeType.HtmlClassify(),
|
||||
thumbnail = Display(x.Shape).ToString(),
|
||||
|
@ -1,12 +1,12 @@
|
||||
@model Orchard.MediaLibrary.Models.MediaFolder
|
||||
@model Orchard.MediaLibrary.Models.FolderHierarchy
|
||||
|
||||
<div class="media-library-folder">
|
||||
<div class="media-library-folder-title" data-bind="click: function(data, event) { selectFolder(@Model.TermId); }, css: { selected: displayed() == $element.getAttribute('data-term-id') }" data-term-id="@Model.TermId" >
|
||||
<a data-bind="disable: $root.pendingRequest" href="#" class="media-library-navigation-folder-link" data-mediapath="@Model.MediaPath"><i class="icon-folder-close-alt"></i>@Model.Name</a>
|
||||
<div class="media-library-folder-title" data-bind="click: function(data, event) { selectFolder('@HttpUtility.JavaScriptStringEncode(Model.Root.MediaPath)'); }, css: { selected: displayed() == $element.getAttribute('data-media-path') }" data-media-path="@Model.Root.MediaPath" >
|
||||
<a data-bind="disable: $root.pendingRequest" href="#" class="media-library-navigation-folder-link" data-mediapath="@Model.Root.MediaPath"><i class="icon-folder-close-alt"></i>@Model.Root.Name</a>
|
||||
</div>
|
||||
@if (Model.Folders.Any()) {
|
||||
@if (Model.Children.Any()) {
|
||||
<ul>
|
||||
@foreach (var folder in Model.Folders) {
|
||||
@foreach (var folder in Model.Children) {
|
||||
<li>
|
||||
@Display.Partial(TemplateName: "MediaManagerFolder", Model: folder)
|
||||
</li>
|
||||
|
@ -87,7 +87,7 @@
|
||||
url: '@Url.Action("Upload", "ClientStorage")',
|
||||
autoUpload: true,
|
||||
formData: {
|
||||
id: @Model,
|
||||
folderPath: '@HttpUtility.JavaScriptStringEncode(Model)',
|
||||
__RequestVerificationToken: '@Html.AntiForgeryTokenValueOrchard()'
|
||||
},
|
||||
done: function (e, data) {
|
||||
|
@ -4,11 +4,14 @@
|
||||
}
|
||||
|
||||
<div class="breadCrumbs">
|
||||
<p>@Html.ActionLink(T("Media Library").ToString(), "Index", "Admin", new { area = "Orchard.MediaLibrary" }) >
|
||||
@foreach (var folder in Model.Hierarchy) {
|
||||
@Html.ActionLink(folder.Name, "Edit", new { id = folder.TermId }) <text>></text>
|
||||
<p>@Html.ActionLink(T("Media Library").ToString(), "Index", "Admin", new { area = "Orchard.MediaLibrary" }) >
|
||||
@foreach (var folder in Model.FolderPath.Split('/')) {
|
||||
if (!String.IsNullOrEmpty(folder)) {
|
||||
@Html.ActionLink(folder, "Edit", new {folderPath = folder})
|
||||
<text>></text>
|
||||
}
|
||||
@T("Add a Folder") </p>
|
||||
}
|
||||
@T("Add a Folder") </p>
|
||||
</div>
|
||||
|
||||
@using (Html.BeginFormAntiForgeryPost()) {
|
||||
@ -16,10 +19,10 @@
|
||||
<fieldset>
|
||||
<label for="Name">@T("Folder Name")</label>
|
||||
<input id="Name" class="textMedium" name="Name" type="text" autofocus="autofocus"/>
|
||||
@Html.HiddenFor(m => m.ParentFolderId)
|
||||
@Html.HiddenFor(m => m.FolderPath)
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<button class="primaryAction" type="submit">@T("Save")</button>
|
||||
@Html.ActionLink(T("Cancel").ToString(), "Index", "Admin", new { area = "Orchard.MediaLibrary" }, new { @class= "button"})
|
||||
@Html.ActionLink(T("Cancel").ToString(), "Index", "Admin", new { area = "Orchard.MediaLibrary", folderPath = Model.FolderPath }, new { @class= "button"})
|
||||
</fieldset>
|
||||
}
|
@ -10,5 +10,5 @@
|
||||
}
|
||||
|
||||
<div class="media-thumbnail media-thumbnail-@contentItem.ContentType.HtmlClassify() mime-type-@media.MimeType.HtmlClassify()">
|
||||
<img src="@Display.ResizeMediaUrl(Width: 200, Height: 200, Mode: "crop", Alignment: "middlecenter", Path: media.Resource)" >
|
||||
<img src="@Display.ResizeMediaUrl(Width: 200, Height: 200, Mode: "crop", Alignment: "middlecenter", Path: media.MediaUrl)" >
|
||||
</div>
|
@ -1,8 +1,5 @@
|
||||
@model Orchard.MediaLibrary.ViewModels.OEmbedViewModel
|
||||
|
||||
@using System.Text
|
||||
@using System.Xml;
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
@ -57,7 +54,7 @@
|
||||
|
||||
using (Html.BeginFormAntiForgeryPost(Url.Action("MediaPost"))) {
|
||||
@Html.Hidden("url", Model.Url)
|
||||
@Html.Hidden("id", Model.Id)
|
||||
@Html.Hidden("folderPath", Model.FolderPath)
|
||||
@Html.Hidden("document", Model.Content.ToString())
|
||||
|
||||
<button type="submit">@("Import")</button>
|
||||
|
@ -5,4 +5,4 @@
|
||||
var mediaPart = ((ContentItem)Model.ContentItem).As<MediaPart>();
|
||||
}
|
||||
|
||||
<audio width="100%" src="@mediaPart.Resource" controls></audio>
|
||||
<audio width="100%" src="@mediaPart.MediaUrl" controls></audio>
|
||||
|
@ -5,4 +5,4 @@
|
||||
var mediaPart = ((ContentItem)Model.ContentItem).As<MediaPart>();
|
||||
}
|
||||
|
||||
<audio width="100%" src="@mediaPart.Resource" controls></audio>
|
||||
<audio width="100%" src="@mediaPart.MediaUrl" controls></audio>
|
||||
|
@ -5,4 +5,4 @@
|
||||
var mediaPart = ((ContentItem)Model.ContentItem).As<MediaPart>();
|
||||
}
|
||||
|
||||
<audio width="100%" src="@mediaPart.Resource" controls></audio>
|
||||
<audio width="100%" src="@mediaPart.MediaUrl" controls></audio>
|
||||
|
@ -5,7 +5,7 @@
|
||||
var mediaPart = ((ContentItem)Model.ContentItem).As<MediaPart>();
|
||||
}
|
||||
|
||||
<a href="@mediaPart.Resource">
|
||||
<a href="@mediaPart.MediaUrl">
|
||||
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAYCAYAAAD6S912AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjEwMPRyoQAAAN5JREFUSEvdlcENwyAMAIn64NkROkSePMoKzJERMgEzZMwoH1DkYhSiJDJgIvXRPk4Cy1xsS1bENE3Q9z2LYRjAOScAIIswxpCPc2itYVkWUoZE4ZYU7mSS9N6fPlyScoQiCZVSse2StEmIefM8wziOWWmzEPPWdRU5KVfYXfOC9E1Jb1WY4lSlTUJ8WMJaCywhwlkA9HCFz0B3ie0cR8KusMT/CiURi/x2y9m2SpSEry3pcThXCcJ917/eMvmgRq1CXLHjLNMdR5DGkM4xLwjlSUgt+h2isOU3WsNaCx9FtNaZP8PEygAAAABJRU5ErkJggg=="/>
|
||||
<span>@T("Download")</span>
|
||||
</a>
|
@ -5,7 +5,7 @@
|
||||
var mediaPart = ((ContentItem)Model.ContentItem).As<MediaPart>();
|
||||
}
|
||||
|
||||
<a href="@mediaPart.Resource">
|
||||
<a href="@mediaPart.MediaUrl">
|
||||
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAYCAYAAAD6S912AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjEwMPRyoQAAAN5JREFUSEvdlcENwyAMAIn64NkROkSePMoKzJERMgEzZMwoH1DkYhSiJDJgIvXRPk4Cy1xsS1bENE3Q9z2LYRjAOScAIIswxpCPc2itYVkWUoZE4ZYU7mSS9N6fPlyScoQiCZVSse2StEmIefM8wziOWWmzEPPWdRU5KVfYXfOC9E1Jb1WY4lSlTUJ8WMJaCywhwlkA9HCFz0B3ie0cR8KusMT/CiURi/x2y9m2SpSEry3pcThXCcJ917/eMvmgRq1CXLHjLNMdR5DGkM4xLwjlSUgt+h2isOU3WsNaCx9FtNaZP8PEygAAAABJRU5ErkJggg=="/>
|
||||
<span>@T("Download")</span>
|
||||
</a>
|
@ -5,7 +5,7 @@
|
||||
var mediaPart = ((ContentItem)Model.ContentItem).As<MediaPart>();
|
||||
}
|
||||
|
||||
<a href="@mediaPart.Resource">
|
||||
<a href="@mediaPart.MediaUrl">
|
||||
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAYCAYAAAD6S912AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjEwMPRyoQAAAN5JREFUSEvdlcENwyAMAIn64NkROkSePMoKzJERMgEzZMwoH1DkYhSiJDJgIvXRPk4Cy1xsS1bENE3Q9z2LYRjAOScAIIswxpCPc2itYVkWUoZE4ZYU7mSS9N6fPlyScoQiCZVSse2StEmIefM8wziOWWmzEPPWdRU5KVfYXfOC9E1Jb1WY4lSlTUJ8WMJaCywhwlkA9HCFz0B3ie0cR8KusMT/CiURi/x2y9m2SpSEry3pcThXCcJ917/eMvmgRq1CXLHjLNMdR5DGkM4xLwjlSUgt+h2isOU3WsNaCx9FtNaZP8PEygAAAABJRU5ErkJggg=="/>
|
||||
<span>@T("Download")</span>
|
||||
</a>
|
@ -6,7 +6,7 @@
|
||||
}
|
||||
|
||||
@* Use a 200x200 profile in order to reuse the general thumbnail *@
|
||||
<a href="@Url.Content(mediaPart.Resource)">
|
||||
<img width="200" height="200" alt="@mediaPart.AlternateText" src="@Display.ResizeMediaUrl(Width: 200, Height: 200, Mode: "crop", Alignment: "middlecenter", Path: mediaPart.Resource)" />
|
||||
<a href="@Url.Content(mediaPart.MediaUrl)">
|
||||
<img width="200" height="200" alt="@mediaPart.AlternateText" src="@Display.ResizeMediaUrl(Width: 200, Height: 200, Mode: "crop", Alignment: "middlecenter", Path: mediaPart.MediaUrl)" />
|
||||
</a>
|
||||
|
||||
|
@ -6,5 +6,5 @@
|
||||
}
|
||||
|
||||
@* Use a 200x200 profile in order to reuse the general thumbnail *@
|
||||
<img width="120" height="120" alt="@mediaPart.AlternateText" src="@Display.ResizeMediaUrl(Width: 200, Height: 200, Mode: "crop", Alignment: "middlecenter", Path: mediaPart.Resource)" />
|
||||
<img width="120" height="120" alt="@mediaPart.AlternateText" src="@Display.ResizeMediaUrl(Width: 200, Height: 200, Mode: "crop", Alignment: "middlecenter", Path: mediaPart.MediaUrl)" />
|
||||
|
||||
|
@ -5,5 +5,5 @@
|
||||
var mediaPart = ((ContentItem)Model.ContentItem).As<MediaPart>();
|
||||
}
|
||||
|
||||
<img width="@imagePart.Width" height="@imagePart.Height" alt="@mediaPart.AlternateText" src="@Url.Content(mediaPart.Resource)" />
|
||||
<img width="@imagePart.Width" height="@imagePart.Height" alt="@mediaPart.AlternateText" src="@Url.Content(mediaPart.MediaUrl)" />
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
</div>
|
||||
<div class="file-name">
|
||||
<em>@T("Filename:")</em>
|
||||
<span>@Path.GetFileName(mediaPart.Resource)</span>
|
||||
<span>@Path.GetFileName(mediaPart.MediaUrl)</span>
|
||||
</div>
|
||||
<div class="mime-type">
|
||||
<em>@T("Mime Type:")</em>
|
||||
|
@ -5,6 +5,6 @@
|
||||
var mediaPart = ((ContentItem)Model.ContentItem).As<MediaPart>();
|
||||
}
|
||||
|
||||
<a href="@mediaPart.Resource" target="_blank" class="button">
|
||||
<a href="@mediaPart.MediaUrl" target="_blank" class="button">
|
||||
<span>@T("Preview")</span>
|
||||
</a>
|
@ -5,6 +5,6 @@
|
||||
var mediaPart = ((ContentItem)Model.ContentItem).As<MediaPart>();
|
||||
}
|
||||
|
||||
<a href="@mediaPart.Resource" target="_blank" class="button">
|
||||
<a href="@mediaPart.MediaUrl" target="_blank" class="button">
|
||||
<span>@T("Preview")</span>
|
||||
</a>
|
||||
|
@ -5,4 +5,4 @@
|
||||
var mediaPart = ((ContentItem)Model.ContentItem).As<MediaPart>();
|
||||
}
|
||||
|
||||
<video width="100%" height="160px" src="@mediaPart.Resource" controls></video>
|
||||
<video width="100%" height="160px" src="@mediaPart.MediaUrl" controls></video>
|
||||
|
@ -5,4 +5,4 @@
|
||||
var mediaPart = ((ContentItem)Model.ContentItem).As<MediaPart>();
|
||||
}
|
||||
|
||||
<video width="100%" height="160px" src="@mediaPart.Resource" controls></video>
|
||||
<video width="100%" height="160px" src="@mediaPart.MediaUrl" controls></video>
|
||||
|
@ -5,4 +5,4 @@
|
||||
var mediaPart = ((ContentItem)Model.ContentItem).As<MediaPart>();
|
||||
}
|
||||
|
||||
<video width="100%" height="160px" src="@mediaPart.Resource" controls></video>
|
||||
<video width="100%" height="160px" src="@mediaPart.MediaUrl" controls></video>
|
||||
|
@ -1,7 +1,6 @@
|
||||
@using System.Text
|
||||
@using Orchard.ContentManagement
|
||||
@using Orchard.MediaLibrary.Models
|
||||
@using Orchard.UI.Notify
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
@ -84,7 +83,7 @@
|
||||
|
||||
@Html.Hidden("antiforgerytoken", Html.AntiForgeryTokenValueOrchard())
|
||||
@Html.Hidden("action", Url.Action("ImagePost"))
|
||||
@Html.Hidden("id", (int)Model)
|
||||
@Html.Hidden("folderPath", (string)Model)
|
||||
|
||||
@using(Script.Foot()) {
|
||||
<script type="text/javascript">
|
||||
|
@ -6,4 +6,4 @@ Version: 1.7
|
||||
OrchardVersion: 1.7
|
||||
Description: Module for processing Media e.g. image resizing
|
||||
Category: Media
|
||||
Dependencies: Orchard.Media, Orchard.Forms
|
||||
Dependencies: Orchard.Forms
|
@ -90,10 +90,6 @@
|
||||
<Project>{642A49D7-8752-4177-80D6-BFBBCFAD3DE0}</Project>
|
||||
<Name>Orchard.Forms</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Media\Orchard.Media.csproj">
|
||||
<Project>{D9A7B330-CD22-4DA1-A95A-8DE1982AD8EB}</Project>
|
||||
<Name>Orchard.Media</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Tokens\Orchard.Tokens.csproj">
|
||||
<Project>{6f759635-13d7-4e94-bcc9-80445d63f117}</Project>
|
||||
<Name>Orchard.Tokens</Name>
|
||||
|
@ -5,7 +5,6 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Web;
|
||||
using System.Web.Hosting;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Environment;
|
||||
@ -126,12 +125,13 @@ namespace Orchard.MediaProcessing.Shapes {
|
||||
}
|
||||
else {
|
||||
profilePart = services.Value.ContentManager.New<ImageProfilePart>("ImageProfile");
|
||||
profilePart.Name = Profile;
|
||||
profilePart.Filters.Add(CustomFilter);
|
||||
}
|
||||
|
||||
using (var image = GetImage(Path)) {
|
||||
|
||||
var filterContext = new FilterContext { Media = image, FilePath = storageProvider.Value.Combine(Profile, CreateDefaultFileName(Path)) };
|
||||
|
||||
var filterContext = new FilterContext { Media = image, FilePath = storageProvider.Value.Combine("_Profiles", storageProvider.Value.Combine(Profile, CreateDefaultFileName(Path))) };
|
||||
|
||||
var tokens = new Dictionary<string, object>();
|
||||
// if a content item is provided, use it while tokenizing
|
||||
@ -152,7 +152,7 @@ namespace Orchard.MediaProcessing.Shapes {
|
||||
_fileNameProvider.Value.UpdateFileName(Profile, Path, filterContext.FilePath);
|
||||
|
||||
if (!filterContext.Saved) {
|
||||
storageProvider.Value.TryCreateFolder(profilePart.Name);
|
||||
storageProvider.Value.TryCreateFolder(storageProvider.Value.Combine("_Profiles", profilePart.Name));
|
||||
var newFile = storageProvider.Value.OpenOrCreate(filterContext.FilePath);
|
||||
using (var imageStream = newFile.OpenWrite()) {
|
||||
using (var sw = new BinaryWriter(imageStream)) {
|
||||
@ -177,7 +177,7 @@ namespace Orchard.MediaProcessing.Shapes {
|
||||
|
||||
// generate a timestamped url to force client caches to update if the file has changed
|
||||
var publicUrl = storageProvider.Value.GetPublicUrl(filePath);
|
||||
var timestamp = storageProvider.Value.GetFile(storageProvider.Value.GetLocalPath(filePath)).GetLastUpdated().Ticks;
|
||||
var timestamp = storageProvider.Value.GetFile(filePath).GetLastUpdated().Ticks;
|
||||
Output.Write(publicUrl + "?v=" + timestamp.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
@ -185,84 +185,39 @@ namespace Orchard.MediaProcessing.Shapes {
|
||||
}
|
||||
}
|
||||
|
||||
private enum ImagePathType
|
||||
{
|
||||
StorageProvider,
|
||||
AbsoluteUrl,
|
||||
AppRelative,
|
||||
Invalid
|
||||
}
|
||||
// TODO: Update this method once the storage provider has been updated
|
||||
private Stream GetImage(string path) {
|
||||
var request = _services.Value.WorkContext.HttpContext.Request;
|
||||
|
||||
private ImagePathType GetImagePathType(string path) {
|
||||
// /OrchardLocal/images/my-image.jpg
|
||||
if (Uri.IsWellFormedUriString(path, UriKind.Relative)) {
|
||||
return ImagePathType.StorageProvider;
|
||||
var storagePath = _storageProvider.Value.GetStoragePath(path);
|
||||
if (storagePath != null) {
|
||||
var file = _storageProvider.Value.GetFile(storagePath);
|
||||
return file.OpenRead();
|
||||
}
|
||||
|
||||
// http://blob.storage-provider.net/my-image.jpg
|
||||
if (Uri.IsWellFormedUriString(path, UriKind.Absolute)) {
|
||||
return ImagePathType.AbsoluteUrl;
|
||||
return new WebClient().OpenRead(new Uri(path));
|
||||
}
|
||||
|
||||
// ~/Media/Default/images/my-image.jpg
|
||||
if (VirtualPathUtility.IsAppRelative(path)) {
|
||||
return ImagePathType.AppRelative;
|
||||
return new WebClient().OpenRead(new Uri(request.Url, VirtualPathUtility.ToAbsolute(path)));
|
||||
}
|
||||
|
||||
return ImagePathType.Invalid;
|
||||
}
|
||||
|
||||
// TODO: Update this method once the storage provider has been updated
|
||||
private Stream GetImage(string path) {
|
||||
var storageProvider = new Lazy<IStorageProvider>(() => _storageProvider.Value);
|
||||
var services = new Lazy<IOrchardServices>(() => _services.Value);
|
||||
var webClient = new Lazy<WebClient>(() => new WebClient());
|
||||
|
||||
var request = services.Value.WorkContext.HttpContext.Request;
|
||||
|
||||
switch (GetImagePathType(path)) {
|
||||
case ImagePathType.StorageProvider:
|
||||
path = storageProvider.Value.GetLocalPath(path);
|
||||
|
||||
// images/my-image.jpg
|
||||
var file = storageProvider.Value.GetFile(path);
|
||||
return file.OpenRead();
|
||||
|
||||
case ImagePathType.AbsoluteUrl:
|
||||
return webClient.Value.OpenRead(new Uri(path));
|
||||
|
||||
case ImagePathType.AppRelative:
|
||||
return webClient.Value.OpenRead(new Uri(request.Url, VirtualPathUtility.ToAbsolute(path)));
|
||||
|
||||
default:
|
||||
throw new ArgumentException("invalid path");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool TryGetImageLastUpdated(string path, out DateTime lastUpdated) {
|
||||
var imagePathType = GetImagePathType(path);
|
||||
switch (imagePathType)
|
||||
{
|
||||
case ImagePathType.StorageProvider:
|
||||
path = _storageProvider.Value.GetLocalPath(path);
|
||||
|
||||
var file = _storageProvider.Value.GetFile(path);
|
||||
lastUpdated = file.GetLastUpdated();
|
||||
|
||||
return true;
|
||||
|
||||
case ImagePathType.AppRelative:
|
||||
var serverPath = HostingEnvironment.MapPath(path);
|
||||
lastUpdated = File.GetLastWriteTime(serverPath);
|
||||
|
||||
return true;
|
||||
|
||||
default:
|
||||
Logger.Warning("Cannot get last updated time for {0}, {1}", imagePathType, path);
|
||||
|
||||
lastUpdated = DateTime.MinValue;
|
||||
return false;
|
||||
var storagePath = _storageProvider.Value.GetStoragePath(path);
|
||||
if (storagePath != null) {
|
||||
var file = _storageProvider.Value.GetFile(storagePath);
|
||||
lastUpdated = file.GetLastUpdated();
|
||||
return true;
|
||||
}
|
||||
|
||||
lastUpdated = DateTime.MinValue;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static string CreateDefaultFileName(string path) {
|
||||
|
@ -1,43 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Orchard;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.FileSystems.Media;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Media.Models;
|
||||
using Orchard.Media.Services;
|
||||
using Orchard.MediaLibrary.Models;
|
||||
using Orchard.MediaLibrary.Services;
|
||||
using Orchard.Security;
|
||||
using Orchard.UI.Admin;
|
||||
using Orchard.UI.Notify;
|
||||
using MediaFolder = Orchard.Media.Models.MediaFolder;
|
||||
|
||||
namespace Upgrade.Controllers {
|
||||
[Admin]
|
||||
public class MediaController : Controller {
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
private readonly IFeatureManager _featureManager;
|
||||
private readonly IMediaService _mediaService;
|
||||
private readonly IMediaLibraryService _mediaLibraryService;
|
||||
private readonly IStorageProvider _storageProvider;
|
||||
|
||||
public MediaController(
|
||||
IOrchardServices orchardServices,
|
||||
IFeatureManager featureManager,
|
||||
IMediaService mediaService,
|
||||
IMediaLibraryService mediaLibraryService,
|
||||
IStorageProvider storageProvider) {
|
||||
IMediaLibraryService mediaLibraryService) {
|
||||
_orchardServices = orchardServices;
|
||||
_featureManager = featureManager;
|
||||
_mediaService = mediaService;
|
||||
_mediaLibraryService = mediaLibraryService;
|
||||
_storageProvider = storageProvider;
|
||||
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
@ -58,10 +46,10 @@ namespace Upgrade.Controllers {
|
||||
if (!_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to convert media files.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
// crawl media file, ignore recipes
|
||||
IEnumerable<MediaFolder> mediaFolders = _mediaService.GetMediaFolders(null);
|
||||
// crawl media file, ignore recipes and profiles
|
||||
IEnumerable<MediaFolder> mediaFolders = _mediaLibraryService.GetMediaFolders(null);
|
||||
foreach (var mediaFolder in mediaFolders) {
|
||||
ImportMediaFolder(mediaFolder, null);
|
||||
ImportMediaFolder(mediaFolder);
|
||||
}
|
||||
|
||||
_orchardServices.Notifier.Information(T("Media files were migrated successfully."));
|
||||
@ -69,54 +57,22 @@ namespace Upgrade.Controllers {
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
private void ImportMediaFolder(MediaFolder mediaFolder, Orchard.MediaLibrary.Models.MediaFolder parentMediaFolder) {
|
||||
// create the folder in Media Library
|
||||
|
||||
int? parentMediaFolderId = parentMediaFolder != null ? (int?)parentMediaFolder.TermId : null;
|
||||
Orchard.MediaLibrary.Models.MediaFolder mediaLibraryFolder = null;
|
||||
|
||||
var candidateFolders = Enumerable.Empty<Orchard.MediaLibrary.Models.MediaFolder>();
|
||||
|
||||
if (parentMediaFolderId.HasValue) {
|
||||
var parentMediaFolderTerm = _mediaLibraryService.GetMediaFolder(parentMediaFolderId.Value);
|
||||
if (parentMediaFolderTerm != null) {
|
||||
candidateFolders = parentMediaFolderTerm.Folders;
|
||||
}
|
||||
}
|
||||
else {
|
||||
candidateFolders = _mediaLibraryService.GetMediaFolders();
|
||||
}
|
||||
|
||||
var match = candidateFolders.FirstOrDefault(x => x.Name.Equals(mediaFolder.Name, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
// if we find an existing term reuse it
|
||||
if (match != null) {
|
||||
mediaLibraryFolder = match;
|
||||
}
|
||||
else {
|
||||
mediaLibraryFolder = _mediaLibraryService.CreateFolder(parentMediaFolderId, mediaFolder.Name);
|
||||
}
|
||||
|
||||
foreach (var mediaFile in _mediaService.GetMediaFiles(mediaFolder.MediaPath)) {
|
||||
ImportMediaFile(mediaFile, mediaLibraryFolder);
|
||||
private void ImportMediaFolder(MediaFolder mediaFolder) {
|
||||
foreach (var mediaFile in _mediaLibraryService.GetMediaFiles(mediaFolder.MediaPath)) {
|
||||
ImportMediaFile(mediaFile);
|
||||
}
|
||||
|
||||
// recursive call on sub-folders
|
||||
foreach (var subMediaFolder in _mediaService.GetMediaFolders(mediaFolder.MediaPath)) {
|
||||
ImportMediaFolder(subMediaFolder, mediaLibraryFolder);
|
||||
foreach (var subMediaFolder in _mediaLibraryService.GetMediaFolders(mediaFolder.MediaPath)) {
|
||||
ImportMediaFolder(subMediaFolder);
|
||||
}
|
||||
}
|
||||
|
||||
private void ImportMediaFile(MediaFile mediaFile, Orchard.MediaLibrary.Models.MediaFolder mediaLibraryFolder) {
|
||||
private void ImportMediaFile(MediaFile mediaFile) {
|
||||
// foreach media file, if there is no media with the same url, import it
|
||||
|
||||
var prefix = _mediaService.GetPublicUrl("foo.$$$");
|
||||
var trim = prefix.IndexOf("foo.$$$");
|
||||
var canonicalFileName = mediaFile.MediaPath.Substring(trim);
|
||||
var fileName = Path.GetFileName(canonicalFileName);
|
||||
|
||||
var contentManager = _orchardServices.ContentManager;
|
||||
var media = contentManager.Query().ForPart<MediaPart>().Where<MediaPartRecord>(x => x.Resource.EndsWith("/" + fileName)).Slice(0, 1).FirstOrDefault();
|
||||
var media = contentManager.Query().ForPart<MediaPart>().Where<MediaPartRecord>(x => x.FolderPath == mediaFile.FolderName && x.FileName == mediaFile.Name).Slice(0, 1).FirstOrDefault();
|
||||
|
||||
if (media != null) {
|
||||
_orchardServices.Notifier.Warning(T("Media {0} has already been imported.", mediaFile.MediaPath));
|
||||
@ -125,12 +81,7 @@ namespace Upgrade.Controllers {
|
||||
|
||||
try {
|
||||
_orchardServices.Notifier.Information(T("Importing {0}.", mediaFile.MediaPath));
|
||||
var storageFile = _storageProvider.GetFile(canonicalFileName);
|
||||
|
||||
using (var stream = storageFile.OpenRead()) {
|
||||
var filename = HttpUtility.UrlDecode(mediaFile.MediaPath);
|
||||
_mediaLibraryService.ImportStream(mediaLibraryFolder.TermId, stream, Path.GetFileName(filename));
|
||||
}
|
||||
_mediaLibraryService.ImportMedia(mediaFile.FolderName, mediaFile.Name);
|
||||
}
|
||||
catch(Exception e) {
|
||||
_orchardServices.Notifier.Error(T("Error while importing {0}. Please check the logs", mediaFile.MediaPath));
|
||||
|
@ -96,10 +96,6 @@
|
||||
<Project>{73a7688a-5bd3-4f7e-adfa-ce36c5a10e3b}</Project>
|
||||
<Name>Orchard.MediaLibrary</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Media\Orchard.Media.csproj">
|
||||
<Project>{d9a7b330-cd22-4da1-a95a-8de1982ad8eb}</Project>
|
||||
<Name>Orchard.Media</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Widgets\Orchard.Widgets.csproj">
|
||||
<Project>{194D3CCC-1153-474D-8176-FDE8D7D0D0BD}</Project>
|
||||
<Name>Orchard.Widgets</Name>
|
||||
|
@ -9,9 +9,9 @@ using Orchard.Validation;
|
||||
|
||||
namespace Orchard.FileSystems.Media {
|
||||
public class FileSystemStorageProvider : IStorageProvider {
|
||||
private readonly string _storagePath;
|
||||
private readonly string _publicPath;
|
||||
private readonly string _relativePath;
|
||||
private readonly string _storagePath; // c:\orchard\media\default
|
||||
private readonly string _virtualPath; // ~/Media/Default/
|
||||
private readonly string _publicPath; // /Orchard/Media/Default/
|
||||
|
||||
public FileSystemStorageProvider(ShellSettings settings) {
|
||||
var mediaPath = HostingEnvironment.IsHosted
|
||||
@ -19,6 +19,7 @@ namespace Orchard.FileSystems.Media {
|
||||
: Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Media");
|
||||
|
||||
_storagePath = Path.Combine(mediaPath, settings.Name);
|
||||
_virtualPath = "~/Media/" + settings.Name + "/";
|
||||
|
||||
var appPath = "";
|
||||
if (HostingEnvironment.IsHosted) {
|
||||
@ -29,7 +30,6 @@ namespace Orchard.FileSystems.Media {
|
||||
if (!appPath.StartsWith("/"))
|
||||
appPath = '/' + appPath;
|
||||
|
||||
_relativePath = "~/Media/" + settings.Name + "/";
|
||||
_publicPath = appPath + "Media/" + settings.Name + "/";
|
||||
|
||||
T = NullLocalizer.Instance;
|
||||
@ -53,7 +53,7 @@ namespace Orchard.FileSystems.Media {
|
||||
/// <param name="path">The relative path to be mapped.</param>
|
||||
/// <returns>The relative path combined with the public path in an URL friendly format ('/' character for directory separator).</returns>
|
||||
private string MapPublic(string path) {
|
||||
return string.IsNullOrEmpty(path) ? _publicPath : Path.Combine(_publicPath, path).Replace(Path.DirectorySeparatorChar, '/');
|
||||
return string.IsNullOrEmpty(path) ? _publicPath : Path.Combine(_publicPath, path).Replace(Path.DirectorySeparatorChar, '/').Replace(" ", "%20");
|
||||
}
|
||||
|
||||
private static string Fix(string path) {
|
||||
@ -84,25 +84,21 @@ namespace Orchard.FileSystems.Media {
|
||||
return MapPublic(path);
|
||||
}
|
||||
|
||||
public string GetRelativePath(string path) {
|
||||
return (_relativePath + path).Replace(Path.DirectorySeparatorChar, '/');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the local path for a given url within the storage provider.
|
||||
/// Retrieves the path within the storage provider for a given public url.
|
||||
/// </summary>
|
||||
/// <param name="url">The public url of the media.</param>
|
||||
/// <returns>The local path.</returns>
|
||||
public string GetLocalPath(string url) {
|
||||
if (url.StartsWith(_relativePath)) {
|
||||
return url.Substring(_relativePath.Length);
|
||||
/// <param name="url">The virtual or public url of a media.</param>
|
||||
/// <returns>The storage path or <value>null</value> if the media is not in a correct format.</returns>
|
||||
public string GetStoragePath(string url) {
|
||||
if (url.StartsWith(_virtualPath)) {
|
||||
return url.Substring(_virtualPath.Length).Replace('/', Path.DirectorySeparatorChar).Replace("%20", " ");
|
||||
}
|
||||
|
||||
if (!url.StartsWith(_publicPath)) {
|
||||
return url;
|
||||
if (url.StartsWith(_publicPath)) {
|
||||
return url.Substring(_publicPath.Length).Replace('/', Path.DirectorySeparatorChar).Replace("%20", " "); ;
|
||||
}
|
||||
|
||||
return Combine("", url.Substring(_publicPath.Length));
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -19,18 +19,12 @@ namespace Orchard.FileSystems.Media {
|
||||
string GetPublicUrl(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the local path for a given url within the storage provider.
|
||||
/// Retrieves the path within the storage provider for a given public url.
|
||||
/// </summary>
|
||||
/// <param name="url">The public url of the media.</param>
|
||||
/// <returns>The local path.</returns>
|
||||
string GetLocalPath(string url);
|
||||
/// <param name="url">The virtual or public url of a media.</param>
|
||||
/// <returns>The storage path or <value>null</value> if the media is not in a correct format.</returns>
|
||||
string GetStoragePath(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>
|
||||
/// Retrieves a file within the storage provider.
|
||||
|
Loading…
Reference in New Issue
Block a user