mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-25 10:59:18 +08:00
@@ -1,22 +1,25 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Xml.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Core.XmlRpc;
|
||||
using Orchard.Core.XmlRpc.Models;
|
||||
using Orchard.Security;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.Media.Services {
|
||||
[UsedImplicitly]
|
||||
public class XmlRpcHandler : IXmlRpcHandler {
|
||||
private readonly IMembershipService _membershipService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IMediaService _mediaService;
|
||||
|
||||
public XmlRpcHandler(IMembershipService membershipService, IAuthorizationService authorizationService) {
|
||||
public XmlRpcHandler(
|
||||
IMembershipService membershipService,
|
||||
IAuthorizationService authorizationService,
|
||||
IMediaService mediaService) {
|
||||
_membershipService = membershipService;
|
||||
_authorizationService = authorizationService;
|
||||
_mediaService = mediaService;
|
||||
}
|
||||
|
||||
public void SetCapabilities(XElement options) {
|
||||
@@ -25,15 +28,8 @@ namespace Orchard.Media.Services {
|
||||
}
|
||||
|
||||
public void Process(XmlRpcContext context) {
|
||||
var uriBuilder = new UriBuilder(context.HttpContext.Request.ToUrlString()) {
|
||||
Path = context.HttpContext.Request.ApplicationPath,
|
||||
Query = string.Empty
|
||||
};
|
||||
|
||||
if (context.Request.MethodName == "metaWeblog.newMediaObject") {
|
||||
var result = MetaWeblogNewMediaObject(
|
||||
uriBuilder,
|
||||
Convert.ToString(context.Request.Params[0].Value),
|
||||
Convert.ToString(context.Request.Params[1].Value),
|
||||
Convert.ToString(context.Request.Params[2].Value),
|
||||
(XRpcStruct)context.Request.Params[3].Value);
|
||||
@@ -42,8 +38,6 @@ namespace Orchard.Media.Services {
|
||||
}
|
||||
|
||||
private XRpcStruct MetaWeblogNewMediaObject(
|
||||
UriBuilder uriBuilder,
|
||||
string blogId,
|
||||
string userName,
|
||||
string password,
|
||||
XRpcStruct file) {
|
||||
@@ -57,14 +51,8 @@ namespace Orchard.Media.Services {
|
||||
var name = file.Optional<string>("name");
|
||||
var bits = file.Optional<byte[]>("bits");
|
||||
|
||||
var target = HttpContext.Current.Server.MapPath("~/Media/" + name);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(target));
|
||||
using (var stream = new FileStream(target, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)) {
|
||||
stream.Write(bits, 0, bits.Length);
|
||||
}
|
||||
|
||||
uriBuilder.Path = uriBuilder.Path.TrimEnd('/') + "/Media/" + name.TrimStart('/');
|
||||
return new XRpcStruct().Set("url", uriBuilder.Uri.AbsoluteUri);
|
||||
string publicUrl = _mediaService.UploadMediaFile(Path.GetDirectoryName(name), Path.GetFileName(name), bits, true);
|
||||
return new XRpcStruct().Set("url", publicUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user