|
@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.StaticFiles;
|
|
using Microsoft.AspNetCore.StaticFiles;
|
|
using Microsoft.Extensions.Options;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
+using SharpCompress.Common;
|
|
using SqlSugar;
|
|
using SqlSugar;
|
|
using XF.Domain.Authentications;
|
|
using XF.Domain.Authentications;
|
|
|
|
|
|
@@ -103,10 +104,31 @@ namespace FileStorage.Host.Controllers
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
[AllowAnonymous]
|
|
[AllowAnonymous]
|
|
[HttpGet("files_indefinitely")]
|
|
[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);
|
|
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")]
|
|
[HttpGet("test")]
|