Add download button to archives list
This commit is contained in:
parent
4c86ebfc3e
commit
4acd8cdc5c
2 changed files with 46 additions and 0 deletions
36
LANCommander/Controllers/DownloadController.cs
Normal file
36
LANCommander/Controllers/DownloadController.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using LANCommander.Data;
|
||||
using LANCommander.Extensions;
|
||||
using LANCommander.Models;
|
||||
using LANCommander.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LANCommander.Controllers
|
||||
{
|
||||
[Authorize(Roles = "Administrator")]
|
||||
public class DownloadController : Controller
|
||||
{
|
||||
private readonly ArchiveService ArchiveService;
|
||||
|
||||
public DownloadController(ArchiveService archiveService)
|
||||
{
|
||||
ArchiveService = archiveService;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Game(Guid id)
|
||||
{
|
||||
var archive = await ArchiveService.Get(id);
|
||||
|
||||
if (archive == null)
|
||||
return NotFound();
|
||||
|
||||
var filename = Path.Combine("Upload", archive.ObjectKey);
|
||||
|
||||
if (!System.IO.File.Exists(filename))
|
||||
return NotFound();
|
||||
|
||||
return File(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read), "application/octet-stream", $"{archive.Game.Title.SanitizeFilename()}.zip");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,6 +21,9 @@
|
|||
<PropertyColumn Property="a => a.CreatedOn" Format="MM/dd/yyyy hh:mm tt" />
|
||||
<ActionColumn Title="">
|
||||
<Space Style="display: flex; justify-content: end">
|
||||
<SpaceItem>
|
||||
<Button OnClick="() => Download(context)" Icon="@IconType.Outline.Download" Type="@ButtonType.Text" />
|
||||
</SpaceItem>
|
||||
<SpaceItem>
|
||||
<Popconfirm Title="Are you sure you want to delete this archive?" OnConfirm="() => Delete(context)">
|
||||
<Button Icon="@IconType.Outline.Close" Type="@ButtonType.Text" Danger />
|
||||
|
@ -114,6 +117,13 @@
|
|||
};
|
||||
}
|
||||
|
||||
private async Task Download(Archive archive)
|
||||
{
|
||||
string url = $"/Download/Game/{archive.Id}";
|
||||
|
||||
await JS.InvokeAsync<object>("open", url, "_blank");
|
||||
}
|
||||
|
||||
private void AddArchive()
|
||||
{
|
||||
Archive = new Archive()
|
||||
|
|
Loading…
Add table
Reference in a new issue