|
|
|
@@ -1,6 +1,7 @@ |
|
|
|
using System.Text.Json; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.AspNetCore.StaticFiles; |
|
|
|
using SecureSharing.Business.Dtos; |
|
|
|
using SecureSharing.Business.Interfaces; |
|
|
|
using SecureSharing.Data.Data; |
|
|
|
@@ -16,6 +17,7 @@ public sealed class HomeController : Controller |
|
|
|
private readonly IMessageService _messageService; |
|
|
|
private readonly IModelFactory _modelFactory; |
|
|
|
private readonly IWebHostEnvironment _webHostEnvironment; |
|
|
|
private const string DefaultPath = "files"; |
|
|
|
|
|
|
|
public HomeController(ILogger<HomeController> logger, IMessageService messageService, IModelFactory modelFactory, IWebHostEnvironment webHostEnvironment) |
|
|
|
{ |
|
|
|
@@ -41,11 +43,10 @@ public sealed class HomeController : Controller |
|
|
|
|
|
|
|
var message = new MessageDto { Text = model.Text }; |
|
|
|
|
|
|
|
// var basePath = Path.Combine(_webHostEnvironment.WebRootPath.Split('/')[0], DefaultPath, message.Code.ToString()); |
|
|
|
var basePath = $"C:\\Users\\radivoje.milutinovic\\Downloads\\fajlovitmp\\{message.Code}"; |
|
|
|
|
|
|
|
var basePath = Path.Combine(_webHostEnvironment.WebRootPath.Split('/')[0], DefaultPath, message.Code.ToString()); |
|
|
|
// var basePath = $"C:\\Users\\radivoje.milutinovic\\Downloads\\fajlovitmp\\{message.Code}"; |
|
|
|
Directory.CreateDirectory(basePath); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var formFile in model.Files) |
|
|
|
{ |
|
|
|
if (formFile.Length <= 0) continue; |
|
|
|
@@ -60,6 +61,19 @@ public sealed class HomeController : Controller |
|
|
|
return RedirectToAction("Link", "Home", new { code = code, share = true }); |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<FileStreamResult> Download(string filename, Guid code) |
|
|
|
{ |
|
|
|
var path = Path.Combine(_webHostEnvironment.WebRootPath.Split('/')[0], DefaultPath, code.ToString(), filename); |
|
|
|
var memory = new MemoryStream(); |
|
|
|
await using var stream = new FileStream(path, FileMode.Open); |
|
|
|
await stream.CopyToAsync(memory); |
|
|
|
memory.Position = 0; |
|
|
|
string? contentType; |
|
|
|
new FileExtensionContentTypeProvider().TryGetContentType(filename, out contentType); |
|
|
|
return contentType is null ? null : File(memory, contentType,Path.GetFileName(path)); |
|
|
|
// Response.Redirect(); |
|
|
|
} |
|
|
|
|
|
|
|
[HttpGet] |
|
|
|
public async Task<IActionResult> Link(Guid code, bool? share) |
|
|
|
{ |