Files
juipnet/Services/Hncore.Pass.OSS/UEditor/UEditorService.cs
“wanyongkang” b562aba2b1 忽略dll文件git
2023-07-29 10:19:42 +08:00

97 lines
3.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#if NETSTANDARD2_0
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
#endif
#if NET35
using System.Web;
#endif
using Hncore.Pass.Vpn.Service;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using System;
using UEditor.Core.Handlers;
namespace UEditor.Core
{
public class UEditorService
{
UploadService m_UploadService;
public UEditorService(IHostingEnvironment env,UploadService uploadService)
{
// .net core的名字起的比较怪而已并不是我赋值赋错了
if (string.IsNullOrWhiteSpace(Config.WebRootPath))
{
Config.WebRootPath = env.ContentRootPath;
}
Config.EnvName = env.EnvironmentName;
m_UploadService = uploadService;
}
/// <summary>
/// 上传并返回结果已处理跨域Jsonp请求
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public UEditorResponse UploadAndGetResponse(HttpContext context)
{
var action = context.Request.Query["action"];
object result;
if (AppConsts.Action.Config.Equals(action, StringComparison.OrdinalIgnoreCase))
{
var configHandle = new ConfigHandler();
result = configHandle.Process();
}
else
{
var handle = HandelFactory.GetHandler(action, context, m_UploadService);
result = handle.Process();
}
string resultJson = JsonConvert.SerializeObject(result, new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
});
string contentType = "text/plain";
string jsonpCallback = context.Request.Query["callback"];
if (!jsonpCallback.IsNullOrWhiteSpace())
{
contentType = "application/javascript";
resultJson = string.Format("{0}({1});", jsonpCallback, resultJson);
UEditorResponse response = new UEditorResponse(contentType, resultJson);
return response;
}
else
{
UEditorResponse response = new UEditorResponse(contentType, resultJson);
return response;
}
}
/// <summary>
/// 单纯的上传并返回结果未处理跨域Jsonp请求
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public object Upload(HttpContext context)
{
var action = context.Request.Query["action"];
object result;
if (AppConsts.Action.Config.Equals(action, StringComparison.OrdinalIgnoreCase))
{
result = new ConfigHandler();
}
else
{
var handle = HandelFactory.GetHandler(action, context, m_UploadService);
result = handle.Process();
}
return result;
}
}
}