radivoje.milutinovic пре 3 година
родитељ
комит
30faa152fd

+ 18
- 4
SecureSharing/Controllers/HomeController.cs Прегледај датотеку

@@ -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)
{

+ 0
- 1
SecureSharing/Models/LinkModel.cs Прегледај датотеку

@@ -6,6 +6,5 @@ public sealed class LinkModel
public MessageModel MessageModel { get; set; }
public bool? Share { get; set; }
public TimeSpan? TimeLeft { get; set; }

public bool IsValid { get; set; }
}

+ 3
- 4
SecureSharing/Views/Home/Link.cshtml Прегледај датотеку

@@ -45,7 +45,7 @@ else
<div class="label-text link-show">
@foreach (var file in Model.MessageModel.FileNames)
{
<p>@file</p>
<a asp-action="Download" asp-route-filename="@file" asp-route-code="@Model.MessageModel.Code">@file</a>
}
</div>
}
@@ -94,7 +94,7 @@ else
<div class="label-text link-show">
@foreach (var file in Model.MessageModel.FileNames)
{
<p>@file</p>
<a asp-action="Download" asp-route-filename="@file" asp-route-code="@Model.MessageModel.Code">@file</a>
}
</div>
}
@@ -104,12 +104,11 @@ else
}

<script>
function copyToClipboard() {
copyToClipboard = () => {
// Get the text field
const copyText = document.getElementById("a-link").innerText;
// Copy the text inside the text field
navigator.clipboard.writeText(copyText);

}
</script>

Loading…
Откажи
Сачувај