mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-25 10:59:18 +08:00
Work Items: 18061, 18106 --HG-- branch : 1.x
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using System.Xml.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Core.XmlRpc;
|
||||
using Orchard.Core.XmlRpc.Models;
|
||||
using Orchard.Mvc.Extensions;
|
||||
using Orchard.Utility.Extensions;
|
||||
using Orchard.Security;
|
||||
|
||||
namespace Orchard.Media.Services {
|
||||
@@ -12,14 +16,17 @@ namespace Orchard.Media.Services {
|
||||
private readonly IMembershipService _membershipService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IMediaService _mediaService;
|
||||
private readonly RouteCollection _routeCollection;
|
||||
|
||||
public XmlRpcHandler(
|
||||
IMembershipService membershipService,
|
||||
IAuthorizationService authorizationService,
|
||||
IMediaService mediaService) {
|
||||
IMediaService mediaService,
|
||||
RouteCollection routeCollection) {
|
||||
_membershipService = membershipService;
|
||||
_authorizationService = authorizationService;
|
||||
_mediaService = mediaService;
|
||||
_routeCollection = routeCollection;
|
||||
}
|
||||
|
||||
public void SetCapabilities(XElement options) {
|
||||
@@ -28,11 +35,14 @@ namespace Orchard.Media.Services {
|
||||
}
|
||||
|
||||
public void Process(XmlRpcContext context) {
|
||||
var urlHelper = new UrlHelper(context.ControllerContext.RequestContext, _routeCollection);
|
||||
|
||||
if (context.Request.MethodName == "metaWeblog.newMediaObject") {
|
||||
var result = MetaWeblogNewMediaObject(
|
||||
Convert.ToString(context.Request.Params[1].Value),
|
||||
Convert.ToString(context.Request.Params[2].Value),
|
||||
(XRpcStruct)context.Request.Params[3].Value);
|
||||
(XRpcStruct)context.Request.Params[3].Value,
|
||||
urlHelper);
|
||||
context.Response = new XRpcMethodResponse().Add(result);
|
||||
}
|
||||
}
|
||||
@@ -40,7 +50,8 @@ namespace Orchard.Media.Services {
|
||||
private XRpcStruct MetaWeblogNewMediaObject(
|
||||
string userName,
|
||||
string password,
|
||||
XRpcStruct file) {
|
||||
XRpcStruct file,
|
||||
UrlHelper url) {
|
||||
|
||||
var user = _membershipService.ValidateUser(userName, password);
|
||||
if (!_authorizationService.TryCheckAccess(Permissions.ManageMedia, user, null)) {
|
||||
@@ -52,7 +63,7 @@ namespace Orchard.Media.Services {
|
||||
var bits = file.Optional<byte[]>("bits");
|
||||
|
||||
string publicUrl = _mediaService.UploadMediaFile(Path.GetDirectoryName(name), Path.GetFileName(name), bits, true);
|
||||
return new XRpcStruct().Set("url", publicUrl);
|
||||
return new XRpcStruct().Set("url", url.MakeAbsolute(publicUrl));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user