Просмотр исходного кода

更新包源配置与文件处理逻辑,禁用Serilog日志

更新了 NuGet.Config 文件:
- 清空现有包源配置,重新添加 nuget.org 和 fengwo.org。
- 为 fengwo.org 添加允许不安全连接的配置。

更新了 FileController.cs 文件:
- 修改 FilesIndefinitely 方法的返回类型和实现。
- 添加文件路径检查、文件信息设置及异常处理逻辑。

更新了 StartupExtensions.cs 文件:
- 注释掉了 Serilog 请求日志记录功能。
xf 10 часов назад
Родитель
Сommit
6458356969

+ 3 - 2
NuGet.Config

@@ -1,7 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <configuration>
   <packageSources>
-    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
-    <add key="fengwo.org" value="http://110.188.24.182:5555/v3/index.json" />
+    <clear />
+    <add key="nuget.org" value="https://api.nuget.org/v3/index.json"  protocolVersion="3"/>
+    <add key="fengwo.org" value="http://110.188.24.182:5555/v3/index.json" allowInsecureConnections="true"/>
   </packageSources>
 </configuration>

+ 24 - 2
src/FileStorage.Host/Controllers/FileController.cs

@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.AspNetCore.StaticFiles;
 using Microsoft.Extensions.Options;
+using SharpCompress.Common;
 using SqlSugar;
 using XF.Domain.Authentications;
 
@@ -103,10 +104,31 @@ namespace FileStorage.Host.Controllers
         /// <returns></returns>
         [AllowAnonymous]
         [HttpGet("files_indefinitely")]
-        public async Task FilesIndefinitely(string id, string expires, string clientid, string signature)
+        public async Task<IActionResult> FilesIndefinitely(string id, string expires, string clientid, string signature)
         {
 	        var fullPath = await _fileStorage.GetFilePathIndefinitely(id, expires, clientid, signature);
-	        await HttpContext.Response.SendFileAsync(fullPath);
+            //await HttpContext.Response.SendFileAsync(fullPath);
+
+            if (!System.IO.File.Exists(fullPath))
+            {
+                return NotFound();
+            }
+
+            var fileInfo = new FileInfo(fullPath);
+            Response.ContentType = "application/octet-stream";
+            Response.ContentLength = fileInfo.Length;
+            //Response.Headers.Add("Content-Disposition", $"attachment; filename=\"{fileInfo.Name}\"");
+            Response.Headers.Add("Content-Disposition", $"inline; filename=\"{fileInfo.Name}\"");
+
+            try
+            {
+                await Response.SendFileAsync(fullPath);
+                return new EmptyResult();
+            }
+            catch (Exception ex) when (ex is TaskCanceledException || ex is IOException)
+            {
+                return StatusCode(StatusCodes.Status410Gone);
+            }
         }
 
         [HttpGet("test")]

+ 1 - 1
src/FileStorage.Host/StartupExtensions.cs

@@ -91,7 +91,7 @@ internal static class StartupExtensions
 
     internal static WebApplication ConfigurePipelines(this WebApplication app)
     {
-        app.UseSerilogRequestLogging();
+        //app.UseSerilogRequestLogging();
 
         var swaggerEnable = app.Configuration.GetSection("Swagger").Get<bool>();
         // Configure the HTTP request pipeline.