生成单文件

This commit is contained in:
2025-09-26 17:42:33 +08:00
parent 0884292626
commit 13b838c7c7
17 changed files with 1671 additions and 206 deletions

View File

@@ -6,6 +6,7 @@ using Swagger.ObjectModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Reflection;
using .Base;
@@ -100,7 +101,11 @@ namespace 电子展板.WebModule
private object GetUploadFiles(string id)
{
string contentType = MimeTypes.GetMimeType(id);
return Response.AsFile(MyEnvironment.Root("/Upload/" + id), contentType);
//return Response.AsFile(MyEnvironment.Root("/Upload/" + id), contentType);
UploadFiles uploadFiles = GlobalVariable.Config.FileUploadList.FirstOrDefault(x => x.Name == id);
if (uploadFiles == null)
return null;
return Response.FromStream(new MemoryStream(uploadFiles.Bin), contentType);
}
/// <summary>
@@ -120,14 +125,21 @@ namespace 电子展板.WebModule
{
Directory.CreateDirectory(uploadPath);
}
string ext = Path.GetExtension(file.Name);
string fileName = UUID.StrSnowId + ext;
var filePath = uploadPath + fileName;
using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
{
file.Value.CopyTo(fileStream);
}
//var filePath = uploadPath + fileName;
//using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
//{
// file.Value.CopyTo(fileStream);
//}
ByteArrayStream stream = new ByteArrayStream();
file.Value.CopyTo(stream);
byte[] data = stream.ToByteArray();
GlobalVariable.Config.FileUploadList.Add(new UploadFiles { Name = fileName, Bin = data });
GlobalVariable.SaveConfig();
RetValue<string> result = new RetValue<string> { state = 1, message = "上传成功", data = $"/upload/{fileName}" };
return Response.AsJson(result);
}
@@ -140,11 +152,14 @@ namespace 电子展板.WebModule
[Route(Tags = new[] { "保存配置" })]
private object SaveConfig([RouteParam(ParamIn = ParameterIn.Body, Name = "parms", Description = "保存参数", Required = true)] MyConfig config)
{
LogHelper.Instance.Info($"用户保存了配置:{JsonHelper.ToJson(config)}");
//保存
PropertyInfo[] propertyInfos = typeof(MyConfig).GetProperties();
foreach (PropertyInfo propertyInfo in propertyInfos)
{
if (propertyInfo.Name == "FileUploadList")
{
continue;
}
object value = propertyInfo.GetValue(config);
propertyInfo.SetValue(GlobalVariable.Config, value);
}