20023-08-10

This commit is contained in:
2023-08-10 11:40:02 +08:00
parent c41b3b9777
commit 02fcf5be10
82 changed files with 9031 additions and 2997 deletions
@@ -1,9 +1,12 @@
using BLL;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
@@ -20,7 +23,9 @@ namespace WebAPI.Controllers
/// </summary>
/// <returns></returns>
public IHttpActionResult Post()
{
{// 定义允许上传的文件类型列表
List<string> allowExtensions = BLL.DropListService.allowExtensions;
HttpFileCollection files = HttpContext.Current.Request.Files;
string typeName = HttpContext.Current.Request["typeName"];
if (string.IsNullOrEmpty(typeName))
@@ -42,6 +47,10 @@ namespace WebAPI.Controllers
string fileName = string.Empty;
string extensionstr = string.Empty;
HttpPostedFile file = files[key];//file.ContentLength文件长度
if (!allowExtensions.Contains(Path.GetExtension(file.FileName)))
{
return BadRequest($"Invalid file extension: {file.FileName}");
}
if (!string.IsNullOrEmpty(file.FileName))
{
extensionstr = Path.GetExtension(file.FileName).ToLower();
@@ -169,5 +178,61 @@ namespace WebAPI.Controllers
return Ok(reUrl);
}
#endregion
#region 线
/// <summary>
/// 在线编辑回调保存文件
/// </summary>
/// <param name="toDoItem"></param>
/// <returns></returns>
[HttpPost]
public async Task<Model.ResponeData> DownloadDocument([FromBody] Model.SaveOnlineFileItem toDoItem)
{
var responeData = new Model.ResponeData();
HttpClient _httpClient = new HttpClient();
try
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
// 发送 GET 请求以获取文件内容
var response = await _httpClient.GetAsync(toDoItem.UrlStr);
response.EnsureSuccessStatusCode();
string savePath = "";
if (!string.IsNullOrEmpty(toDoItem.PCUrl))
{
savePath = ConfigurationManager.AppSettings["localRoot"] + toDoItem.PCUrl;
}
if (savePath != null)
{
// 将文件内容保存到本地
using (var fileStream = File.Create(savePath))
{
await response.Content.CopyToAsync(fileStream);
}
responeData.code = 1;
responeData.data = "文件已成功下载并保存到本地";
}
else
{
responeData.code = 0;
responeData.message = "保存路径为空";
}
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = $"下载文件时出现错误:{ex.Message}";
}
return responeData;
}
#endregion
}
}
+24 -3
View File
@@ -1,4 +1,5 @@
using System;
using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
@@ -45,13 +46,33 @@ namespace WebAPI.Filter
}
// base.OnActionExecuting(actionContext);
if (isOk)
{
{ // 在调用 Action 方法之前执行的代码,可获取请求的接口名称和参数
IDictionary<string, object> arguments = actionContext.ActionArguments; // 获取参数
foreach (KeyValuePair<string, object> item in arguments)
{
if (item.Key == "projectid" || item.Key == "ProjectId" || item.Key == "projectId" || item.Key == "Projectid")
{
var ProjectItems = APIProjectService.geProjectsByUserId(token.FirstOrDefault());
List<string> projects = new List<string>();
if (ProjectItems.Count > 0)
{
projects = ProjectItems.Select(x => x.ProjectId).ToList();
}
if (item.Value != null && !projects.Contains(item.Value.ToString()))
{
actionContext.Response = actionContext.Request.CreateResponse(System.Net.HttpStatusCode.OK,
new { code = "0", message = "您没有该项目权限!" }, actionContext.ControllerContext.Configuration.Formatters.JsonFormatter);
return;
}
}
}
base.OnActionExecuting(actionContext);
}
else
{
actionContext.Response = actionContext.Request.CreateResponse(System.Net.HttpStatusCode.OK,
new { code = "0", message = "您没有权限!" }, actionContext.ControllerContext.Configuration.Formatters.JsonFormatter);
new { code = "0", message = "您没有权限!" }, actionContext.ControllerContext.Configuration.Formatters.JsonFormatter);
}
}