忽略dll文件git
This commit is contained in:
@@ -1,131 +1,131 @@
|
||||
using Hncore.Infrastructure.EntitiesExtension;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Vpn.Service;
|
||||
using Hncore.Pass.OSS.Domain;
|
||||
using Hncore.Pass.OSS.Request;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.OSS.Controllers
|
||||
{
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/oss/v{version:apiVersion}/asset/[action]")]
|
||||
public class AssetController : HncoreControllerBase
|
||||
{
|
||||
AssetGroupService m_AssetGroupService;
|
||||
AssetService m_AssetService;
|
||||
public AssetController(AssetGroupService assetGroupService, AssetService _AssetService)
|
||||
{
|
||||
m_AssetGroupService = assetGroupService;
|
||||
m_AssetService = _AssetService;
|
||||
}
|
||||
|
||||
#region group
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> AddGroup([FromBody] PostGroupRequest request)
|
||||
{
|
||||
var entity = request.MapTo<AssetGroup>();
|
||||
entity.TenantId = this.Request.GetManageUserInfo().TenantId;
|
||||
await m_AssetGroupService.Add(entity);
|
||||
return Success();
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> UpdateGroup([FromBody] PostGroupRequest request)
|
||||
{
|
||||
var enitty = await m_AssetGroupService.GetById(request.Id);
|
||||
enitty.Name = request.Name;
|
||||
enitty.TenantId = this.Request.GetManageUserInfo().TenantId;
|
||||
await m_AssetGroupService.Update(enitty);
|
||||
return Success();
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> DeleteGroup([FromQuery] int id)
|
||||
{
|
||||
await m_AssetGroupService.DeleteById(id);
|
||||
return Success();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> GetGroups([FromQuery] int groupType)
|
||||
{
|
||||
var enitty = await m_AssetGroupService.Query(m => m.GroupType == groupType, true).ToListAsync();
|
||||
return Success(enitty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 添加
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Post([FromBody]PostAssetRequest request)
|
||||
{
|
||||
var entity = request.MapTo<Asset>();
|
||||
entity.TenantId = this.Request.GetManageUserInfo().TenantId;
|
||||
await m_AssetService.Add(entity);
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Put([FromBody]PostAssetRequest request)
|
||||
{
|
||||
var entity = await m_AssetService.GetById(request.Id);
|
||||
if (entity == null)
|
||||
return Error("资源不存在");
|
||||
if (request.Name.Has())
|
||||
{
|
||||
entity.Name = request.Name;
|
||||
}
|
||||
if (request.GroupId > 0)
|
||||
{
|
||||
entity.GroupId = request.GroupId;
|
||||
}
|
||||
await m_AssetService.Update(entity);
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Delete([FromQuery]int id)
|
||||
{
|
||||
var flag = await m_AssetService.DeleteById(id);
|
||||
if (flag)
|
||||
return Success();
|
||||
else
|
||||
return Error("删除失败");
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> Page([FromQuery]int pageIndex,[FromQuery] int assetType,int groupId, [FromQuery] string name)
|
||||
{
|
||||
Expression<Func<Asset, bool>> expr = m => m.AssetType == assetType;
|
||||
if (groupId>0)
|
||||
{
|
||||
expr = expr.And(m => m.GroupId== groupId);
|
||||
}
|
||||
if (name.Has())
|
||||
{
|
||||
expr = expr.And(m => m.Name.Contains(name));
|
||||
}
|
||||
var enitty = await m_AssetService.Page(pageIndex,15,expr, true);
|
||||
return Success(enitty);
|
||||
}
|
||||
}
|
||||
}
|
||||
using Hncore.Infrastructure.EntitiesExtension;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Vpn.Service;
|
||||
using Hncore.Pass.OSS.Domain;
|
||||
using Hncore.Pass.OSS.Request;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.OSS.Controllers
|
||||
{
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/oss/v{version:apiVersion}/asset/[action]")]
|
||||
public class AssetController : HncoreControllerBase
|
||||
{
|
||||
AssetGroupService m_AssetGroupService;
|
||||
AssetService m_AssetService;
|
||||
public AssetController(AssetGroupService assetGroupService, AssetService _AssetService)
|
||||
{
|
||||
m_AssetGroupService = assetGroupService;
|
||||
m_AssetService = _AssetService;
|
||||
}
|
||||
|
||||
#region group
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> AddGroup([FromBody] PostGroupRequest request)
|
||||
{
|
||||
var entity = request.MapTo<AssetGroup>();
|
||||
entity.TenantId = this.Request.GetManageUserInfo().TenantId;
|
||||
await m_AssetGroupService.Add(entity);
|
||||
return Success();
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> UpdateGroup([FromBody] PostGroupRequest request)
|
||||
{
|
||||
var enitty = await m_AssetGroupService.GetById(request.Id);
|
||||
enitty.Name = request.Name;
|
||||
enitty.TenantId = this.Request.GetManageUserInfo().TenantId;
|
||||
await m_AssetGroupService.Update(enitty);
|
||||
return Success();
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> DeleteGroup([FromQuery] int id)
|
||||
{
|
||||
await m_AssetGroupService.DeleteById(id);
|
||||
return Success();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> GetGroups([FromQuery] int groupType)
|
||||
{
|
||||
var enitty = await m_AssetGroupService.Query(m => m.GroupType == groupType, true).ToListAsync();
|
||||
return Success(enitty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 添加
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Post([FromBody]PostAssetRequest request)
|
||||
{
|
||||
var entity = request.MapTo<Asset>();
|
||||
entity.TenantId = this.Request.GetManageUserInfo().TenantId;
|
||||
await m_AssetService.Add(entity);
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Put([FromBody]PostAssetRequest request)
|
||||
{
|
||||
var entity = await m_AssetService.GetById(request.Id);
|
||||
if (entity == null)
|
||||
return Error("资源不存在");
|
||||
if (request.Name.Has())
|
||||
{
|
||||
entity.Name = request.Name;
|
||||
}
|
||||
if (request.GroupId > 0)
|
||||
{
|
||||
entity.GroupId = request.GroupId;
|
||||
}
|
||||
await m_AssetService.Update(entity);
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<ApiResult> Delete([FromQuery]int id)
|
||||
{
|
||||
var flag = await m_AssetService.DeleteById(id);
|
||||
if (flag)
|
||||
return Success();
|
||||
else
|
||||
return Error("删除失败");
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ApiResult> Page([FromQuery]int pageIndex,[FromQuery] int assetType,int groupId, [FromQuery] string name)
|
||||
{
|
||||
Expression<Func<Asset, bool>> expr = m => m.AssetType == assetType;
|
||||
if (groupId>0)
|
||||
{
|
||||
expr = expr.And(m => m.GroupId== groupId);
|
||||
}
|
||||
if (name.Has())
|
||||
{
|
||||
expr = expr.And(m => m.Name.Contains(name));
|
||||
}
|
||||
var enitty = await m_AssetService.Page(pageIndex,15,expr, true);
|
||||
return Success(enitty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Vpn.Service;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.OSS.Controllers
|
||||
{
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/oss/v{version:apiVersion}/ImageCloud/[action]")]
|
||||
public class ImageCloudController : HncoreControllerBase
|
||||
{
|
||||
UploadService m_UploadService;
|
||||
|
||||
public ImageCloudController(UploadService _UploadService)
|
||||
{
|
||||
m_UploadService = _UploadService;
|
||||
}
|
||||
|
||||
[HttpPost, AllowAnonymous]
|
||||
public async Task<ApiResult> Upload()
|
||||
{
|
||||
var ret = await m_UploadService.GetStreamFromRequest(this.Request);
|
||||
|
||||
if (ret.Item2 == null)
|
||||
return Error("没有图片");
|
||||
|
||||
var url = m_UploadService.AliYunUpload(ret.Item1, ret.Item2,ret.Item3);
|
||||
return Success(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Vpn.Service;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.OSS.Controllers
|
||||
{
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/oss/v{version:apiVersion}/ImageCloud/[action]")]
|
||||
public class ImageCloudController : HncoreControllerBase
|
||||
{
|
||||
UploadService m_UploadService;
|
||||
|
||||
public ImageCloudController(UploadService _UploadService)
|
||||
{
|
||||
m_UploadService = _UploadService;
|
||||
}
|
||||
|
||||
[HttpPost, AllowAnonymous]
|
||||
public async Task<ApiResult> Upload()
|
||||
{
|
||||
var ret = await m_UploadService.GetStreamFromRequest(this.Request);
|
||||
|
||||
if (ret.Item2 == null)
|
||||
return Error("没有图片");
|
||||
|
||||
var url = m_UploadService.AliYunUpload(ret.Item1, ret.Item2,ret.Item3);
|
||||
return Success(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using UEditor.Core;
|
||||
|
||||
namespace Hncore.Pass.OSS.Controllers
|
||||
{
|
||||
[Route("api/ueditor")]
|
||||
[AllowAnonymous]
|
||||
public class UEditorController : Controller
|
||||
{
|
||||
private readonly UEditorService _ueditorService;
|
||||
public UEditorController(UEditorService ueditorService)
|
||||
{
|
||||
this._ueditorService = ueditorService;
|
||||
}
|
||||
|
||||
[HttpGet, HttpPost]
|
||||
public ContentResult Upload()
|
||||
{
|
||||
var response = _ueditorService.UploadAndGetResponse(this.Request.HttpContext);
|
||||
return Content(response.Result, response.ContentType);
|
||||
}
|
||||
|
||||
}
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using UEditor.Core;
|
||||
|
||||
namespace Hncore.Pass.OSS.Controllers
|
||||
{
|
||||
[Route("api/ueditor")]
|
||||
[AllowAnonymous]
|
||||
public class UEditorController : Controller
|
||||
{
|
||||
private readonly UEditorService _ueditorService;
|
||||
public UEditorController(UEditorService ueditorService)
|
||||
{
|
||||
this._ueditorService = ueditorService;
|
||||
}
|
||||
|
||||
[HttpGet, HttpPost]
|
||||
public ContentResult Upload()
|
||||
{
|
||||
var response = _ueditorService.UploadAndGetResponse(this.Request.HttpContext);
|
||||
return Content(response.Result, response.ContentType);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
using Hncore.Infrastructure.DDD;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Hncore.Pass.OSS.Domain
|
||||
{
|
||||
public partial class Asset : EntityWithDelete<int>, ITenant
|
||||
{
|
||||
public int TenantId { get; set; }
|
||||
public int? GroupId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int AssetType { get; set; }
|
||||
public string Image { get; set; }
|
||||
public string BaseUrl { get; set; }
|
||||
public string Path { get; set; }
|
||||
public DateTime? CreateTime { get; set; }
|
||||
|
||||
public string Url { get => BaseUrl.Has() ? $"{BaseUrl}/{Path}" : Path; }
|
||||
}
|
||||
}
|
||||
using Hncore.Infrastructure.DDD;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Hncore.Pass.OSS.Domain
|
||||
{
|
||||
public partial class Asset : EntityWithDelete<int>, ITenant
|
||||
{
|
||||
public int TenantId { get; set; }
|
||||
public int? GroupId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int AssetType { get; set; }
|
||||
public string Image { get; set; }
|
||||
public string BaseUrl { get; set; }
|
||||
public string Path { get; set; }
|
||||
public DateTime? CreateTime { get; set; }
|
||||
|
||||
public string Url { get => BaseUrl.Has() ? $"{BaseUrl}/{Path}" : Path; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
using Hncore.Infrastructure.DDD;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Hncore.Pass.OSS.Domain
|
||||
{
|
||||
public partial class AssetGroup : EntityWithDelete<int>, ITenant
|
||||
{
|
||||
public int TenantId { get; set; }
|
||||
public int? GroupType { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int? OrderNum { get; set; }
|
||||
}
|
||||
}
|
||||
using Hncore.Infrastructure.DDD;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Hncore.Pass.OSS.Domain
|
||||
{
|
||||
public partial class AssetGroup : EntityWithDelete<int>, ITenant
|
||||
{
|
||||
public int TenantId { get; set; }
|
||||
public int? GroupType { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int? OrderNum { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
using Hncore.Infrastructure.EF;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
||||
namespace Hncore.Pass.OSS.Domain
|
||||
{
|
||||
public partial class CourseContext : DbContextBase
|
||||
{
|
||||
IHttpContextAccessor _httpContextAccessor;
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="options">上下文实体</param>
|
||||
/// <param name="httpContextAccessor">http请求上下文</param>
|
||||
public CourseContext(DbContextOptions<CourseContext> options, IHttpContextAccessor httpContextAccessor) :
|
||||
base(options, httpContextAccessor)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public virtual DbSet<Asset> Asset { get; set; }
|
||||
public virtual DbSet<AssetGroup> AssetGroup { get; set; }
|
||||
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Asset>(entity =>
|
||||
{
|
||||
entity.ToTable("asset");
|
||||
entity.HasKey(p => p.Id);
|
||||
entity.Property(e => e.Id).ValueGeneratedOnAdd();
|
||||
});
|
||||
|
||||
modelBuilder.Entity<AssetGroup>(entity =>
|
||||
{
|
||||
entity.ToTable("asset_group");
|
||||
entity.HasKey(p => p.Id);
|
||||
entity.Property(e => e.Id).ValueGeneratedOnAdd();
|
||||
|
||||
});
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
using Hncore.Infrastructure.EF;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
||||
namespace Hncore.Pass.OSS.Domain
|
||||
{
|
||||
public partial class CourseContext : DbContextBase
|
||||
{
|
||||
IHttpContextAccessor _httpContextAccessor;
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="options">上下文实体</param>
|
||||
/// <param name="httpContextAccessor">http请求上下文</param>
|
||||
public CourseContext(DbContextOptions<CourseContext> options, IHttpContextAccessor httpContextAccessor) :
|
||||
base(options, httpContextAccessor)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public virtual DbSet<Asset> Asset { get; set; }
|
||||
public virtual DbSet<AssetGroup> AssetGroup { get; set; }
|
||||
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Asset>(entity =>
|
||||
{
|
||||
entity.ToTable("asset");
|
||||
entity.HasKey(p => p.Id);
|
||||
entity.Property(e => e.Id).ValueGeneratedOnAdd();
|
||||
});
|
||||
|
||||
modelBuilder.Entity<AssetGroup>(entity =>
|
||||
{
|
||||
entity.ToTable("asset_group");
|
||||
entity.HasKey(p => p.Id);
|
||||
entity.Property(e => e.Id).ValueGeneratedOnAdd();
|
||||
|
||||
});
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Aliyun.OSS.SDK.NetCore" Version="2.9.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App">
|
||||
<PrivateAssets Condition="'%(PackageReference.Version)' == ''">all</PrivateAssets>
|
||||
<Publish Condition="'%(PackageReference.Version)' == ''">true</Publish>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Infrastructure\Hncore.Infrastructure\Hncore.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Aliyun.OSS.SDK.NetCore" Version="2.9.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App">
|
||||
<PrivateAssets Condition="'%(PackageReference.Version)' == ''">all</PrivateAssets>
|
||||
<Publish Condition="'%(PackageReference.Version)' == ''">true</Publish>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Infrastructure\Hncore.Infrastructure\Hncore.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using Hncore.Pass.OSS.Domain;
|
||||
using Hncore.Pass.OSS.Request;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Hncore.Pass.Oss.Map
|
||||
{
|
||||
public class MapConfig
|
||||
{
|
||||
public static void Config()
|
||||
{
|
||||
TinyMapperExtension.Binds<AssetGroup, PostGroupRequest>();
|
||||
|
||||
TinyMapperExtension.Binds<List<AssetGroup>, List<PostGroupRequest>>();
|
||||
|
||||
TinyMapperExtension.Binds<Asset, PostAssetRequest>();
|
||||
|
||||
TinyMapperExtension.Binds<List<Asset>, List<PostAssetRequest>>();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using Hncore.Pass.OSS.Domain;
|
||||
using Hncore.Pass.OSS.Request;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Hncore.Pass.Oss.Map
|
||||
{
|
||||
public class MapConfig
|
||||
{
|
||||
public static void Config()
|
||||
{
|
||||
TinyMapperExtension.Binds<AssetGroup, PostGroupRequest>();
|
||||
|
||||
TinyMapperExtension.Binds<List<AssetGroup>, List<PostGroupRequest>>();
|
||||
|
||||
TinyMapperExtension.Binds<Asset, PostAssetRequest>();
|
||||
|
||||
TinyMapperExtension.Binds<List<Asset>, List<PostAssetRequest>>();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.OSS.Model
|
||||
{
|
||||
public class UploadResult
|
||||
{
|
||||
public int AssetType { get; set; } = 0;
|
||||
public string OriginName { get; set; }
|
||||
|
||||
public string BaseUrl { get; set; }
|
||||
|
||||
public string Path { get; set; }
|
||||
|
||||
public string Url { get => BaseUrl.Has() ? $"{BaseUrl}/{Path}" : Path; }
|
||||
}
|
||||
}
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.OSS.Model
|
||||
{
|
||||
public class UploadResult
|
||||
{
|
||||
public int AssetType { get; set; } = 0;
|
||||
public string OriginName { get; set; }
|
||||
|
||||
public string BaseUrl { get; set; }
|
||||
|
||||
public string Path { get; set; }
|
||||
|
||||
public string Url { get => BaseUrl.Has() ? $"{BaseUrl}/{Path}" : Path; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Hncore.Pass.OSS
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateWebHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>();
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Hncore.Pass.OSS
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateWebHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:61626",
|
||||
"sslPort": 0
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "api/values",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"Hncore.Pass.OSS": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "http://localhost:5005"
|
||||
}
|
||||
}
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:61626",
|
||||
"sslPort": 0
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "api/values",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"Hncore.Pass.OSS": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "http://localhost:5005"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.OSS.Request
|
||||
{
|
||||
public class PostAssetRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int GroupId { get; set; } = 0;
|
||||
public string Name { get; set; }
|
||||
public int AssetType { get; set; } = 1;
|
||||
public string BaseUrl { get; set; }
|
||||
public string Path { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.OSS.Request
|
||||
{
|
||||
public class PostAssetRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int GroupId { get; set; } = 0;
|
||||
public string Name { get; set; }
|
||||
public int AssetType { get; set; } = 1;
|
||||
public string BaseUrl { get; set; }
|
||||
public string Path { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.OSS.Request
|
||||
{
|
||||
public class PostGroupRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int TenantId { get; set; }
|
||||
public int? GroupType { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.OSS.Request
|
||||
{
|
||||
public class PostGroupRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int TenantId { get; set; }
|
||||
public int? GroupType { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
namespace Hncore.Pass.Oss.Request
|
||||
{
|
||||
public class UploadImageBase64Request
|
||||
{
|
||||
public string Base64 { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
namespace Hncore.Pass.Oss.Request
|
||||
{
|
||||
public class UploadImageBase64Request
|
||||
{
|
||||
public string Base64 { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Hncore.Pass.OSS.Domain;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Service
|
||||
{
|
||||
public partial class AssetGroupService : ServiceBase<AssetGroup>, IFindService
|
||||
{
|
||||
CourseContext m_DbContext;
|
||||
public AssetGroupService(CourseContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
m_DbContext = dbContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Hncore.Pass.OSS.Domain;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Service
|
||||
{
|
||||
public partial class AssetGroupService : ServiceBase<AssetGroup>, IFindService
|
||||
{
|
||||
CourseContext m_DbContext;
|
||||
public AssetGroupService(CourseContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
m_DbContext = dbContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Hncore.Pass.OSS.Domain;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Service
|
||||
{
|
||||
public partial class AssetService : ServiceBase<Asset>, IFindService
|
||||
{
|
||||
CourseContext m_DbContext;
|
||||
public AssetService(CourseContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
m_DbContext = dbContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Hncore.Pass.OSS.Domain;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Service
|
||||
{
|
||||
public partial class AssetService : ServiceBase<Asset>, IFindService
|
||||
{
|
||||
CourseContext m_DbContext;
|
||||
public AssetService(CourseContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
m_DbContext = dbContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,65 +1,65 @@
|
||||
using Aliyun.OSS;
|
||||
using Hncore.Infrastructure.Core.Web;
|
||||
using Hncore.Infrastructure.Serializer;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Oss.Request;
|
||||
using Hncore.Pass.OSS.Model;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Service
|
||||
{
|
||||
public class UploadService
|
||||
{
|
||||
OssClient m_AliOssClient;
|
||||
IConfiguration m_Configuration;
|
||||
const string m_BucketName = "hncourse";
|
||||
public UploadService(OssClient _AliOssClient, IConfiguration _Configuration)
|
||||
{
|
||||
m_AliOssClient = _AliOssClient;
|
||||
m_Configuration = _Configuration;
|
||||
}
|
||||
public async Task<(string,string,Stream)> GetStreamFromRequest(HttpRequest reuest)
|
||||
{
|
||||
var name = "";
|
||||
var fileKey = DateTime.Now.Ticks + new Random((int)DateTime.Now.Ticks).Next(0, 100000).ToString();
|
||||
Stream stream = default(Stream);
|
||||
//base64上传
|
||||
if (reuest.ContentType.Contains("application/json"))
|
||||
{
|
||||
var body = await reuest.ReadBodyAsStringAsync();
|
||||
var request = body.FromJsonTo<RequestBase<UploadImageBase64Request>>();
|
||||
var base64 = request.Data.Base64;
|
||||
byte[] imageByte = Convert.FromBase64String(base64);
|
||||
stream = new MemoryStream(imageByte);
|
||||
fileKey = $"{fileKey.ToString()}.jpg";
|
||||
name = request.Data.Name;
|
||||
}
|
||||
else if (reuest.Form.Files.Any())
|
||||
{
|
||||
var file = reuest.Form.Files.First();
|
||||
name = file.Name;
|
||||
fileKey = $"{fileKey.ToString()}{Path.GetExtension(file.FileName)}";
|
||||
stream = file.OpenReadStream();
|
||||
}
|
||||
return (fileKey, name,stream);
|
||||
}
|
||||
|
||||
public UploadResult AliYunUpload(string key,string name, Stream stream)
|
||||
{
|
||||
var result = new UploadResult()
|
||||
{
|
||||
BaseUrl = string.Format("http://{0}.{1}", m_BucketName, m_Configuration["Aliyun:Oss:AliEndpoint"]),
|
||||
Path = key,
|
||||
OriginName = name
|
||||
};
|
||||
var ret = m_AliOssClient.PutObject(m_BucketName, key, stream);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
using Aliyun.OSS;
|
||||
using Hncore.Infrastructure.Core.Web;
|
||||
using Hncore.Infrastructure.Serializer;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Oss.Request;
|
||||
using Hncore.Pass.OSS.Model;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.Vpn.Service
|
||||
{
|
||||
public class UploadService
|
||||
{
|
||||
OssClient m_AliOssClient;
|
||||
IConfiguration m_Configuration;
|
||||
const string m_BucketName = "hncourse";
|
||||
public UploadService(OssClient _AliOssClient, IConfiguration _Configuration)
|
||||
{
|
||||
m_AliOssClient = _AliOssClient;
|
||||
m_Configuration = _Configuration;
|
||||
}
|
||||
public async Task<(string,string,Stream)> GetStreamFromRequest(HttpRequest reuest)
|
||||
{
|
||||
var name = "";
|
||||
var fileKey = DateTime.Now.Ticks + new Random((int)DateTime.Now.Ticks).Next(0, 100000).ToString();
|
||||
Stream stream = default(Stream);
|
||||
//base64上传
|
||||
if (reuest.ContentType.Contains("application/json"))
|
||||
{
|
||||
var body = await reuest.ReadBodyAsStringAsync();
|
||||
var request = body.FromJsonTo<RequestBase<UploadImageBase64Request>>();
|
||||
var base64 = request.Data.Base64;
|
||||
byte[] imageByte = Convert.FromBase64String(base64);
|
||||
stream = new MemoryStream(imageByte);
|
||||
fileKey = $"{fileKey.ToString()}.jpg";
|
||||
name = request.Data.Name;
|
||||
}
|
||||
else if (reuest.Form.Files.Any())
|
||||
{
|
||||
var file = reuest.Form.Files.First();
|
||||
name = file.Name;
|
||||
fileKey = $"{fileKey.ToString()}{Path.GetExtension(file.FileName)}";
|
||||
stream = file.OpenReadStream();
|
||||
}
|
||||
return (fileKey, name,stream);
|
||||
}
|
||||
|
||||
public UploadResult AliYunUpload(string key,string name, Stream stream)
|
||||
{
|
||||
var result = new UploadResult()
|
||||
{
|
||||
BaseUrl = string.Format("http://{0}.{1}", m_BucketName, m_Configuration["Aliyun:Oss:AliEndpoint"]),
|
||||
Path = key,
|
||||
OriginName = name
|
||||
};
|
||||
var ret = m_AliOssClient.PutObject(m_BucketName, key, stream);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Oss.Map;
|
||||
using Hncore.Pass.OSS.Domain;
|
||||
using Hncore.Pass.OSS.Utils;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.IO;
|
||||
using UEditor.Core;
|
||||
|
||||
namespace Hncore.Pass.OSS
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
public Startup(IHostingEnvironment env)
|
||||
{
|
||||
Configuration = env.UseAppsettings();
|
||||
}
|
||||
|
||||
public IServiceProvider ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddDbContext<CourseContext>(opt => { opt.UseMySql(Configuration["MySql"]); });
|
||||
services.AddUEditorService();
|
||||
services.AddHttpClient();
|
||||
services.AutoAddService();
|
||||
services.AddAliOssClient(Configuration["Aliyun:Oss:AliEndpoint"], Configuration["Aliyun:Oss:AliAccessId"], Configuration["Aliyun:Oss:AliAccessKey"]);
|
||||
|
||||
return services.Init(Configuration, CompatibilityVersion.Version_2_2, new ServiceOption
|
||||
{
|
||||
UseGlobalManageAuthFilter = false,
|
||||
});
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IApplicationLifetime applicationLifetime,
|
||||
ILoggerFactory loggerFactory)
|
||||
{
|
||||
app.UseStaticFiles();
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "upload")),
|
||||
RequestPath = "/upload",
|
||||
OnPrepareResponse = ctx =>
|
||||
{
|
||||
ctx.Context.Response.Headers.Append("Cache-Control", "public,max-age=36000");
|
||||
}
|
||||
});
|
||||
|
||||
app.Init(loggerFactory, applicationLifetime);
|
||||
MapConfig.Config();
|
||||
}
|
||||
}
|
||||
}
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using Hncore.Pass.Oss.Map;
|
||||
using Hncore.Pass.OSS.Domain;
|
||||
using Hncore.Pass.OSS.Utils;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.IO;
|
||||
using UEditor.Core;
|
||||
|
||||
namespace Hncore.Pass.OSS
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
public Startup(IHostingEnvironment env)
|
||||
{
|
||||
Configuration = env.UseAppsettings();
|
||||
}
|
||||
|
||||
public IServiceProvider ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddDbContext<CourseContext>(opt => { opt.UseMySql(Configuration["MySql"]); });
|
||||
services.AddUEditorService();
|
||||
services.AddHttpClient();
|
||||
services.AutoAddService();
|
||||
services.AddAliOssClient(Configuration["Aliyun:Oss:AliEndpoint"], Configuration["Aliyun:Oss:AliAccessId"], Configuration["Aliyun:Oss:AliAccessKey"]);
|
||||
|
||||
return services.Init(Configuration, CompatibilityVersion.Version_2_2, new ServiceOption
|
||||
{
|
||||
UseGlobalManageAuthFilter = false,
|
||||
});
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IApplicationLifetime applicationLifetime,
|
||||
ILoggerFactory loggerFactory)
|
||||
{
|
||||
app.UseStaticFiles();
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "upload")),
|
||||
RequestPath = "/upload",
|
||||
OnPrepareResponse = ctx =>
|
||||
{
|
||||
ctx.Context.Response.Headers.Append("Cache-Control", "public,max-age=36000");
|
||||
}
|
||||
});
|
||||
|
||||
app.Init(loggerFactory, applicationLifetime);
|
||||
MapConfig.Config();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace UEditor.Core
|
||||
{
|
||||
internal class AppConsts
|
||||
{
|
||||
internal class Action
|
||||
{
|
||||
public const string Config = "config";
|
||||
public const string UploadImage = "uploadimage";
|
||||
public const string UploadScrawl = "uploadscrawl";
|
||||
public const string UploadVideo = "uploadvideo";
|
||||
public const string UploadFile = "uploadfile";
|
||||
public const string ListImage = "listimage";
|
||||
public const string ListFile = "listfile";
|
||||
public const string CatchImage = "catchimage";
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace UEditor.Core
|
||||
{
|
||||
internal class AppConsts
|
||||
{
|
||||
internal class Action
|
||||
{
|
||||
public const string Config = "config";
|
||||
public const string UploadImage = "uploadimage";
|
||||
public const string UploadScrawl = "uploadscrawl";
|
||||
public const string UploadVideo = "uploadvideo";
|
||||
public const string UploadFile = "uploadfile";
|
||||
public const string ListImage = "listimage";
|
||||
public const string ListFile = "listfile";
|
||||
public const string CatchImage = "catchimage";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,80 +1,80 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace UEditor.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Config 的摘要说明
|
||||
/// </summary>
|
||||
public static class Config
|
||||
{
|
||||
public static bool NoCache = true;
|
||||
|
||||
private static JObject BuildItems()
|
||||
{
|
||||
var configExtension = Path.GetExtension(ConfigFile);
|
||||
var configFileName = ConfigFile.Substring(0, ConfigFile.Length - configExtension.Length);
|
||||
var evnConfig = $"{configFileName}.{Config.EnvName}{configExtension}";
|
||||
if (File.Exists(Path.Combine(WebRootPath, evnConfig)))
|
||||
{
|
||||
var json = File.ReadAllText(Path.Combine(WebRootPath, evnConfig));
|
||||
return JObject.Parse(json);
|
||||
}
|
||||
else
|
||||
{
|
||||
var configFilePath = Path.Combine(WebRootPath, ConfigFile);
|
||||
if (!File.Exists(configFilePath))
|
||||
{
|
||||
throw new Exception("未找到UEditor配置文件,请检查!若有问题,请参阅文档:https://github.com/baiyunchen/UEditor.Core");
|
||||
}
|
||||
var json = File.ReadAllText(configFilePath);
|
||||
return JObject.Parse(json);
|
||||
}
|
||||
}
|
||||
|
||||
public static JObject Items
|
||||
{
|
||||
get
|
||||
{
|
||||
if (NoCache || _Items == null)
|
||||
{
|
||||
_Items = BuildItems();
|
||||
}
|
||||
return _Items;
|
||||
}
|
||||
}
|
||||
|
||||
public static string EnvName { get; set; }
|
||||
|
||||
public static string WebRootPath { get; set; }
|
||||
|
||||
// public static string WwwRootPath { get; set; }
|
||||
|
||||
public static string ConfigFile { set; get; } = "ueditor.json";
|
||||
|
||||
private static JObject _Items;
|
||||
|
||||
|
||||
public static T GetValue<T>(string key)
|
||||
{
|
||||
return Items[key].Value<T>();
|
||||
}
|
||||
|
||||
public static String[] GetStringList(string key)
|
||||
{
|
||||
return Items[key].Select(x => x.Value<String>()).ToArray();
|
||||
}
|
||||
|
||||
public static String GetString(string key)
|
||||
{
|
||||
return GetValue<String>(key);
|
||||
}
|
||||
|
||||
public static int GetInt(string key)
|
||||
{
|
||||
return GetValue<int>(key);
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace UEditor.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Config 的摘要说明
|
||||
/// </summary>
|
||||
public static class Config
|
||||
{
|
||||
public static bool NoCache = true;
|
||||
|
||||
private static JObject BuildItems()
|
||||
{
|
||||
var configExtension = Path.GetExtension(ConfigFile);
|
||||
var configFileName = ConfigFile.Substring(0, ConfigFile.Length - configExtension.Length);
|
||||
var evnConfig = $"{configFileName}.{Config.EnvName}{configExtension}";
|
||||
if (File.Exists(Path.Combine(WebRootPath, evnConfig)))
|
||||
{
|
||||
var json = File.ReadAllText(Path.Combine(WebRootPath, evnConfig));
|
||||
return JObject.Parse(json);
|
||||
}
|
||||
else
|
||||
{
|
||||
var configFilePath = Path.Combine(WebRootPath, ConfigFile);
|
||||
if (!File.Exists(configFilePath))
|
||||
{
|
||||
throw new Exception("未找到UEditor配置文件,请检查!若有问题,请参阅文档:https://github.com/baiyunchen/UEditor.Core");
|
||||
}
|
||||
var json = File.ReadAllText(configFilePath);
|
||||
return JObject.Parse(json);
|
||||
}
|
||||
}
|
||||
|
||||
public static JObject Items
|
||||
{
|
||||
get
|
||||
{
|
||||
if (NoCache || _Items == null)
|
||||
{
|
||||
_Items = BuildItems();
|
||||
}
|
||||
return _Items;
|
||||
}
|
||||
}
|
||||
|
||||
public static string EnvName { get; set; }
|
||||
|
||||
public static string WebRootPath { get; set; }
|
||||
|
||||
// public static string WwwRootPath { get; set; }
|
||||
|
||||
public static string ConfigFile { set; get; } = "ueditor.json";
|
||||
|
||||
private static JObject _Items;
|
||||
|
||||
|
||||
public static T GetValue<T>(string key)
|
||||
{
|
||||
return Items[key].Value<T>();
|
||||
}
|
||||
|
||||
public static String[] GetStringList(string key)
|
||||
{
|
||||
return Items[key].Select(x => x.Value<String>()).ToArray();
|
||||
}
|
||||
|
||||
public static String GetString(string key)
|
||||
{
|
||||
return GetValue<String>(key);
|
||||
}
|
||||
|
||||
public static int GetInt(string key)
|
||||
{
|
||||
return GetValue<int>(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,121 +1,121 @@
|
||||
using Hncore.Pass.Vpn.Service;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace UEditor.Core.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// UploadHandler 的摘要说明
|
||||
/// </summary>
|
||||
public class AliUploadHandler : UploadHandler
|
||||
{
|
||||
public AliUploadHandler(HttpContext context)
|
||||
: base(context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public UploadService Uploader { get; set; }
|
||||
|
||||
public override UEditorResult Process()
|
||||
{
|
||||
string uploadFileName = "";
|
||||
Stream stream = default(Stream);
|
||||
if (UploadConfig.Base64)
|
||||
{
|
||||
uploadFileName = UploadConfig.Base64Filename;
|
||||
var uploadFileBytes = Convert.FromBase64String(Request.Form[UploadConfig.UploadFieldName]);
|
||||
stream = new MemoryStream(uploadFileBytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
var file = Request.Form.Files[UploadConfig.UploadFieldName];
|
||||
uploadFileName = file.FileName;
|
||||
if (!CheckFileType(uploadFileName))
|
||||
{
|
||||
Result.State = UploadState.TypeNotAllow;
|
||||
return WriteResult();
|
||||
}
|
||||
if (!CheckFileSize(file.Length))
|
||||
{
|
||||
Result.State = UploadState.SizeLimitExceed;
|
||||
return WriteResult();
|
||||
}
|
||||
try
|
||||
{
|
||||
stream = file.OpenReadStream();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Result.State = UploadState.NetworkError;
|
||||
WriteResult();
|
||||
}
|
||||
}
|
||||
var fileKey = DateTime.Now.Ticks + new Random((int)DateTime.Now.Ticks).Next(0, 100000).ToString();
|
||||
Result.OriginFileName = uploadFileName;
|
||||
UEditorResult result;
|
||||
try
|
||||
{
|
||||
fileKey = $"{fileKey.ToString()}{Path.GetExtension(uploadFileName)}";
|
||||
var ret = Uploader.AliYunUpload(fileKey, Result.OriginFileName, stream);
|
||||
Result.Url = ret.Url;
|
||||
Result.State = UploadState.Success;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Result.State = UploadState.FileAccessError;
|
||||
Result.ErrorMessage = e.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
result = WriteResult();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private UEditorResult WriteResult()
|
||||
{
|
||||
return new UEditorResult
|
||||
{
|
||||
State = GetStateMessage(Result.State),
|
||||
Url = Result.Url,
|
||||
Title = Result.OriginFileName,
|
||||
Original = Result.OriginFileName,
|
||||
Error = Result.ErrorMessage
|
||||
};
|
||||
}
|
||||
|
||||
private string GetStateMessage(UploadState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case UploadState.Success:
|
||||
return "SUCCESS";
|
||||
case UploadState.FileAccessError:
|
||||
return "文件访问出错,请检查写入权限";
|
||||
case UploadState.SizeLimitExceed:
|
||||
return "文件大小超出服务器限制";
|
||||
case UploadState.TypeNotAllow:
|
||||
return "不允许的文件格式";
|
||||
case UploadState.NetworkError:
|
||||
return "网络错误";
|
||||
}
|
||||
return "未知错误";
|
||||
}
|
||||
|
||||
private bool CheckFileType(string filename)
|
||||
{
|
||||
var fileExtension = Path.GetExtension(filename).ToLower();
|
||||
return UploadConfig.AllowExtensions.Select(x => x.ToLower()).Contains(fileExtension);
|
||||
}
|
||||
|
||||
private bool CheckFileSize(long size)
|
||||
{
|
||||
return size < UploadConfig.SizeLimit;
|
||||
}
|
||||
}
|
||||
using Hncore.Pass.Vpn.Service;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace UEditor.Core.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// UploadHandler 的摘要说明
|
||||
/// </summary>
|
||||
public class AliUploadHandler : UploadHandler
|
||||
{
|
||||
public AliUploadHandler(HttpContext context)
|
||||
: base(context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public UploadService Uploader { get; set; }
|
||||
|
||||
public override UEditorResult Process()
|
||||
{
|
||||
string uploadFileName = "";
|
||||
Stream stream = default(Stream);
|
||||
if (UploadConfig.Base64)
|
||||
{
|
||||
uploadFileName = UploadConfig.Base64Filename;
|
||||
var uploadFileBytes = Convert.FromBase64String(Request.Form[UploadConfig.UploadFieldName]);
|
||||
stream = new MemoryStream(uploadFileBytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
var file = Request.Form.Files[UploadConfig.UploadFieldName];
|
||||
uploadFileName = file.FileName;
|
||||
if (!CheckFileType(uploadFileName))
|
||||
{
|
||||
Result.State = UploadState.TypeNotAllow;
|
||||
return WriteResult();
|
||||
}
|
||||
if (!CheckFileSize(file.Length))
|
||||
{
|
||||
Result.State = UploadState.SizeLimitExceed;
|
||||
return WriteResult();
|
||||
}
|
||||
try
|
||||
{
|
||||
stream = file.OpenReadStream();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Result.State = UploadState.NetworkError;
|
||||
WriteResult();
|
||||
}
|
||||
}
|
||||
var fileKey = DateTime.Now.Ticks + new Random((int)DateTime.Now.Ticks).Next(0, 100000).ToString();
|
||||
Result.OriginFileName = uploadFileName;
|
||||
UEditorResult result;
|
||||
try
|
||||
{
|
||||
fileKey = $"{fileKey.ToString()}{Path.GetExtension(uploadFileName)}";
|
||||
var ret = Uploader.AliYunUpload(fileKey, Result.OriginFileName, stream);
|
||||
Result.Url = ret.Url;
|
||||
Result.State = UploadState.Success;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Result.State = UploadState.FileAccessError;
|
||||
Result.ErrorMessage = e.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
result = WriteResult();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private UEditorResult WriteResult()
|
||||
{
|
||||
return new UEditorResult
|
||||
{
|
||||
State = GetStateMessage(Result.State),
|
||||
Url = Result.Url,
|
||||
Title = Result.OriginFileName,
|
||||
Original = Result.OriginFileName,
|
||||
Error = Result.ErrorMessage
|
||||
};
|
||||
}
|
||||
|
||||
private string GetStateMessage(UploadState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case UploadState.Success:
|
||||
return "SUCCESS";
|
||||
case UploadState.FileAccessError:
|
||||
return "文件访问出错,请检查写入权限";
|
||||
case UploadState.SizeLimitExceed:
|
||||
return "文件大小超出服务器限制";
|
||||
case UploadState.TypeNotAllow:
|
||||
return "不允许的文件格式";
|
||||
case UploadState.NetworkError:
|
||||
return "网络错误";
|
||||
}
|
||||
return "未知错误";
|
||||
}
|
||||
|
||||
private bool CheckFileType(string filename)
|
||||
{
|
||||
var fileExtension = Path.GetExtension(filename).ToLower();
|
||||
return UploadConfig.AllowExtensions.Select(x => x.ToLower()).Contains(fileExtension);
|
||||
}
|
||||
|
||||
private bool CheckFileSize(long size)
|
||||
{
|
||||
return size < UploadConfig.SizeLimit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace UEditor.Core.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// Config 的摘要说明
|
||||
/// </summary>
|
||||
public class ConfigHandler
|
||||
{
|
||||
public JObject Process()
|
||||
{
|
||||
return Config.Items;
|
||||
}
|
||||
}
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace UEditor.Core.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// Config 的摘要说明
|
||||
/// </summary>
|
||||
public class ConfigHandler
|
||||
{
|
||||
public JObject Process()
|
||||
{
|
||||
return Config.Items;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,177 +1,177 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
|
||||
namespace UEditor.Core.Handlers
|
||||
{
|
||||
public class CrawlerHandler : Handler
|
||||
{
|
||||
private string[] _sources;
|
||||
private Crawler[] _crawlers;
|
||||
public CrawlerHandler(HttpContext context) : base(context) { }
|
||||
|
||||
public override UEditorResult Process()
|
||||
{
|
||||
_sources = Request.Form["source[]"];
|
||||
|
||||
//fixed bug:https://github.com/baiyunchen/UEditor.Core/pull/5
|
||||
if (_sources == null || _sources.Length == 0)
|
||||
{
|
||||
_sources = Request.Query["source[]"];
|
||||
}
|
||||
|
||||
|
||||
if (_sources == null || _sources.Length == 0)
|
||||
{
|
||||
return new UEditorResult
|
||||
{
|
||||
State = "参数错误:没有指定抓取源"
|
||||
};
|
||||
|
||||
}
|
||||
_crawlers = _sources.Select(x => new Crawler(x).Fetch()).ToArray();
|
||||
return new UEditorResult
|
||||
{
|
||||
State = "SUCCESS",
|
||||
List = _crawlers.Select(x => new UEditorFileList
|
||||
{
|
||||
State = x.State,
|
||||
Source = x.SourceUrl,
|
||||
Url = x.ServerUrl
|
||||
})
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class Crawler
|
||||
{
|
||||
public string SourceUrl { get; set; }
|
||||
public string ServerUrl { get; set; }
|
||||
public string State { get; set; }
|
||||
|
||||
|
||||
public Crawler(string sourceUrl)
|
||||
{
|
||||
this.SourceUrl = sourceUrl;
|
||||
}
|
||||
|
||||
public Crawler Fetch()
|
||||
{
|
||||
if (!IsExternalIpAddress(this.SourceUrl))
|
||||
{
|
||||
State = "INVALID_URL";
|
||||
return this;
|
||||
}
|
||||
var request = WebRequest.Create(this.SourceUrl) as HttpWebRequest;
|
||||
using (var response = request.GetResponse() as HttpWebResponse)
|
||||
{
|
||||
if (response != null && response.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
State = "Url returns " + response.StatusCode + ", " + response.StatusDescription;
|
||||
return this;
|
||||
}
|
||||
if (response != null && response.ContentType.IndexOf("image", StringComparison.Ordinal) == -1)
|
||||
{
|
||||
State = "Url is not an image";
|
||||
return this;
|
||||
}
|
||||
var sourceUri = new Uri(this.SourceUrl);
|
||||
|
||||
ServerUrl = PathFormatter.Format(Path.GetFileName(sourceUri.AbsolutePath), Config.GetString("catcherPathFormat"));
|
||||
|
||||
var savePath = Path.Combine(Config.WebRootPath, ServerUrl);
|
||||
|
||||
if (!Directory.Exists(Path.GetDirectoryName(savePath)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(savePath));
|
||||
}
|
||||
try
|
||||
{
|
||||
if (response != null)
|
||||
{
|
||||
var stream = response.GetResponseStream();
|
||||
var reader = new BinaryReader(stream);
|
||||
byte[] bytes;
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
byte[] buffer = new byte[4096];
|
||||
int count;
|
||||
while ((count = reader.Read(buffer, 0, buffer.Length)) != 0)
|
||||
{
|
||||
ms.Write(buffer, 0, count);
|
||||
}
|
||||
bytes = ms.ToArray();
|
||||
}
|
||||
File.WriteAllBytes(savePath, bytes);
|
||||
}
|
||||
|
||||
State = "SUCCESS";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
State = "抓取错误:" + e.Message;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsExternalIpAddress(string url)
|
||||
{
|
||||
var uri = new Uri(url);
|
||||
switch (uri.HostNameType)
|
||||
{
|
||||
case UriHostNameType.Dns:
|
||||
var ipHostEntry = Dns.GetHostEntry(uri.DnsSafeHost);
|
||||
foreach (IPAddress ipAddress in ipHostEntry.AddressList)
|
||||
{
|
||||
byte[] ipBytes = ipAddress.GetAddressBytes();
|
||||
if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
|
||||
{
|
||||
if (!IsPrivateIP(ipAddress))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case UriHostNameType.IPv4:
|
||||
return !IsPrivateIP(IPAddress.Parse(uri.DnsSafeHost));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsPrivateIP(IPAddress myIpAddress)
|
||||
{
|
||||
if (IPAddress.IsLoopback(myIpAddress)) return true;
|
||||
if (myIpAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
|
||||
{
|
||||
byte[] ipBytes = myIpAddress.GetAddressBytes();
|
||||
// 10.0.0.0/24
|
||||
if (ipBytes[0] == 10)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// 172.16.0.0/16
|
||||
else if (ipBytes[0] == 172 && ipBytes[1] == 16)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// 192.168.0.0/16
|
||||
else if (ipBytes[0] == 192 && ipBytes[1] == 168)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// 169.254.0.0/16
|
||||
else if (ipBytes[0] == 169 && ipBytes[1] == 254)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
|
||||
namespace UEditor.Core.Handlers
|
||||
{
|
||||
public class CrawlerHandler : Handler
|
||||
{
|
||||
private string[] _sources;
|
||||
private Crawler[] _crawlers;
|
||||
public CrawlerHandler(HttpContext context) : base(context) { }
|
||||
|
||||
public override UEditorResult Process()
|
||||
{
|
||||
_sources = Request.Form["source[]"];
|
||||
|
||||
//fixed bug:https://github.com/baiyunchen/UEditor.Core/pull/5
|
||||
if (_sources == null || _sources.Length == 0)
|
||||
{
|
||||
_sources = Request.Query["source[]"];
|
||||
}
|
||||
|
||||
|
||||
if (_sources == null || _sources.Length == 0)
|
||||
{
|
||||
return new UEditorResult
|
||||
{
|
||||
State = "参数错误:没有指定抓取源"
|
||||
};
|
||||
|
||||
}
|
||||
_crawlers = _sources.Select(x => new Crawler(x).Fetch()).ToArray();
|
||||
return new UEditorResult
|
||||
{
|
||||
State = "SUCCESS",
|
||||
List = _crawlers.Select(x => new UEditorFileList
|
||||
{
|
||||
State = x.State,
|
||||
Source = x.SourceUrl,
|
||||
Url = x.ServerUrl
|
||||
})
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class Crawler
|
||||
{
|
||||
public string SourceUrl { get; set; }
|
||||
public string ServerUrl { get; set; }
|
||||
public string State { get; set; }
|
||||
|
||||
|
||||
public Crawler(string sourceUrl)
|
||||
{
|
||||
this.SourceUrl = sourceUrl;
|
||||
}
|
||||
|
||||
public Crawler Fetch()
|
||||
{
|
||||
if (!IsExternalIpAddress(this.SourceUrl))
|
||||
{
|
||||
State = "INVALID_URL";
|
||||
return this;
|
||||
}
|
||||
var request = WebRequest.Create(this.SourceUrl) as HttpWebRequest;
|
||||
using (var response = request.GetResponse() as HttpWebResponse)
|
||||
{
|
||||
if (response != null && response.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
State = "Url returns " + response.StatusCode + ", " + response.StatusDescription;
|
||||
return this;
|
||||
}
|
||||
if (response != null && response.ContentType.IndexOf("image", StringComparison.Ordinal) == -1)
|
||||
{
|
||||
State = "Url is not an image";
|
||||
return this;
|
||||
}
|
||||
var sourceUri = new Uri(this.SourceUrl);
|
||||
|
||||
ServerUrl = PathFormatter.Format(Path.GetFileName(sourceUri.AbsolutePath), Config.GetString("catcherPathFormat"));
|
||||
|
||||
var savePath = Path.Combine(Config.WebRootPath, ServerUrl);
|
||||
|
||||
if (!Directory.Exists(Path.GetDirectoryName(savePath)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(savePath));
|
||||
}
|
||||
try
|
||||
{
|
||||
if (response != null)
|
||||
{
|
||||
var stream = response.GetResponseStream();
|
||||
var reader = new BinaryReader(stream);
|
||||
byte[] bytes;
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
byte[] buffer = new byte[4096];
|
||||
int count;
|
||||
while ((count = reader.Read(buffer, 0, buffer.Length)) != 0)
|
||||
{
|
||||
ms.Write(buffer, 0, count);
|
||||
}
|
||||
bytes = ms.ToArray();
|
||||
}
|
||||
File.WriteAllBytes(savePath, bytes);
|
||||
}
|
||||
|
||||
State = "SUCCESS";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
State = "抓取错误:" + e.Message;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsExternalIpAddress(string url)
|
||||
{
|
||||
var uri = new Uri(url);
|
||||
switch (uri.HostNameType)
|
||||
{
|
||||
case UriHostNameType.Dns:
|
||||
var ipHostEntry = Dns.GetHostEntry(uri.DnsSafeHost);
|
||||
foreach (IPAddress ipAddress in ipHostEntry.AddressList)
|
||||
{
|
||||
byte[] ipBytes = ipAddress.GetAddressBytes();
|
||||
if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
|
||||
{
|
||||
if (!IsPrivateIP(ipAddress))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case UriHostNameType.IPv4:
|
||||
return !IsPrivateIP(IPAddress.Parse(uri.DnsSafeHost));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsPrivateIP(IPAddress myIpAddress)
|
||||
{
|
||||
if (IPAddress.IsLoopback(myIpAddress)) return true;
|
||||
if (myIpAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
|
||||
{
|
||||
byte[] ipBytes = myIpAddress.GetAddressBytes();
|
||||
// 10.0.0.0/24
|
||||
if (ipBytes[0] == 10)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// 172.16.0.0/16
|
||||
else if (ipBytes[0] == 172 && ipBytes[1] == 16)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// 192.168.0.0/16
|
||||
else if (ipBytes[0] == 192 && ipBytes[1] == 168)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// 169.254.0.0/16
|
||||
else if (ipBytes[0] == 169 && ipBytes[1] == 254)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,76 +1,76 @@
|
||||
|
||||
using Hncore.Pass.Vpn.Service;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace UEditor.Core.Handlers
|
||||
{
|
||||
public class HandelFactory
|
||||
{
|
||||
|
||||
public static Handler GetHandler(string action, HttpContext context, UploadService m_UploadService)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case AppConsts.Action.UploadImage:
|
||||
return new UploadHandler(context)
|
||||
{
|
||||
//Uploader= m_UploadService,
|
||||
UploadConfig = new UploadConfig
|
||||
{
|
||||
AllowExtensions = Config.GetStringList("imageAllowFiles"),
|
||||
PathFormat = Config.GetString("imagePathFormat"),
|
||||
SizeLimit = Config.GetInt("imageMaxSize"),
|
||||
UploadFieldName = Config.GetString("imageFieldName")
|
||||
}
|
||||
};
|
||||
case AppConsts.Action.UploadScrawl:
|
||||
return new UploadHandler(context)
|
||||
{
|
||||
//Uploader = m_UploadService,
|
||||
UploadConfig = new UploadConfig()
|
||||
{
|
||||
AllowExtensions = new string[] { ".png" },
|
||||
PathFormat = Config.GetString("scrawlPathFormat"),
|
||||
SizeLimit = Config.GetInt("scrawlMaxSize"),
|
||||
UploadFieldName = Config.GetString("scrawlFieldName"),
|
||||
Base64 = true,
|
||||
Base64Filename = "scrawl.png"
|
||||
}
|
||||
};
|
||||
case AppConsts.Action.UploadVideo:
|
||||
return new UploadHandler(context)
|
||||
{
|
||||
//Uploader = m_UploadService,
|
||||
UploadConfig = new UploadConfig()
|
||||
{
|
||||
AllowExtensions = Config.GetStringList("videoAllowFiles"),
|
||||
PathFormat = Config.GetString("videoPathFormat"),
|
||||
SizeLimit = Config.GetInt("videoMaxSize"),
|
||||
UploadFieldName = Config.GetString("videoFieldName")
|
||||
}
|
||||
};
|
||||
case AppConsts.Action.UploadFile:
|
||||
return new UploadHandler(context)
|
||||
{
|
||||
//Uploader = m_UploadService,
|
||||
UploadConfig = new UploadConfig()
|
||||
{
|
||||
AllowExtensions = Config.GetStringList("fileAllowFiles"),
|
||||
PathFormat = Config.GetString("filePathFormat"),
|
||||
SizeLimit = Config.GetInt("fileMaxSize"),
|
||||
UploadFieldName = Config.GetString("fileFieldName")
|
||||
}
|
||||
};
|
||||
|
||||
case AppConsts.Action.ListImage:
|
||||
return new ListFileManager(context, Config.GetString("imageManagerListPath"), Config.GetStringList("imageManagerAllowFiles"));
|
||||
case AppConsts.Action.ListFile:
|
||||
return new ListFileManager(context, Config.GetString("fileManagerListPath"), Config.GetStringList("fileManagerAllowFiles"));
|
||||
case AppConsts.Action.CatchImage:
|
||||
return new CrawlerHandler(context);
|
||||
default:
|
||||
return new NotSupportedHandler(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using Hncore.Pass.Vpn.Service;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace UEditor.Core.Handlers
|
||||
{
|
||||
public class HandelFactory
|
||||
{
|
||||
|
||||
public static Handler GetHandler(string action, HttpContext context, UploadService m_UploadService)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case AppConsts.Action.UploadImage:
|
||||
return new UploadHandler(context)
|
||||
{
|
||||
//Uploader= m_UploadService,
|
||||
UploadConfig = new UploadConfig
|
||||
{
|
||||
AllowExtensions = Config.GetStringList("imageAllowFiles"),
|
||||
PathFormat = Config.GetString("imagePathFormat"),
|
||||
SizeLimit = Config.GetInt("imageMaxSize"),
|
||||
UploadFieldName = Config.GetString("imageFieldName")
|
||||
}
|
||||
};
|
||||
case AppConsts.Action.UploadScrawl:
|
||||
return new UploadHandler(context)
|
||||
{
|
||||
//Uploader = m_UploadService,
|
||||
UploadConfig = new UploadConfig()
|
||||
{
|
||||
AllowExtensions = new string[] { ".png" },
|
||||
PathFormat = Config.GetString("scrawlPathFormat"),
|
||||
SizeLimit = Config.GetInt("scrawlMaxSize"),
|
||||
UploadFieldName = Config.GetString("scrawlFieldName"),
|
||||
Base64 = true,
|
||||
Base64Filename = "scrawl.png"
|
||||
}
|
||||
};
|
||||
case AppConsts.Action.UploadVideo:
|
||||
return new UploadHandler(context)
|
||||
{
|
||||
//Uploader = m_UploadService,
|
||||
UploadConfig = new UploadConfig()
|
||||
{
|
||||
AllowExtensions = Config.GetStringList("videoAllowFiles"),
|
||||
PathFormat = Config.GetString("videoPathFormat"),
|
||||
SizeLimit = Config.GetInt("videoMaxSize"),
|
||||
UploadFieldName = Config.GetString("videoFieldName")
|
||||
}
|
||||
};
|
||||
case AppConsts.Action.UploadFile:
|
||||
return new UploadHandler(context)
|
||||
{
|
||||
//Uploader = m_UploadService,
|
||||
UploadConfig = new UploadConfig()
|
||||
{
|
||||
AllowExtensions = Config.GetStringList("fileAllowFiles"),
|
||||
PathFormat = Config.GetString("filePathFormat"),
|
||||
SizeLimit = Config.GetInt("fileMaxSize"),
|
||||
UploadFieldName = Config.GetString("fileFieldName")
|
||||
}
|
||||
};
|
||||
|
||||
case AppConsts.Action.ListImage:
|
||||
return new ListFileManager(context, Config.GetString("imageManagerListPath"), Config.GetStringList("imageManagerAllowFiles"));
|
||||
case AppConsts.Action.ListFile:
|
||||
return new ListFileManager(context, Config.GetString("fileManagerListPath"), Config.GetStringList("fileManagerAllowFiles"));
|
||||
case AppConsts.Action.CatchImage:
|
||||
return new CrawlerHandler(context);
|
||||
default:
|
||||
return new NotSupportedHandler(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace UEditor.Core.Handlers
|
||||
{
|
||||
public abstract class Handler
|
||||
{
|
||||
public Handler(HttpContext context)
|
||||
{
|
||||
this.Request = context.Request;
|
||||
this.Response = context.Response;
|
||||
this.Context = context;
|
||||
}
|
||||
|
||||
public abstract UEditorResult Process();
|
||||
|
||||
public HttpRequest Request { get; private set; }
|
||||
public HttpResponse Response { get; private set; }
|
||||
public HttpContext Context { get; private set; }
|
||||
}
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace UEditor.Core.Handlers
|
||||
{
|
||||
public abstract class Handler
|
||||
{
|
||||
public Handler(HttpContext context)
|
||||
{
|
||||
this.Request = context.Request;
|
||||
this.Response = context.Response;
|
||||
this.Context = context;
|
||||
}
|
||||
|
||||
public abstract UEditorResult Process();
|
||||
|
||||
public HttpRequest Request { get; private set; }
|
||||
public HttpResponse Response { get; private set; }
|
||||
public HttpContext Context { get; private set; }
|
||||
}
|
||||
}
|
||||
@@ -1,113 +1,113 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
|
||||
namespace UEditor.Core.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// FileManager 的摘要说明
|
||||
/// </summary>
|
||||
public class ListFileManager : Handler
|
||||
{
|
||||
enum ResultState
|
||||
{
|
||||
Success,
|
||||
InvalidParam,
|
||||
AuthorizError,
|
||||
IOError,
|
||||
PathNotFound
|
||||
}
|
||||
|
||||
private int Start;
|
||||
private int Size;
|
||||
private int Total;
|
||||
private ResultState State;
|
||||
private String PathToList;
|
||||
private String[] FileList;
|
||||
private String[] SearchExtensions;
|
||||
|
||||
public ListFileManager(HttpContext context, string pathToList, string[] searchExtensions)
|
||||
: base(context)
|
||||
{
|
||||
this.SearchExtensions = searchExtensions.Select(x => x.ToLower()).ToArray();
|
||||
this.PathToList = pathToList;
|
||||
}
|
||||
|
||||
public override UEditorResult Process()
|
||||
{
|
||||
try
|
||||
{
|
||||
Start = string.IsNullOrWhiteSpace(Request.Query["start"]) ? 0 : Convert.ToInt32(Request.Query["start"]);
|
||||
Size = string.IsNullOrWhiteSpace(Request.Query["size"]) ? Config.GetInt("imageManagerListSize") : Convert.ToInt32(Request.Query["size"]);
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
State = ResultState.InvalidParam;
|
||||
return WriteResult();
|
||||
}
|
||||
UEditorResult result;
|
||||
var buildingList = new List<String>();
|
||||
try
|
||||
{
|
||||
var localPath = Path.Combine(Config.WebRootPath, PathToList);
|
||||
buildingList.AddRange(Directory.GetFiles(localPath, "*", SearchOption.AllDirectories)
|
||||
.Where(x => SearchExtensions.Contains(Path.GetExtension(x).ToLower()))
|
||||
.Select(x => PathToList + x.Substring(localPath.Length).Replace("\\", "/")));
|
||||
Total = buildingList.Count;
|
||||
FileList = buildingList.OrderBy(x => x).Skip(Start).Take(Size).ToArray();
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
State = ResultState.AuthorizError;
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
State = ResultState.PathNotFound;
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
State = ResultState.IOError;
|
||||
}
|
||||
finally
|
||||
{
|
||||
result = WriteResult();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private UEditorResult WriteResult()
|
||||
{
|
||||
return new UEditorResult
|
||||
{
|
||||
State = GetStateString(),
|
||||
List = FileList?.Select(x => new UEditorFileList { Url = x }),
|
||||
Start = Start,
|
||||
Size = Size,
|
||||
Total = Total
|
||||
};
|
||||
}
|
||||
|
||||
private string GetStateString()
|
||||
{
|
||||
switch (State)
|
||||
{
|
||||
case ResultState.Success:
|
||||
return "SUCCESS";
|
||||
case ResultState.InvalidParam:
|
||||
return "参数不正确";
|
||||
case ResultState.PathNotFound:
|
||||
return "路径不存在";
|
||||
case ResultState.AuthorizError:
|
||||
return "文件系统权限不足";
|
||||
case ResultState.IOError:
|
||||
return "文件系统读取错误";
|
||||
}
|
||||
return "未知错误";
|
||||
}
|
||||
}
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
|
||||
namespace UEditor.Core.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// FileManager 的摘要说明
|
||||
/// </summary>
|
||||
public class ListFileManager : Handler
|
||||
{
|
||||
enum ResultState
|
||||
{
|
||||
Success,
|
||||
InvalidParam,
|
||||
AuthorizError,
|
||||
IOError,
|
||||
PathNotFound
|
||||
}
|
||||
|
||||
private int Start;
|
||||
private int Size;
|
||||
private int Total;
|
||||
private ResultState State;
|
||||
private String PathToList;
|
||||
private String[] FileList;
|
||||
private String[] SearchExtensions;
|
||||
|
||||
public ListFileManager(HttpContext context, string pathToList, string[] searchExtensions)
|
||||
: base(context)
|
||||
{
|
||||
this.SearchExtensions = searchExtensions.Select(x => x.ToLower()).ToArray();
|
||||
this.PathToList = pathToList;
|
||||
}
|
||||
|
||||
public override UEditorResult Process()
|
||||
{
|
||||
try
|
||||
{
|
||||
Start = string.IsNullOrWhiteSpace(Request.Query["start"]) ? 0 : Convert.ToInt32(Request.Query["start"]);
|
||||
Size = string.IsNullOrWhiteSpace(Request.Query["size"]) ? Config.GetInt("imageManagerListSize") : Convert.ToInt32(Request.Query["size"]);
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
State = ResultState.InvalidParam;
|
||||
return WriteResult();
|
||||
}
|
||||
UEditorResult result;
|
||||
var buildingList = new List<String>();
|
||||
try
|
||||
{
|
||||
var localPath = Path.Combine(Config.WebRootPath, PathToList);
|
||||
buildingList.AddRange(Directory.GetFiles(localPath, "*", SearchOption.AllDirectories)
|
||||
.Where(x => SearchExtensions.Contains(Path.GetExtension(x).ToLower()))
|
||||
.Select(x => PathToList + x.Substring(localPath.Length).Replace("\\", "/")));
|
||||
Total = buildingList.Count;
|
||||
FileList = buildingList.OrderBy(x => x).Skip(Start).Take(Size).ToArray();
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
State = ResultState.AuthorizError;
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
State = ResultState.PathNotFound;
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
State = ResultState.IOError;
|
||||
}
|
||||
finally
|
||||
{
|
||||
result = WriteResult();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private UEditorResult WriteResult()
|
||||
{
|
||||
return new UEditorResult
|
||||
{
|
||||
State = GetStateString(),
|
||||
List = FileList?.Select(x => new UEditorFileList { Url = x }),
|
||||
Start = Start,
|
||||
Size = Size,
|
||||
Total = Total
|
||||
};
|
||||
}
|
||||
|
||||
private string GetStateString()
|
||||
{
|
||||
switch (State)
|
||||
{
|
||||
case ResultState.Success:
|
||||
return "SUCCESS";
|
||||
case ResultState.InvalidParam:
|
||||
return "参数不正确";
|
||||
case ResultState.PathNotFound:
|
||||
return "路径不存在";
|
||||
case ResultState.AuthorizError:
|
||||
return "文件系统权限不足";
|
||||
case ResultState.IOError:
|
||||
return "文件系统读取错误";
|
||||
}
|
||||
return "未知错误";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,25 @@
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
|
||||
namespace UEditor.Core.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// NotSupportedHandler 的摘要说明
|
||||
/// </summary>
|
||||
public class NotSupportedHandler : Handler
|
||||
{
|
||||
public NotSupportedHandler(HttpContext context)
|
||||
: base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public override UEditorResult Process()
|
||||
{
|
||||
return new UEditorResult
|
||||
{
|
||||
State = "action 参数为空或者 action 不被支持。"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
|
||||
namespace UEditor.Core.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// NotSupportedHandler 的摘要说明
|
||||
/// </summary>
|
||||
public class NotSupportedHandler : Handler
|
||||
{
|
||||
public NotSupportedHandler(HttpContext context)
|
||||
: base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public override UEditorResult Process()
|
||||
{
|
||||
return new UEditorResult
|
||||
{
|
||||
State = "action 参数为空或者 action 不被支持。"
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,190 +1,190 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
|
||||
namespace UEditor.Core.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// UploadHandler 的摘要说明
|
||||
/// </summary>
|
||||
public class UploadHandler : Handler
|
||||
{
|
||||
|
||||
public UploadConfig UploadConfig { get; set; }
|
||||
public UploadResult Result { get; private set; }
|
||||
|
||||
|
||||
public UploadHandler(HttpContext context)
|
||||
: base(context)
|
||||
{
|
||||
this.Result = new UploadResult() { State = UploadState.Unknown };
|
||||
}
|
||||
|
||||
public override UEditorResult Process()
|
||||
{
|
||||
byte[] uploadFileBytes = null;
|
||||
string uploadFileName = null;
|
||||
|
||||
if (UploadConfig.Base64)
|
||||
{
|
||||
uploadFileName = UploadConfig.Base64Filename;
|
||||
uploadFileBytes = Convert.FromBase64String(Request.Form[UploadConfig.UploadFieldName]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var file = Request.Form.Files[UploadConfig.UploadFieldName];
|
||||
uploadFileName = file.FileName;
|
||||
|
||||
if (!CheckFileType(uploadFileName))
|
||||
{
|
||||
Result.State = UploadState.TypeNotAllow;
|
||||
return WriteResult();
|
||||
}
|
||||
if (!CheckFileSize(file.Length))
|
||||
{
|
||||
Result.State = UploadState.SizeLimitExceed;
|
||||
return WriteResult();
|
||||
|
||||
}
|
||||
uploadFileBytes = new byte[file.Length];
|
||||
try
|
||||
{
|
||||
file.OpenReadStream().Read(uploadFileBytes, 0, (int)file.Length);
|
||||
}
|
||||
|
||||
catch (Exception)
|
||||
{
|
||||
Result.State = UploadState.NetworkError;
|
||||
WriteResult();
|
||||
}
|
||||
}
|
||||
|
||||
Result.OriginFileName = uploadFileName;
|
||||
|
||||
var savePath = PathFormatter.Format(uploadFileName, UploadConfig.PathFormat);
|
||||
|
||||
var localPath = Path.Combine(Config.WebRootPath,savePath);
|
||||
UEditorResult result;
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(Path.GetDirectoryName(localPath)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(localPath));
|
||||
}
|
||||
File.WriteAllBytes(localPath, uploadFileBytes);
|
||||
Result.Url =savePath;
|
||||
Result.State = UploadState.Success;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Result.State = UploadState.FileAccessError;
|
||||
Result.ErrorMessage = e.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
result = WriteResult();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private UEditorResult WriteResult()
|
||||
{
|
||||
return new UEditorResult
|
||||
{
|
||||
State = GetStateMessage(Result.State),
|
||||
Url = Result.Url,
|
||||
Title = Result.OriginFileName,
|
||||
Original = Result.OriginFileName,
|
||||
Error = Result.ErrorMessage
|
||||
};
|
||||
}
|
||||
|
||||
private string GetStateMessage(UploadState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case UploadState.Success:
|
||||
return "SUCCESS";
|
||||
case UploadState.FileAccessError:
|
||||
return "文件访问出错,请检查写入权限";
|
||||
case UploadState.SizeLimitExceed:
|
||||
return "文件大小超出服务器限制";
|
||||
case UploadState.TypeNotAllow:
|
||||
return "不允许的文件格式";
|
||||
case UploadState.NetworkError:
|
||||
return "网络错误";
|
||||
}
|
||||
return "未知错误";
|
||||
}
|
||||
|
||||
private bool CheckFileType(string filename)
|
||||
{
|
||||
var fileExtension = Path.GetExtension(filename).ToLower();
|
||||
return UploadConfig.AllowExtensions.Select(x => x.ToLower()).Contains(fileExtension);
|
||||
}
|
||||
|
||||
private bool CheckFileSize(long size)
|
||||
{
|
||||
return size < UploadConfig.SizeLimit;
|
||||
}
|
||||
}
|
||||
|
||||
public class UploadConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件命名规则
|
||||
/// </summary>
|
||||
public string PathFormat { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上传表单域名称
|
||||
/// </summary>
|
||||
public string UploadFieldName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上传大小限制
|
||||
/// </summary>
|
||||
public int SizeLimit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上传允许的文件格式
|
||||
/// </summary>
|
||||
public string[] AllowExtensions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件是否以 Base64 的形式上传
|
||||
/// </summary>
|
||||
public bool Base64 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Base64 字符串所表示的文件名
|
||||
/// </summary>
|
||||
public string Base64Filename { get; set; }
|
||||
}
|
||||
|
||||
public class UploadResult
|
||||
{
|
||||
public UploadState State { get; set; }
|
||||
public string Url { get; set; }
|
||||
public string OriginFileName { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
}
|
||||
|
||||
public enum UploadState
|
||||
{
|
||||
Success = 0,
|
||||
SizeLimitExceed = -1,
|
||||
TypeNotAllow = -2,
|
||||
FileAccessError = -3,
|
||||
NetworkError = -4,
|
||||
Unknown = 1,
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
|
||||
namespace UEditor.Core.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// UploadHandler 的摘要说明
|
||||
/// </summary>
|
||||
public class UploadHandler : Handler
|
||||
{
|
||||
|
||||
public UploadConfig UploadConfig { get; set; }
|
||||
public UploadResult Result { get; private set; }
|
||||
|
||||
|
||||
public UploadHandler(HttpContext context)
|
||||
: base(context)
|
||||
{
|
||||
this.Result = new UploadResult() { State = UploadState.Unknown };
|
||||
}
|
||||
|
||||
public override UEditorResult Process()
|
||||
{
|
||||
byte[] uploadFileBytes = null;
|
||||
string uploadFileName = null;
|
||||
|
||||
if (UploadConfig.Base64)
|
||||
{
|
||||
uploadFileName = UploadConfig.Base64Filename;
|
||||
uploadFileBytes = Convert.FromBase64String(Request.Form[UploadConfig.UploadFieldName]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var file = Request.Form.Files[UploadConfig.UploadFieldName];
|
||||
uploadFileName = file.FileName;
|
||||
|
||||
if (!CheckFileType(uploadFileName))
|
||||
{
|
||||
Result.State = UploadState.TypeNotAllow;
|
||||
return WriteResult();
|
||||
}
|
||||
if (!CheckFileSize(file.Length))
|
||||
{
|
||||
Result.State = UploadState.SizeLimitExceed;
|
||||
return WriteResult();
|
||||
|
||||
}
|
||||
uploadFileBytes = new byte[file.Length];
|
||||
try
|
||||
{
|
||||
file.OpenReadStream().Read(uploadFileBytes, 0, (int)file.Length);
|
||||
}
|
||||
|
||||
catch (Exception)
|
||||
{
|
||||
Result.State = UploadState.NetworkError;
|
||||
WriteResult();
|
||||
}
|
||||
}
|
||||
|
||||
Result.OriginFileName = uploadFileName;
|
||||
|
||||
var savePath = PathFormatter.Format(uploadFileName, UploadConfig.PathFormat);
|
||||
|
||||
var localPath = Path.Combine(Config.WebRootPath,savePath);
|
||||
UEditorResult result;
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(Path.GetDirectoryName(localPath)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(localPath));
|
||||
}
|
||||
File.WriteAllBytes(localPath, uploadFileBytes);
|
||||
Result.Url =savePath;
|
||||
Result.State = UploadState.Success;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Result.State = UploadState.FileAccessError;
|
||||
Result.ErrorMessage = e.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
result = WriteResult();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private UEditorResult WriteResult()
|
||||
{
|
||||
return new UEditorResult
|
||||
{
|
||||
State = GetStateMessage(Result.State),
|
||||
Url = Result.Url,
|
||||
Title = Result.OriginFileName,
|
||||
Original = Result.OriginFileName,
|
||||
Error = Result.ErrorMessage
|
||||
};
|
||||
}
|
||||
|
||||
private string GetStateMessage(UploadState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case UploadState.Success:
|
||||
return "SUCCESS";
|
||||
case UploadState.FileAccessError:
|
||||
return "文件访问出错,请检查写入权限";
|
||||
case UploadState.SizeLimitExceed:
|
||||
return "文件大小超出服务器限制";
|
||||
case UploadState.TypeNotAllow:
|
||||
return "不允许的文件格式";
|
||||
case UploadState.NetworkError:
|
||||
return "网络错误";
|
||||
}
|
||||
return "未知错误";
|
||||
}
|
||||
|
||||
private bool CheckFileType(string filename)
|
||||
{
|
||||
var fileExtension = Path.GetExtension(filename).ToLower();
|
||||
return UploadConfig.AllowExtensions.Select(x => x.ToLower()).Contains(fileExtension);
|
||||
}
|
||||
|
||||
private bool CheckFileSize(long size)
|
||||
{
|
||||
return size < UploadConfig.SizeLimit;
|
||||
}
|
||||
}
|
||||
|
||||
public class UploadConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件命名规则
|
||||
/// </summary>
|
||||
public string PathFormat { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上传表单域名称
|
||||
/// </summary>
|
||||
public string UploadFieldName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上传大小限制
|
||||
/// </summary>
|
||||
public int SizeLimit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上传允许的文件格式
|
||||
/// </summary>
|
||||
public string[] AllowExtensions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件是否以 Base64 的形式上传
|
||||
/// </summary>
|
||||
public bool Base64 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Base64 字符串所表示的文件名
|
||||
/// </summary>
|
||||
public string Base64Filename { get; set; }
|
||||
}
|
||||
|
||||
public class UploadResult
|
||||
{
|
||||
public UploadState State { get; set; }
|
||||
public string Url { get; set; }
|
||||
public string OriginFileName { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
}
|
||||
|
||||
public enum UploadState
|
||||
{
|
||||
Success = 0,
|
||||
SizeLimitExceed = -1,
|
||||
TypeNotAllow = -2,
|
||||
FileAccessError = -3,
|
||||
NetworkError = -4,
|
||||
Unknown = 1,
|
||||
}
|
||||
}
|
||||
@@ -1,49 +1,49 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace UEditor.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// PathFormater 的摘要说明
|
||||
/// </summary>
|
||||
public static class PathFormatter
|
||||
{
|
||||
public static string Format(string originFileName, string pathFormat)
|
||||
{
|
||||
if (pathFormat.IsNullOrWhiteSpace())
|
||||
{
|
||||
pathFormat = "{filename}{rand:6}";
|
||||
}
|
||||
|
||||
var invalidPattern = new Regex(@"[\\\/\:\*\?\042\<\>\|]");
|
||||
originFileName = invalidPattern.Replace(originFileName, "");
|
||||
|
||||
string extension = Path.GetExtension(originFileName);
|
||||
string filename = Path.GetFileNameWithoutExtension(originFileName);
|
||||
|
||||
pathFormat = pathFormat.Replace("{filename}", filename);
|
||||
pathFormat = new Regex(@"\{rand(\:?)(\d+)\}", RegexOptions.Compiled).Replace(pathFormat, new MatchEvaluator(delegate(Match match)
|
||||
{
|
||||
var digit = 6;
|
||||
if (match.Groups.Count > 2)
|
||||
{
|
||||
digit = Convert.ToInt32(match.Groups[2].Value);
|
||||
}
|
||||
var rand = new Random();
|
||||
return rand.Next((int)Math.Pow(10, digit), (int)Math.Pow(10, digit + 1)).ToString();
|
||||
}));
|
||||
|
||||
pathFormat = pathFormat.Replace("{time}", DateTime.Now.Ticks.ToString());
|
||||
pathFormat = pathFormat.Replace("{yyyy}", DateTime.Now.Year.ToString());
|
||||
pathFormat = pathFormat.Replace("{yy}", (DateTime.Now.Year % 100).ToString("D2"));
|
||||
pathFormat = pathFormat.Replace("{mm}", DateTime.Now.Month.ToString("D2"));
|
||||
pathFormat = pathFormat.Replace("{dd}", DateTime.Now.Day.ToString("D2"));
|
||||
pathFormat = pathFormat.Replace("{hh}", DateTime.Now.Hour.ToString("D2"));
|
||||
pathFormat = pathFormat.Replace("{ii}", DateTime.Now.Minute.ToString("D2"));
|
||||
pathFormat = pathFormat.Replace("{ss}", DateTime.Now.Second.ToString("D2"));
|
||||
|
||||
return pathFormat + extension;
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace UEditor.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// PathFormater 的摘要说明
|
||||
/// </summary>
|
||||
public static class PathFormatter
|
||||
{
|
||||
public static string Format(string originFileName, string pathFormat)
|
||||
{
|
||||
if (pathFormat.IsNullOrWhiteSpace())
|
||||
{
|
||||
pathFormat = "{filename}{rand:6}";
|
||||
}
|
||||
|
||||
var invalidPattern = new Regex(@"[\\\/\:\*\?\042\<\>\|]");
|
||||
originFileName = invalidPattern.Replace(originFileName, "");
|
||||
|
||||
string extension = Path.GetExtension(originFileName);
|
||||
string filename = Path.GetFileNameWithoutExtension(originFileName);
|
||||
|
||||
pathFormat = pathFormat.Replace("{filename}", filename);
|
||||
pathFormat = new Regex(@"\{rand(\:?)(\d+)\}", RegexOptions.Compiled).Replace(pathFormat, new MatchEvaluator(delegate(Match match)
|
||||
{
|
||||
var digit = 6;
|
||||
if (match.Groups.Count > 2)
|
||||
{
|
||||
digit = Convert.ToInt32(match.Groups[2].Value);
|
||||
}
|
||||
var rand = new Random();
|
||||
return rand.Next((int)Math.Pow(10, digit), (int)Math.Pow(10, digit + 1)).ToString();
|
||||
}));
|
||||
|
||||
pathFormat = pathFormat.Replace("{time}", DateTime.Now.Ticks.ToString());
|
||||
pathFormat = pathFormat.Replace("{yyyy}", DateTime.Now.Year.ToString());
|
||||
pathFormat = pathFormat.Replace("{yy}", (DateTime.Now.Year % 100).ToString("D2"));
|
||||
pathFormat = pathFormat.Replace("{mm}", DateTime.Now.Month.ToString("D2"));
|
||||
pathFormat = pathFormat.Replace("{dd}", DateTime.Now.Day.ToString("D2"));
|
||||
pathFormat = pathFormat.Replace("{hh}", DateTime.Now.Hour.ToString("D2"));
|
||||
pathFormat = pathFormat.Replace("{ii}", DateTime.Now.Minute.ToString("D2"));
|
||||
pathFormat = pathFormat.Replace("{ss}", DateTime.Now.Second.ToString("D2"));
|
||||
|
||||
return pathFormat + extension;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace UEditor.Core
|
||||
{
|
||||
public static class StringExtension
|
||||
{
|
||||
public static bool IsNullOrWhiteSpace(this string value)
|
||||
{
|
||||
if (value == null) return true;
|
||||
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
{
|
||||
if (!Char.IsWhiteSpace(value[i])) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace UEditor.Core
|
||||
{
|
||||
public static class StringExtension
|
||||
{
|
||||
public static bool IsNullOrWhiteSpace(this string value)
|
||||
{
|
||||
if (value == null) return true;
|
||||
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
{
|
||||
if (!Char.IsWhiteSpace(value[i])) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
|
||||
using Hncore.Pass.Vpn.Service;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
|
||||
namespace UEditor.Core
|
||||
{
|
||||
public static class UEditorMvcExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// 添加UEditor后端服务
|
||||
/// </summary>
|
||||
/// <param name="services">IServiceCollection</param>
|
||||
/// <param name="configFileRelativePath">配置文件相对路径</param>
|
||||
/// <param name="isCacheConfig">是否缓存配置文件</param>
|
||||
/// <param name="basePath">配置文件、文件存储路径等各种路径的根目录,默认为Web项目的根目录</param>
|
||||
public static void AddUEditorService(this IServiceCollection services,
|
||||
string configFileRelativePath = "ueditor.json",
|
||||
bool isCacheConfig = true,
|
||||
string basePath = "")
|
||||
{
|
||||
|
||||
Config.ConfigFile = configFileRelativePath;
|
||||
Config.NoCache = isCacheConfig;
|
||||
Config.WebRootPath = basePath;
|
||||
services.AddScoped<UploadService>();
|
||||
services.TryAddSingleton<UEditorService>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
using Hncore.Pass.Vpn.Service;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
|
||||
namespace UEditor.Core
|
||||
{
|
||||
public static class UEditorMvcExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// 添加UEditor后端服务
|
||||
/// </summary>
|
||||
/// <param name="services">IServiceCollection</param>
|
||||
/// <param name="configFileRelativePath">配置文件相对路径</param>
|
||||
/// <param name="isCacheConfig">是否缓存配置文件</param>
|
||||
/// <param name="basePath">配置文件、文件存储路径等各种路径的根目录,默认为Web项目的根目录</param>
|
||||
public static void AddUEditorService(this IServiceCollection services,
|
||||
string configFileRelativePath = "ueditor.json",
|
||||
bool isCacheConfig = true,
|
||||
string basePath = "")
|
||||
{
|
||||
|
||||
Config.ConfigFile = configFileRelativePath;
|
||||
Config.NoCache = isCacheConfig;
|
||||
Config.WebRootPath = basePath;
|
||||
services.AddScoped<UploadService>();
|
||||
services.TryAddSingleton<UEditorService>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
namespace UEditor.Core
|
||||
{
|
||||
public class UEditorResponse
|
||||
{
|
||||
|
||||
public UEditorResponse(string contentType, string result)
|
||||
{
|
||||
ContentType = contentType;
|
||||
Result = result;
|
||||
}
|
||||
|
||||
public string ContentType { get; set; }
|
||||
|
||||
public string Result { get; set; }
|
||||
}
|
||||
}
|
||||
namespace UEditor.Core
|
||||
{
|
||||
public class UEditorResponse
|
||||
{
|
||||
|
||||
public UEditorResponse(string contentType, string result)
|
||||
{
|
||||
ContentType = contentType;
|
||||
Result = result;
|
||||
}
|
||||
|
||||
public string ContentType { get; set; }
|
||||
|
||||
public string Result { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +1,50 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UEditor.Core
|
||||
{
|
||||
public class UEditorResult
|
||||
{
|
||||
[JsonProperty("state")]
|
||||
public string State { get; set; }
|
||||
|
||||
[JsonProperty("list")]
|
||||
public IEnumerable<UEditorFileList> List { get; set; }
|
||||
|
||||
[JsonProperty("start")]
|
||||
public int? Start { get; set; }
|
||||
|
||||
[JsonProperty("size")]
|
||||
public int? Size { get; set; }
|
||||
|
||||
[JsonProperty("source")]
|
||||
public string Source { get; set; }
|
||||
|
||||
[JsonProperty("total")]
|
||||
public int? Total { get; set; }
|
||||
|
||||
[JsonProperty("url")]
|
||||
public string Url { get; set; }
|
||||
|
||||
[JsonProperty("title")]
|
||||
public string Title { get; set; }
|
||||
|
||||
[JsonProperty("original")]
|
||||
public string Original { get; set; }
|
||||
|
||||
[JsonProperty("error")]
|
||||
public string Error { get; set; }
|
||||
}
|
||||
|
||||
public class UEditorFileList
|
||||
{
|
||||
[JsonProperty("state")]
|
||||
public string State { get; set; }
|
||||
|
||||
[JsonProperty("source")]
|
||||
public string Source { get; set; }
|
||||
|
||||
[JsonProperty("url")]
|
||||
public string Url { get; set; }
|
||||
}
|
||||
}
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UEditor.Core
|
||||
{
|
||||
public class UEditorResult
|
||||
{
|
||||
[JsonProperty("state")]
|
||||
public string State { get; set; }
|
||||
|
||||
[JsonProperty("list")]
|
||||
public IEnumerable<UEditorFileList> List { get; set; }
|
||||
|
||||
[JsonProperty("start")]
|
||||
public int? Start { get; set; }
|
||||
|
||||
[JsonProperty("size")]
|
||||
public int? Size { get; set; }
|
||||
|
||||
[JsonProperty("source")]
|
||||
public string Source { get; set; }
|
||||
|
||||
[JsonProperty("total")]
|
||||
public int? Total { get; set; }
|
||||
|
||||
[JsonProperty("url")]
|
||||
public string Url { get; set; }
|
||||
|
||||
[JsonProperty("title")]
|
||||
public string Title { get; set; }
|
||||
|
||||
[JsonProperty("original")]
|
||||
public string Original { get; set; }
|
||||
|
||||
[JsonProperty("error")]
|
||||
public string Error { get; set; }
|
||||
}
|
||||
|
||||
public class UEditorFileList
|
||||
{
|
||||
[JsonProperty("state")]
|
||||
public string State { get; set; }
|
||||
|
||||
[JsonProperty("source")]
|
||||
public string Source { get; set; }
|
||||
|
||||
[JsonProperty("url")]
|
||||
public string Url { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,96 +1,96 @@
|
||||
#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;
|
||||
}
|
||||
}
|
||||
}
|
||||
#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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
using Aliyun.OSS;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.OSS.Utils
|
||||
{
|
||||
public static class AliOssClientExt
|
||||
{
|
||||
public static IServiceCollection AddAliOssClient(this IServiceCollection services, string AliEndpoint, string AliAccessId, string AliAccessKey)
|
||||
{
|
||||
OssClient client = new OssClient(AliEndpoint, AliAccessId, AliAccessKey);
|
||||
services.AddSingleton(client);
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
using Aliyun.OSS;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hncore.Pass.OSS.Utils
|
||||
{
|
||||
public static class AliOssClientExt
|
||||
{
|
||||
public static IServiceCollection AddAliOssClient(this IServiceCollection services, string AliEndpoint, string AliAccessId, string AliAccessKey)
|
||||
{
|
||||
OssClient client = new OssClient(AliEndpoint, AliAccessId, AliAccessKey);
|
||||
services.AddSingleton(client);
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"System": "Information",
|
||||
"Microsoft": "Information"
|
||||
}
|
||||
},
|
||||
"Aliyun": {
|
||||
"Oss": {
|
||||
"AliEndpoint": "oss-cn-shenzhen.aliyuncs.com",
|
||||
"AliAccessId": "dpisQKVqzAYffodY",
|
||||
"AliAccessKey": "ZG3uAkwPR4UpfsTJzG9DW1WeKIskHz"
|
||||
|
||||
}
|
||||
}
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"System": "Information",
|
||||
"Microsoft": "Information"
|
||||
}
|
||||
},
|
||||
"Aliyun": {
|
||||
"Oss": {
|
||||
"AliEndpoint": "oss-cn-shenzhen.aliyuncs.com",
|
||||
"AliAccessId": "dpisQKVqzAYffodY",
|
||||
"AliAccessKey": "ZG3uAkwPR4UpfsTJzG9DW1WeKIskHz"
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,180 +1,180 @@
|
||||
/* 前后端通信相关的配置,注释只允许使用多行方式 */
|
||||
{
|
||||
/* 上传图片配置项 */
|
||||
"imageActionName": "uploadimage", /* 执行上传图片的action名称 */
|
||||
"imageFieldName": "upfile", /* 提交的图片表单名称 */
|
||||
"imageMaxSize": 2048000, /* 上传大小限制,单位B */
|
||||
"imageAllowFiles": [ ".png", ".jpg", ".jpeg", ".gif", ".bmp" ], /* 上传图片格式显示 */
|
||||
"imageCompressEnable": true, /* 是否压缩图片,默认是true */
|
||||
"imageCompressBorder": 1600, /* 图片压缩最长边限制 */
|
||||
"imageInsertAlign": "none", /* 插入的图片浮动方式 */
|
||||
"imageUrlPrefix": "http://xxx.com", /* 图片访问路径前缀 */
|
||||
"imagePathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
/* {filename} 会替换成原文件名,配置这项需要注意中文乱码问题 */
|
||||
/* {rand:6} 会替换成随机数,后面的数字是随机数的位数 */
|
||||
/* {time} 会替换成时间戳 */
|
||||
/* {yyyy} 会替换成四位年份 */
|
||||
/* {yy} 会替换成两位年份 */
|
||||
/* {mm} 会替换成两位月份 */
|
||||
/* {dd} 会替换成两位日期 */
|
||||
/* {hh} 会替换成两位小时 */
|
||||
/* {ii} 会替换成两位分钟 */
|
||||
/* {ss} 会替换成两位秒 */
|
||||
/* 非法字符 \ : * ? " < > | */
|
||||
/* 具请体看线上文档: fex.baidu.com/ueditor/#use-format_upload_filename */
|
||||
|
||||
/* 涂鸦图片上传配置项 */
|
||||
"scrawlActionName": "uploadscrawl", /* 执行上传涂鸦的action名称 */
|
||||
"scrawlFieldName": "upfile", /* 提交的图片表单名称 */
|
||||
"scrawlPathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"scrawlMaxSize": 2048000, /* 上传大小限制,单位B */
|
||||
"scrawlUrlPrefix": "http://xxx.com", /* 图片访问路径前缀 */
|
||||
"scrawlInsertAlign": "none",
|
||||
|
||||
/* 截图工具上传 */
|
||||
"snapscreenActionName": "uploadimage", /* 执行上传截图的action名称 */
|
||||
"snapscreenPathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"snapscreenUrlPrefix": "http://xxx.com", /* 图片访问路径前缀 */
|
||||
"snapscreenInsertAlign": "none", /* 插入的图片浮动方式 */
|
||||
|
||||
/* 抓取远程图片配置 */
|
||||
"catcherLocalDomain": [ "127.0.0.1", "localhost", "img.baidu.com" ],
|
||||
"catcherActionName": "catchimage", /* 执行抓取远程图片的action名称 */
|
||||
"catcherFieldName": "source", /* 提交的图片列表表单名称 */
|
||||
"catcherPathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"catcherUrlPrefix": "http://xxx.com", /* 图片访问路径前缀 */
|
||||
"catcherMaxSize": 2048000, /* 上传大小限制,单位B */
|
||||
"catcherAllowFiles": [ ".png", ".jpg", ".jpeg", ".gif", ".bmp" ], /* 抓取图片格式显示 */
|
||||
|
||||
/* 上传视频配置 */
|
||||
"videoActionName": "uploadvideo", /* 执行上传视频的action名称 */
|
||||
"videoFieldName": "upfile", /* 提交的视频表单名称 */
|
||||
"videoPathFormat": "upload/video/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"videoUrlPrefix": "http://xxx.com/", /* 视频访问路径前缀 */
|
||||
"videoMaxSize": 102400000, /* 上传大小限制,单位B,默认100MB */
|
||||
"videoAllowFiles": [
|
||||
".flv",
|
||||
".swf",
|
||||
".mkv",
|
||||
".avi",
|
||||
".rm",
|
||||
".rmvb",
|
||||
".mpeg",
|
||||
".mpg",
|
||||
".ogg",
|
||||
".ogv",
|
||||
".mov",
|
||||
".wmv",
|
||||
".mp4",
|
||||
".webm",
|
||||
".mp3",
|
||||
".wav",
|
||||
".mid"
|
||||
], /* 上传视频格式显示 */
|
||||
|
||||
/* 上传文件配置 */
|
||||
"fileActionName": "uploadfile", /* controller里,执行上传视频的action名称 */
|
||||
"fileFieldName": "upfile", /* 提交的文件表单名称 */
|
||||
"filePathFormat": "upload/file/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"fileUrlPrefix": "http://xxx.com", /* 文件访问路径前缀 */
|
||||
"fileMaxSize": 51200000, /* 上传大小限制,单位B,默认50MB */
|
||||
"fileAllowFiles": [
|
||||
".png",
|
||||
".jpg",
|
||||
".jpeg",
|
||||
".gif",
|
||||
".bmp",
|
||||
".flv",
|
||||
".swf",
|
||||
".mkv",
|
||||
".avi",
|
||||
".rm",
|
||||
".rmvb",
|
||||
".mpeg",
|
||||
".mpg",
|
||||
".ogg",
|
||||
".ogv",
|
||||
".mov",
|
||||
".wmv",
|
||||
".mp4",
|
||||
".webm",
|
||||
".mp3",
|
||||
".wav",
|
||||
".mid",
|
||||
".rar",
|
||||
".zip",
|
||||
".tar",
|
||||
".gz",
|
||||
".7z",
|
||||
".bz2",
|
||||
".cab",
|
||||
".iso",
|
||||
".doc",
|
||||
".docx",
|
||||
".xls",
|
||||
".xlsx",
|
||||
".ppt",
|
||||
".pptx",
|
||||
".pdf",
|
||||
".txt",
|
||||
".md",
|
||||
".xml"
|
||||
], /* 上传文件格式显示 */
|
||||
|
||||
/* 列出指定目录下的图片 */
|
||||
"imageManagerActionName": "listimage", /* 执行图片管理的action名称 */
|
||||
"imageManagerListPath": "upload/image", /* 指定要列出图片的目录 */
|
||||
"imageManagerListSize": 20, /* 每次列出文件数量 */
|
||||
"imageManagerUrlPrefix": "http://xxx.com", /* 图片访问路径前缀 */
|
||||
"imageManagerInsertAlign": "none", /* 插入的图片浮动方式 */
|
||||
"imageManagerAllowFiles": [ ".png", ".jpg", ".jpeg", ".gif", ".bmp" ], /* 列出的文件类型 */
|
||||
|
||||
/* 列出指定目录下的文件 */
|
||||
"fileManagerActionName": "listfile", /* 执行文件管理的action名称 */
|
||||
"fileManagerListPath": "upload/file", /* 指定要列出文件的目录 */
|
||||
"fileManagerUrlPrefix": "http://xxx.com", /* 文件访问路径前缀 */
|
||||
"fileManagerListSize": 20, /* 每次列出文件数量 */
|
||||
"fileManagerAllowFiles": [
|
||||
".png",
|
||||
".jpg",
|
||||
".jpeg",
|
||||
".gif",
|
||||
".bmp",
|
||||
".flv",
|
||||
".swf",
|
||||
".mkv",
|
||||
".avi",
|
||||
".rm",
|
||||
".rmvb",
|
||||
".mpeg",
|
||||
".mpg",
|
||||
".ogg",
|
||||
".ogv",
|
||||
".mov",
|
||||
".wmv",
|
||||
".mp4",
|
||||
".webm",
|
||||
".mp3",
|
||||
".wav",
|
||||
".mid",
|
||||
".rar",
|
||||
".zip",
|
||||
".tar",
|
||||
".gz",
|
||||
".7z",
|
||||
".bz2",
|
||||
".cab",
|
||||
".iso",
|
||||
".doc",
|
||||
".docx",
|
||||
".xls",
|
||||
".xlsx",
|
||||
".ppt",
|
||||
".pptx",
|
||||
".pdf",
|
||||
".txt",
|
||||
".md",
|
||||
".xml"
|
||||
] /* 列出的文件类型 */
|
||||
|
||||
/* 前后端通信相关的配置,注释只允许使用多行方式 */
|
||||
{
|
||||
/* 上传图片配置项 */
|
||||
"imageActionName": "uploadimage", /* 执行上传图片的action名称 */
|
||||
"imageFieldName": "upfile", /* 提交的图片表单名称 */
|
||||
"imageMaxSize": 2048000, /* 上传大小限制,单位B */
|
||||
"imageAllowFiles": [ ".png", ".jpg", ".jpeg", ".gif", ".bmp" ], /* 上传图片格式显示 */
|
||||
"imageCompressEnable": true, /* 是否压缩图片,默认是true */
|
||||
"imageCompressBorder": 1600, /* 图片压缩最长边限制 */
|
||||
"imageInsertAlign": "none", /* 插入的图片浮动方式 */
|
||||
"imageUrlPrefix": "http://xxx.com", /* 图片访问路径前缀 */
|
||||
"imagePathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
/* {filename} 会替换成原文件名,配置这项需要注意中文乱码问题 */
|
||||
/* {rand:6} 会替换成随机数,后面的数字是随机数的位数 */
|
||||
/* {time} 会替换成时间戳 */
|
||||
/* {yyyy} 会替换成四位年份 */
|
||||
/* {yy} 会替换成两位年份 */
|
||||
/* {mm} 会替换成两位月份 */
|
||||
/* {dd} 会替换成两位日期 */
|
||||
/* {hh} 会替换成两位小时 */
|
||||
/* {ii} 会替换成两位分钟 */
|
||||
/* {ss} 会替换成两位秒 */
|
||||
/* 非法字符 \ : * ? " < > | */
|
||||
/* 具请体看线上文档: fex.baidu.com/ueditor/#use-format_upload_filename */
|
||||
|
||||
/* 涂鸦图片上传配置项 */
|
||||
"scrawlActionName": "uploadscrawl", /* 执行上传涂鸦的action名称 */
|
||||
"scrawlFieldName": "upfile", /* 提交的图片表单名称 */
|
||||
"scrawlPathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"scrawlMaxSize": 2048000, /* 上传大小限制,单位B */
|
||||
"scrawlUrlPrefix": "http://xxx.com", /* 图片访问路径前缀 */
|
||||
"scrawlInsertAlign": "none",
|
||||
|
||||
/* 截图工具上传 */
|
||||
"snapscreenActionName": "uploadimage", /* 执行上传截图的action名称 */
|
||||
"snapscreenPathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"snapscreenUrlPrefix": "http://xxx.com", /* 图片访问路径前缀 */
|
||||
"snapscreenInsertAlign": "none", /* 插入的图片浮动方式 */
|
||||
|
||||
/* 抓取远程图片配置 */
|
||||
"catcherLocalDomain": [ "127.0.0.1", "localhost", "img.baidu.com" ],
|
||||
"catcherActionName": "catchimage", /* 执行抓取远程图片的action名称 */
|
||||
"catcherFieldName": "source", /* 提交的图片列表表单名称 */
|
||||
"catcherPathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"catcherUrlPrefix": "http://xxx.com", /* 图片访问路径前缀 */
|
||||
"catcherMaxSize": 2048000, /* 上传大小限制,单位B */
|
||||
"catcherAllowFiles": [ ".png", ".jpg", ".jpeg", ".gif", ".bmp" ], /* 抓取图片格式显示 */
|
||||
|
||||
/* 上传视频配置 */
|
||||
"videoActionName": "uploadvideo", /* 执行上传视频的action名称 */
|
||||
"videoFieldName": "upfile", /* 提交的视频表单名称 */
|
||||
"videoPathFormat": "upload/video/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"videoUrlPrefix": "http://xxx.com/", /* 视频访问路径前缀 */
|
||||
"videoMaxSize": 102400000, /* 上传大小限制,单位B,默认100MB */
|
||||
"videoAllowFiles": [
|
||||
".flv",
|
||||
".swf",
|
||||
".mkv",
|
||||
".avi",
|
||||
".rm",
|
||||
".rmvb",
|
||||
".mpeg",
|
||||
".mpg",
|
||||
".ogg",
|
||||
".ogv",
|
||||
".mov",
|
||||
".wmv",
|
||||
".mp4",
|
||||
".webm",
|
||||
".mp3",
|
||||
".wav",
|
||||
".mid"
|
||||
], /* 上传视频格式显示 */
|
||||
|
||||
/* 上传文件配置 */
|
||||
"fileActionName": "uploadfile", /* controller里,执行上传视频的action名称 */
|
||||
"fileFieldName": "upfile", /* 提交的文件表单名称 */
|
||||
"filePathFormat": "upload/file/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"fileUrlPrefix": "http://xxx.com", /* 文件访问路径前缀 */
|
||||
"fileMaxSize": 51200000, /* 上传大小限制,单位B,默认50MB */
|
||||
"fileAllowFiles": [
|
||||
".png",
|
||||
".jpg",
|
||||
".jpeg",
|
||||
".gif",
|
||||
".bmp",
|
||||
".flv",
|
||||
".swf",
|
||||
".mkv",
|
||||
".avi",
|
||||
".rm",
|
||||
".rmvb",
|
||||
".mpeg",
|
||||
".mpg",
|
||||
".ogg",
|
||||
".ogv",
|
||||
".mov",
|
||||
".wmv",
|
||||
".mp4",
|
||||
".webm",
|
||||
".mp3",
|
||||
".wav",
|
||||
".mid",
|
||||
".rar",
|
||||
".zip",
|
||||
".tar",
|
||||
".gz",
|
||||
".7z",
|
||||
".bz2",
|
||||
".cab",
|
||||
".iso",
|
||||
".doc",
|
||||
".docx",
|
||||
".xls",
|
||||
".xlsx",
|
||||
".ppt",
|
||||
".pptx",
|
||||
".pdf",
|
||||
".txt",
|
||||
".md",
|
||||
".xml"
|
||||
], /* 上传文件格式显示 */
|
||||
|
||||
/* 列出指定目录下的图片 */
|
||||
"imageManagerActionName": "listimage", /* 执行图片管理的action名称 */
|
||||
"imageManagerListPath": "upload/image", /* 指定要列出图片的目录 */
|
||||
"imageManagerListSize": 20, /* 每次列出文件数量 */
|
||||
"imageManagerUrlPrefix": "http://xxx.com", /* 图片访问路径前缀 */
|
||||
"imageManagerInsertAlign": "none", /* 插入的图片浮动方式 */
|
||||
"imageManagerAllowFiles": [ ".png", ".jpg", ".jpeg", ".gif", ".bmp" ], /* 列出的文件类型 */
|
||||
|
||||
/* 列出指定目录下的文件 */
|
||||
"fileManagerActionName": "listfile", /* 执行文件管理的action名称 */
|
||||
"fileManagerListPath": "upload/file", /* 指定要列出文件的目录 */
|
||||
"fileManagerUrlPrefix": "http://xxx.com", /* 文件访问路径前缀 */
|
||||
"fileManagerListSize": 20, /* 每次列出文件数量 */
|
||||
"fileManagerAllowFiles": [
|
||||
".png",
|
||||
".jpg",
|
||||
".jpeg",
|
||||
".gif",
|
||||
".bmp",
|
||||
".flv",
|
||||
".swf",
|
||||
".mkv",
|
||||
".avi",
|
||||
".rm",
|
||||
".rmvb",
|
||||
".mpeg",
|
||||
".mpg",
|
||||
".ogg",
|
||||
".ogv",
|
||||
".mov",
|
||||
".wmv",
|
||||
".mp4",
|
||||
".webm",
|
||||
".mp3",
|
||||
".wav",
|
||||
".mid",
|
||||
".rar",
|
||||
".zip",
|
||||
".tar",
|
||||
".gz",
|
||||
".7z",
|
||||
".bz2",
|
||||
".cab",
|
||||
".iso",
|
||||
".doc",
|
||||
".docx",
|
||||
".xls",
|
||||
".xlsx",
|
||||
".ppt",
|
||||
".pptx",
|
||||
".pdf",
|
||||
".txt",
|
||||
".md",
|
||||
".xml"
|
||||
] /* 列出的文件类型 */
|
||||
|
||||
}
|
||||
@@ -1,180 +1,180 @@
|
||||
/* 前后端通信相关的配置,注释只允许使用多行方式 */
|
||||
{
|
||||
/* 上传图片配置项 */
|
||||
"imageActionName": "uploadimage", /* 执行上传图片的action名称 */
|
||||
"imageFieldName": "upfile", /* 提交的图片表单名称 */
|
||||
"imageMaxSize": 2048000, /* 上传大小限制,单位B */
|
||||
"imageAllowFiles": [ ".png", ".jpg", ".jpeg", ".gif", ".bmp" ], /* 上传图片格式显示 */
|
||||
"imageCompressEnable": true, /* 是否压缩图片,默认是true */
|
||||
"imageCompressBorder": 1600, /* 图片压缩最长边限制 */
|
||||
"imageInsertAlign": "none", /* 插入的图片浮动方式 */
|
||||
"imageUrlPrefix": "http://localhost:64279/", /* 图片访问路径前缀 */
|
||||
"imagePathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
/* {filename} 会替换成原文件名,配置这项需要注意中文乱码问题 */
|
||||
/* {rand:6} 会替换成随机数,后面的数字是随机数的位数 */
|
||||
/* {time} 会替换成时间戳 */
|
||||
/* {yyyy} 会替换成四位年份 */
|
||||
/* {yy} 会替换成两位年份 */
|
||||
/* {mm} 会替换成两位月份 */
|
||||
/* {dd} 会替换成两位日期 */
|
||||
/* {hh} 会替换成两位小时 */
|
||||
/* {ii} 会替换成两位分钟 */
|
||||
/* {ss} 会替换成两位秒 */
|
||||
/* 非法字符 \ : * ? " < > | */
|
||||
/* 具请体看线上文档: fex.baidu.com/ueditor/#use-format_upload_filename */
|
||||
|
||||
/* 涂鸦图片上传配置项 */
|
||||
"scrawlActionName": "uploadscrawl", /* 执行上传涂鸦的action名称 */
|
||||
"scrawlFieldName": "upfile", /* 提交的图片表单名称 */
|
||||
"scrawlPathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"scrawlMaxSize": 2048000, /* 上传大小限制,单位B */
|
||||
"scrawlUrlPrefix": "http://localhost:64279/", /* 图片访问路径前缀 */
|
||||
"scrawlInsertAlign": "none",
|
||||
|
||||
/* 截图工具上传 */
|
||||
"snapscreenActionName": "uploadimage", /* 执行上传截图的action名称 */
|
||||
"snapscreenPathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"snapscreenUrlPrefix": "http://localhost:64279/", /* 图片访问路径前缀 */
|
||||
"snapscreenInsertAlign": "none", /* 插入的图片浮动方式 */
|
||||
|
||||
/* 抓取远程图片配置 */
|
||||
"catcherLocalDomain": [ "127.0.0.1", "localhost", "img.baidu.com" ],
|
||||
"catcherActionName": "catchimage", /* 执行抓取远程图片的action名称 */
|
||||
"catcherFieldName": "source", /* 提交的图片列表表单名称 */
|
||||
"catcherPathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"catcherUrlPrefix": "http://localhost:64279/", /* 图片访问路径前缀 */
|
||||
"catcherMaxSize": 2048000, /* 上传大小限制,单位B */
|
||||
"catcherAllowFiles": [ ".png", ".jpg", ".jpeg", ".gif", ".bmp" ], /* 抓取图片格式显示 */
|
||||
|
||||
/* 上传视频配置 */
|
||||
"videoActionName": "uploadvideo", /* 执行上传视频的action名称 */
|
||||
"videoFieldName": "upfile", /* 提交的视频表单名称 */
|
||||
"videoPathFormat": "upload/video/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"videoUrlPrefix": "http://localhost:64279/", /* 视频访问路径前缀 */
|
||||
"videoMaxSize": 102400000, /* 上传大小限制,单位B,默认100MB */
|
||||
"videoAllowFiles": [
|
||||
".flv",
|
||||
".swf",
|
||||
".mkv",
|
||||
".avi",
|
||||
".rm",
|
||||
".rmvb",
|
||||
".mpeg",
|
||||
".mpg",
|
||||
".ogg",
|
||||
".ogv",
|
||||
".mov",
|
||||
".wmv",
|
||||
".mp4",
|
||||
".webm",
|
||||
".mp3",
|
||||
".wav",
|
||||
".mid"
|
||||
], /* 上传视频格式显示 */
|
||||
|
||||
/* 上传文件配置 */
|
||||
"fileActionName": "uploadfile", /* controller里,执行上传视频的action名称 */
|
||||
"fileFieldName": "upfile", /* 提交的文件表单名称 */
|
||||
"filePathFormat": "upload/file/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"fileUrlPrefix": "http://localhost:64279/", /* 文件访问路径前缀 */
|
||||
"fileMaxSize": 51200000, /* 上传大小限制,单位B,默认50MB */
|
||||
"fileAllowFiles": [
|
||||
".png",
|
||||
".jpg",
|
||||
".jpeg",
|
||||
".gif",
|
||||
".bmp",
|
||||
".flv",
|
||||
".swf",
|
||||
".mkv",
|
||||
".avi",
|
||||
".rm",
|
||||
".rmvb",
|
||||
".mpeg",
|
||||
".mpg",
|
||||
".ogg",
|
||||
".ogv",
|
||||
".mov",
|
||||
".wmv",
|
||||
".mp4",
|
||||
".webm",
|
||||
".mp3",
|
||||
".wav",
|
||||
".mid",
|
||||
".rar",
|
||||
".zip",
|
||||
".tar",
|
||||
".gz",
|
||||
".7z",
|
||||
".bz2",
|
||||
".cab",
|
||||
".iso",
|
||||
".doc",
|
||||
".docx",
|
||||
".xls",
|
||||
".xlsx",
|
||||
".ppt",
|
||||
".pptx",
|
||||
".pdf",
|
||||
".txt",
|
||||
".md",
|
||||
".xml"
|
||||
], /* 上传文件格式显示 */
|
||||
|
||||
/* 列出指定目录下的图片 */
|
||||
"imageManagerActionName": "listimage", /* 执行图片管理的action名称 */
|
||||
"imageManagerListPath": "upload/image", /* 指定要列出图片的目录 */
|
||||
"imageManagerListSize": 20, /* 每次列出文件数量 */
|
||||
"imageManagerUrlPrefix": "http://localhost:64279/", /* 图片访问路径前缀 */
|
||||
"imageManagerInsertAlign": "none", /* 插入的图片浮动方式 */
|
||||
"imageManagerAllowFiles": [ ".png", ".jpg", ".jpeg", ".gif", ".bmp" ], /* 列出的文件类型 */
|
||||
|
||||
/* 列出指定目录下的文件 */
|
||||
"fileManagerActionName": "listfile", /* 执行文件管理的action名称 */
|
||||
"fileManagerListPath": "upload/file", /* 指定要列出文件的目录 */
|
||||
"fileManagerUrlPrefix": "http://localhost:64279/", /* 文件访问路径前缀 */
|
||||
"fileManagerListSize": 20, /* 每次列出文件数量 */
|
||||
"fileManagerAllowFiles": [
|
||||
".png",
|
||||
".jpg",
|
||||
".jpeg",
|
||||
".gif",
|
||||
".bmp",
|
||||
".flv",
|
||||
".swf",
|
||||
".mkv",
|
||||
".avi",
|
||||
".rm",
|
||||
".rmvb",
|
||||
".mpeg",
|
||||
".mpg",
|
||||
".ogg",
|
||||
".ogv",
|
||||
".mov",
|
||||
".wmv",
|
||||
".mp4",
|
||||
".webm",
|
||||
".mp3",
|
||||
".wav",
|
||||
".mid",
|
||||
".rar",
|
||||
".zip",
|
||||
".tar",
|
||||
".gz",
|
||||
".7z",
|
||||
".bz2",
|
||||
".cab",
|
||||
".iso",
|
||||
".doc",
|
||||
".docx",
|
||||
".xls",
|
||||
".xlsx",
|
||||
".ppt",
|
||||
".pptx",
|
||||
".pdf",
|
||||
".txt",
|
||||
".md",
|
||||
".xml"
|
||||
] /* 列出的文件类型 */
|
||||
|
||||
/* 前后端通信相关的配置,注释只允许使用多行方式 */
|
||||
{
|
||||
/* 上传图片配置项 */
|
||||
"imageActionName": "uploadimage", /* 执行上传图片的action名称 */
|
||||
"imageFieldName": "upfile", /* 提交的图片表单名称 */
|
||||
"imageMaxSize": 2048000, /* 上传大小限制,单位B */
|
||||
"imageAllowFiles": [ ".png", ".jpg", ".jpeg", ".gif", ".bmp" ], /* 上传图片格式显示 */
|
||||
"imageCompressEnable": true, /* 是否压缩图片,默认是true */
|
||||
"imageCompressBorder": 1600, /* 图片压缩最长边限制 */
|
||||
"imageInsertAlign": "none", /* 插入的图片浮动方式 */
|
||||
"imageUrlPrefix": "http://localhost:64279/", /* 图片访问路径前缀 */
|
||||
"imagePathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
/* {filename} 会替换成原文件名,配置这项需要注意中文乱码问题 */
|
||||
/* {rand:6} 会替换成随机数,后面的数字是随机数的位数 */
|
||||
/* {time} 会替换成时间戳 */
|
||||
/* {yyyy} 会替换成四位年份 */
|
||||
/* {yy} 会替换成两位年份 */
|
||||
/* {mm} 会替换成两位月份 */
|
||||
/* {dd} 会替换成两位日期 */
|
||||
/* {hh} 会替换成两位小时 */
|
||||
/* {ii} 会替换成两位分钟 */
|
||||
/* {ss} 会替换成两位秒 */
|
||||
/* 非法字符 \ : * ? " < > | */
|
||||
/* 具请体看线上文档: fex.baidu.com/ueditor/#use-format_upload_filename */
|
||||
|
||||
/* 涂鸦图片上传配置项 */
|
||||
"scrawlActionName": "uploadscrawl", /* 执行上传涂鸦的action名称 */
|
||||
"scrawlFieldName": "upfile", /* 提交的图片表单名称 */
|
||||
"scrawlPathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"scrawlMaxSize": 2048000, /* 上传大小限制,单位B */
|
||||
"scrawlUrlPrefix": "http://localhost:64279/", /* 图片访问路径前缀 */
|
||||
"scrawlInsertAlign": "none",
|
||||
|
||||
/* 截图工具上传 */
|
||||
"snapscreenActionName": "uploadimage", /* 执行上传截图的action名称 */
|
||||
"snapscreenPathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"snapscreenUrlPrefix": "http://localhost:64279/", /* 图片访问路径前缀 */
|
||||
"snapscreenInsertAlign": "none", /* 插入的图片浮动方式 */
|
||||
|
||||
/* 抓取远程图片配置 */
|
||||
"catcherLocalDomain": [ "127.0.0.1", "localhost", "img.baidu.com" ],
|
||||
"catcherActionName": "catchimage", /* 执行抓取远程图片的action名称 */
|
||||
"catcherFieldName": "source", /* 提交的图片列表表单名称 */
|
||||
"catcherPathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"catcherUrlPrefix": "http://localhost:64279/", /* 图片访问路径前缀 */
|
||||
"catcherMaxSize": 2048000, /* 上传大小限制,单位B */
|
||||
"catcherAllowFiles": [ ".png", ".jpg", ".jpeg", ".gif", ".bmp" ], /* 抓取图片格式显示 */
|
||||
|
||||
/* 上传视频配置 */
|
||||
"videoActionName": "uploadvideo", /* 执行上传视频的action名称 */
|
||||
"videoFieldName": "upfile", /* 提交的视频表单名称 */
|
||||
"videoPathFormat": "upload/video/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"videoUrlPrefix": "http://localhost:64279/", /* 视频访问路径前缀 */
|
||||
"videoMaxSize": 102400000, /* 上传大小限制,单位B,默认100MB */
|
||||
"videoAllowFiles": [
|
||||
".flv",
|
||||
".swf",
|
||||
".mkv",
|
||||
".avi",
|
||||
".rm",
|
||||
".rmvb",
|
||||
".mpeg",
|
||||
".mpg",
|
||||
".ogg",
|
||||
".ogv",
|
||||
".mov",
|
||||
".wmv",
|
||||
".mp4",
|
||||
".webm",
|
||||
".mp3",
|
||||
".wav",
|
||||
".mid"
|
||||
], /* 上传视频格式显示 */
|
||||
|
||||
/* 上传文件配置 */
|
||||
"fileActionName": "uploadfile", /* controller里,执行上传视频的action名称 */
|
||||
"fileFieldName": "upfile", /* 提交的文件表单名称 */
|
||||
"filePathFormat": "upload/file/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"fileUrlPrefix": "http://localhost:64279/", /* 文件访问路径前缀 */
|
||||
"fileMaxSize": 51200000, /* 上传大小限制,单位B,默认50MB */
|
||||
"fileAllowFiles": [
|
||||
".png",
|
||||
".jpg",
|
||||
".jpeg",
|
||||
".gif",
|
||||
".bmp",
|
||||
".flv",
|
||||
".swf",
|
||||
".mkv",
|
||||
".avi",
|
||||
".rm",
|
||||
".rmvb",
|
||||
".mpeg",
|
||||
".mpg",
|
||||
".ogg",
|
||||
".ogv",
|
||||
".mov",
|
||||
".wmv",
|
||||
".mp4",
|
||||
".webm",
|
||||
".mp3",
|
||||
".wav",
|
||||
".mid",
|
||||
".rar",
|
||||
".zip",
|
||||
".tar",
|
||||
".gz",
|
||||
".7z",
|
||||
".bz2",
|
||||
".cab",
|
||||
".iso",
|
||||
".doc",
|
||||
".docx",
|
||||
".xls",
|
||||
".xlsx",
|
||||
".ppt",
|
||||
".pptx",
|
||||
".pdf",
|
||||
".txt",
|
||||
".md",
|
||||
".xml"
|
||||
], /* 上传文件格式显示 */
|
||||
|
||||
/* 列出指定目录下的图片 */
|
||||
"imageManagerActionName": "listimage", /* 执行图片管理的action名称 */
|
||||
"imageManagerListPath": "upload/image", /* 指定要列出图片的目录 */
|
||||
"imageManagerListSize": 20, /* 每次列出文件数量 */
|
||||
"imageManagerUrlPrefix": "http://localhost:64279/", /* 图片访问路径前缀 */
|
||||
"imageManagerInsertAlign": "none", /* 插入的图片浮动方式 */
|
||||
"imageManagerAllowFiles": [ ".png", ".jpg", ".jpeg", ".gif", ".bmp" ], /* 列出的文件类型 */
|
||||
|
||||
/* 列出指定目录下的文件 */
|
||||
"fileManagerActionName": "listfile", /* 执行文件管理的action名称 */
|
||||
"fileManagerListPath": "upload/file", /* 指定要列出文件的目录 */
|
||||
"fileManagerUrlPrefix": "http://localhost:64279/", /* 文件访问路径前缀 */
|
||||
"fileManagerListSize": 20, /* 每次列出文件数量 */
|
||||
"fileManagerAllowFiles": [
|
||||
".png",
|
||||
".jpg",
|
||||
".jpeg",
|
||||
".gif",
|
||||
".bmp",
|
||||
".flv",
|
||||
".swf",
|
||||
".mkv",
|
||||
".avi",
|
||||
".rm",
|
||||
".rmvb",
|
||||
".mpeg",
|
||||
".mpg",
|
||||
".ogg",
|
||||
".ogv",
|
||||
".mov",
|
||||
".wmv",
|
||||
".mp4",
|
||||
".webm",
|
||||
".mp3",
|
||||
".wav",
|
||||
".mid",
|
||||
".rar",
|
||||
".zip",
|
||||
".tar",
|
||||
".gz",
|
||||
".7z",
|
||||
".bz2",
|
||||
".cab",
|
||||
".iso",
|
||||
".doc",
|
||||
".docx",
|
||||
".xls",
|
||||
".xlsx",
|
||||
".ppt",
|
||||
".pptx",
|
||||
".pdf",
|
||||
".txt",
|
||||
".md",
|
||||
".xml"
|
||||
] /* 列出的文件类型 */
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user