fix&feat: c# 上传文件存在最大限制。消息优化和更改,现在减少用户使用时的担心,它更加人性化

```csharp
// 使用默认的Kestrel  服务器部署,将默认限制最大文件的上传,使用这个取消限制
 [DisableRequestSizeLimit]
 [HttpPost("/UploadFile")]
 public async Task<IActionResult> UploadFile(IFormFile file)
 {

```
This commit is contained in:
ZhaoLei 2024-10-29 18:08:34 +08:00
parent 6df1dbd6ae
commit fa64f0c6d5
7 changed files with 161 additions and 48 deletions

View file

@ -4,8 +4,12 @@ public enum SyncMsgType
{
Error = 0,
General = 1,
//进度消息
Process = 2,
// DirFilePack = 3
//文件展示消息
DirFileDiff = 3
}
public enum SyncProcessStep

View file

@ -8,10 +8,10 @@ using System.Threading;
namespace Common;
public class ProgressStreamContent(Stream stream_, IProgress<double> progress)
: StreamContent(stream_, 1024 * 1024)
: StreamContent(stream_, 5 * 1024 * 1024)
{
private readonly Stream FileStream = stream_;
private readonly int BufferSize = 1024 * 1024;
private readonly int BufferSize = 5 * 1024 * 1024;
private readonly IProgress<double> Progress = progress;
protected override async Task SerializeToStreamAsync(

View file

@ -286,6 +286,11 @@ public class DiffFileAndPackHelper(LocalSyncServer context)
Context.NotNullSyncConfig.LocalRootPath
);
e.DiffDirInfo.WriteByThisInfo(PackOp);
Context
.LocalPipe.SendMsg(
CreateMsg(JsonSerializer.Serialize(e.DiffDirInfo), SyncMsgType.DirFileDiff)
)
.Wait();
}
});
Context.LocalPipe.SendMsg(CreateMsg("文件差异比较成功!")).Wait();
@ -318,6 +323,7 @@ public class DeployMSSqlHelper(LocalSyncServer context)
}
else
{
Context.LocalPipe.SendMsg(CreateMsg("正在打包数据库...")).Wait();
var arguments =
$" /Action:Extract /TargetFile:{LocalSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id.ToString()}/{Context.NotNullSyncConfig.Id.ToString()}.dacpac"
// 不要log file 了
@ -387,7 +393,7 @@ public class UploadPackedHelper(LocalSyncServer context)
$"{LocalSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id}.zip",
(double current) =>
{
//这里可能需要降低获取上传进度的频率
// 每上传1Mb 更新一下进度
Context
.LocalPipe.SendMsg(CreateMsg(current.ToString(), SyncMsgType.Process))
.Wait();

View file

@ -6,21 +6,21 @@ import WebSocket from "ws";
const LocalHost = "127.0.0.1";
const config = {
//发布的名称,每个项目具有唯一的一个名称
Name: "FYMF",
RemotePwd: "FYMF",
Name: "Test",
RemotePwd: "t123",
//远程服务器地址,也就是发布的目的地,它是正式环境
RemoteUrl: "127.0.0.1:8007",
RemoteUrl: "127.0.0.1:6819",
//是否发布数据库 sqlserver
IsDeployDb: true,
//是否发布前重新构建项目
IsDeployProject: false,
IsDeployProject: true,
//项目地址
LocalProjectAbsolutePath:
"D:/git/HMES-H7-HNFY/HMES-H7-HNFYMF/HMES-H7-HNFYMF.WEB",
//源文件目录地址,是要发布的文件根目录,它是绝对路径,!执行发布时将发布到这个目录!
LocalRootPath: "D:/FileSyncTest/src",
//目标文件目录地址,也就是部署服务的机器上的项目文件根目录,它是绝对路径
RemoteRootPath: "D:/FYMF",
RemoteRootPath: "D:/FileSyncTest/dst",
//源数据库配置 SqlServer,将会同步数据库的结构
SrcDb: {
//Host
@ -44,7 +44,7 @@ const config = {
ServerName: "127.0.0.1",
DatabaseName: "HMES_H7_HNFYMF",
User: "sa",
Password: "Yuanmo520...",
Password: "0",
TrustServerCertificate: "True",
},
//子目录配置每个子目录都有自己不同的发布策略它是相对路径即相对于LocalRootPath和RemoteRootPath(注意 '/',这将拼成一个完整的路径),文件数据依此进行,
@ -82,20 +82,20 @@ let IsSuccess = false;
* 在新行打印错误信息
*/
function PrintErrInNewLine(str) {
process.stdout.write("\n");
var chunk = chalk["red"]("[错误]: ");
process.stdout.write(chunk);
process.stdout.write(str);
process.stdout.write("\n");
}
/**
* 在新行打印成功信息
*/
function PrintSuccessInNewLine(str) {
process.stdout.write("\n");
var chunk = chalk["green"]("[成功]: ");
process.stdout.write(chunk);
process.stdout.write(str);
process.stdout.write("\n");
}
/**
@ -111,8 +111,11 @@ function PrintCloseNewLine(str) {
/**
* 在当前行打印一般信息打印此行信息之前会清除当前行
*/
function PrintGeneralInCurrentLine(str) {
process.stdout.write(`\r${str}`);
function PrintProcessLine(str) {
var chunk = chalk["yellow"]("[上传进度]: ");
process.stdout.write(chunk);
process.stdout.write(`${str}`);
process.stdout.write("\n");
}
//#endregion
@ -122,26 +125,52 @@ function PrintGeneralInCurrentLine(str) {
/**
* 1-n. localServer 工作此处只展示信息
*/
function getOpEmoj(Op) {
switch (Op) {
case 0:
return "";
case 1:
return "Ⓜ️";
case 2:
return "❌";
default:
return "🚀";
}
}
let ws = null;
function MsgCb(MsgIt) {
if (MsgIt.Type == 2) {
PrintGeneralInCurrentLine(MsgIt.Body);
} else {
if (MsgIt.Step <= 6) {
if (MsgIt.Type == 2) {
PrintProcessLine(`(${MsgIt.Step}/6) ${MsgIt.Body}`);
if (parseFloat(MsgIt.Body) == 1) {
var chunk = chalk["green"]("[上传成功]");
process.stdout.write(chunk);
process.stdout.write("\n");
}
} else if (MsgIt.Type == 3) {
var it = JSON.parse(MsgIt.Body);
it.Children.forEach((e) => {
PrintSuccessInNewLine(
`(${MsgIt.Step}/6) [${getOpEmoj(e.NextOp)}] ${e.FormatedPath}`
);
});
} else {
PrintSuccessInNewLine(`(${MsgIt.Step}/6) ${MsgIt.Body}`);
}
if (MsgIt.Step == 6) {
if (MsgIt.Body == "发布完成!") {
IsSuccess = true;
ws.close();
}
}
} else if (MsgIt == 7) {
} else if (MsgIt.Step == 7) {
PrintErrInNewLine(MsgIt.Body);
} else {
PrintCloseNewLine("(关闭)" + MsgIt.Body);
}
}
}
//#endregion
async function connectWebSocket() {
return new Promise((resolve, reject) => {
@ -183,6 +212,10 @@ async function connectWebSocket() {
}
(async function main() {
try {
// for(var i = 0;i<10;++i) {
// PrintGeneralInCurrentLine(`${i}`)
// }
// PrintSuccessInNewLine("11")
await connectWebSocket();
// console.log('WebSocket has closed');
// The script will wait here until the WebSocket connection is closed

View file

@ -12,26 +12,27 @@ const options = ref({
tabSize: 2,
})
let IsSuccess = false
let Pipe = null
const Msgs = ref([])
const code = ref(`
config = {
//
Name: "FYMF",
RemotePwd: "FYMF",
Name: "Test",
RemotePwd: "t123",
//
RemoteUrl: "127.0.0.1:8007",
RemoteUrl: "127.0.0.1:6819",
// sqlserver
IsDeployDb: true,
//
IsDeployProject: false,
IsDeployProject: true,
//
LocalProjectAbsolutePath:
"D:/git/HMES-H7-HNFY/HMES-H7-HNFYMF/HMES-H7-HNFYMF.WEB",
//!!
LocalRootPath: "D:/FileSyncTest/src",
//
RemoteRootPath: "D:/FYMF",
RemoteRootPath: "D:/FileSyncTest/dst",
// SqlServer,
SrcDb: {
//Host
@ -55,7 +56,7 @@ config = {
ServerName: "127.0.0.1",
DatabaseName: "HMES_H7_HNFYMF",
User: "sa",
Password: "Yuanmo520...",
Password: "0",
TrustServerCertificate: "True",
},
//LocalRootPathRemoteRootPath( '/'),
@ -86,16 +87,40 @@ config = {
};
`)
var CStatus = ref('None')
function getOpEmoj(Op) {
switch (Op) {
case 0:
return "";
case 1:
return "Ⓜ️";
case 2:
return "❌";
default:
return "🚀";
}
}
function publishCB(MsgIt) {
console.log(MsgIt)
if (MsgIt.Type == 2) {
Msgs.value[Msgs.value.length - 1] = MsgIt
} else {
} else if (MsgIt.Type == 3) {
var it = JSON.parse(MsgIt.Body);
it.Children.forEach((e) => {
Msgs.value.push({
Step: MsgIt.Step,
Type: MsgIt.Type,
Body: `[${getOpEmoj(e.NextOp)}] ${e.FormatedPath}`
})
});
}
else {
Msgs.value.push(MsgIt)
}
if (MsgIt.Step == 6) {
if (MsgIt.Body == "发布完成!") {
CStatus.value = 'Success'
IsSuccess = true
Pipe.ClosePipe()
dialogShow("正确:发布完成!")
}
@ -162,6 +187,46 @@ function dialogShow(msg) {
dMsg.value = msg
document.getElementById('dialog').showModal()
}
function getColor(msg) {
if (msg.Step >= 7) {
if (IsSuccess) {
return "green"
}
return "red"
} else if (msg.Type == 2) {
return "yellow"
} else {
return "green"
}
}
function getTitle(msg) {
var x = getColor(msg)
switch (x) {
case "green":
return "[成功]"
break;
case "red":
return "[失败]"
break;
case "yellow":
return "[上传进度]"
break;
default:
break;
}
}
function getStep(msg) {
if (msg.Step > 6) {
return ""
}
return `(${msg.Step}/6)`
}
function getBody(msg) {
return msg.Body
}
</script>
<template>
@ -173,13 +238,18 @@ function dialogShow(msg) {
<MonacoEditor theme="vs-dark" :options="options" language="javascript" :width="800" :height="700"
v-model:value="code"></MonacoEditor>
<div style="width: 800px;height: 700px;background-color: #1e1e1e;">
<div style="width: 1200px;height: 700px;background-color: #1e1e1e;overflow:auto;">
发布日志
<p style="text-align: left;border: 1px solid gray;margin: 5px;" v-for="msg in Msgs">
<span :style="{ width: '100px', color: msg.Step > 6 ? 'red' : 'green' }">[{{ msg.Step
> 6 ? msg.Step > 7 ? "关闭" : "错误" : `${msg.Step}/${6}`}}]</span>
<span style="margin-left: 5px ;">{{ msg.Body }}</span>
<span :style="{ width: '100px', color: getColor(msg) }">
{{ getTitle(msg) }}
</span>
<span>
{{ getStep(msg) }}
</span>
{{ getBody(msg) }}
</p>
</div>
</div>

View file

@ -6,8 +6,8 @@ class ConnectPipe {
// this.#websocket = new WebSocket(`ws://${window.location.host}`)
}
OpenPipe(config, MsgCb) {
var webSocUrl = `ws://${window.location.host}/websoc?Name=${config.Name}`
// var webSocUrl = "ws://127.0.0.1:6818/websoc?Name=Test";
// var webSocUrl = `ws://${window.location.host}/websoc?Name=${config.Name}`
var webSocUrl = "ws://127.0.0.1:6818/websoc?Name=Test";
this.#websocket = new WebSocket(webSocUrl);
this.#websocket.onopen = (event) => {
var starter = {

View file

@ -59,7 +59,7 @@ button:focus-visible {
}
#app {
max-width: 1280px;
/* max-width: 1280px; */
margin: 0 auto;
padding: 2rem;
text-align: center;