38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using System.Runtime.InteropServices;
|
|
using System.Security.Claims;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Watcher.Controllers;
|
|
|
|
[Authorize]
|
|
public class DownloadController : Controller
|
|
{
|
|
[HttpGet("Download/File/{type}/{filename}")]
|
|
public IActionResult FileDownload(string type, string filename)
|
|
{
|
|
// Nur erlaubte Endungen zulassen (Sicherheit!)
|
|
var allowedExtensions = new[] { ".exe", "", ".sql" };
|
|
var extension = Path.GetExtension(filename).ToLowerInvariant();
|
|
|
|
if (!allowedExtensions.Contains(extension))
|
|
return BadRequest("Dateityp nicht erlaubt");
|
|
|
|
var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "downloads", type, filename);
|
|
|
|
if (!System.IO.File.Exists(path))
|
|
return NotFound("Datei nicht gefunden");
|
|
|
|
// .exe MIME-Typ: application/octet-stream
|
|
var mimeType = "application/octet-stream";
|
|
|
|
var fileBytes = System.IO.File.ReadAllBytes(path);
|
|
|
|
return File(fileBytes, mimeType, filename);
|
|
//return File(fileBytes, filename);
|
|
}
|
|
}
|