mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-26 20:16:15 +08:00
Work Items: 18166, 17789 --HG-- branch : 1.x
This commit is contained in:
@@ -6,8 +6,8 @@ using System.Xml.Linq;
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Orchard.Core.XmlRpc;
|
using Orchard.Core.XmlRpc;
|
||||||
using Orchard.Core.XmlRpc.Models;
|
using Orchard.Core.XmlRpc.Models;
|
||||||
|
using Orchard.Localization;
|
||||||
using Orchard.Mvc.Extensions;
|
using Orchard.Mvc.Extensions;
|
||||||
using Orchard.Utility.Extensions;
|
|
||||||
using Orchard.Security;
|
using Orchard.Security;
|
||||||
|
|
||||||
namespace Orchard.Media.Services {
|
namespace Orchard.Media.Services {
|
||||||
@@ -27,8 +27,12 @@ namespace Orchard.Media.Services {
|
|||||||
_authorizationService = authorizationService;
|
_authorizationService = authorizationService;
|
||||||
_mediaService = mediaService;
|
_mediaService = mediaService;
|
||||||
_routeCollection = routeCollection;
|
_routeCollection = routeCollection;
|
||||||
|
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
public void SetCapabilities(XElement options) {
|
public void SetCapabilities(XElement options) {
|
||||||
const string manifestUri = "http://schemas.microsoft.com/wlw/manifest/weblog";
|
const string manifestUri = "http://schemas.microsoft.com/wlw/manifest/weblog";
|
||||||
options.SetElementValue(XName.Get("supportsFileUpload", manifestUri), "Yes");
|
options.SetElementValue(XName.Get("supportsFileUpload", manifestUri), "Yes");
|
||||||
@@ -55,14 +59,22 @@ namespace Orchard.Media.Services {
|
|||||||
|
|
||||||
var user = _membershipService.ValidateUser(userName, password);
|
var user = _membershipService.ValidateUser(userName, password);
|
||||||
if (!_authorizationService.TryCheckAccess(Permissions.ManageMedia, user, null)) {
|
if (!_authorizationService.TryCheckAccess(Permissions.ManageMedia, user, null)) {
|
||||||
//TEMP: return appropriate access-denied response for user
|
throw new OrchardCoreException(T("Access denied"));
|
||||||
throw new ApplicationException("Access denied");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var name = file.Optional<string>("name");
|
var name = file.Optional<string>("name");
|
||||||
var bits = file.Optional<byte[]>("bits");
|
var bits = file.Optional<byte[]>("bits");
|
||||||
|
|
||||||
string publicUrl = _mediaService.UploadMediaFile(Path.GetDirectoryName(name), Path.GetFileName(name), bits, true);
|
try {
|
||||||
|
// delete the file if it already exists, e.g. and updated image in a blog post
|
||||||
|
// it's safe to delete the file as each content item gets a specific folder
|
||||||
|
_mediaService.DeleteFile(Path.GetDirectoryName(name), Path.GetFileName(name));
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
// current way to delete a file if it exists
|
||||||
|
}
|
||||||
|
|
||||||
|
string publicUrl = _mediaService.UploadMediaFile(Path.GetDirectoryName(name), Path.GetFileName(name), bits, false);
|
||||||
return new XRpcStruct().Set("url", url.MakeAbsolute(publicUrl));
|
return new XRpcStruct().Set("url", url.MakeAbsolute(publicUrl));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user