mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-29 09:15:33 +00:00
76 lines
2.6 KiB
C#
76 lines
2.6 KiB
C#
namespace HaWeb.Controllers;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using HaDocument.Interfaces;
|
|
using HaXMLReader.Interfaces;
|
|
using Microsoft.FeatureManagement.Mvc;
|
|
using System.Runtime.InteropServices;
|
|
using Microsoft.AspNetCore.Http.Features;
|
|
using Microsoft.Extensions.Configuration;
|
|
using HaWeb.Filters;
|
|
using HaWeb.XMLParser;
|
|
using HaWeb.Models;
|
|
using HaWeb.FileHelpers;
|
|
|
|
public class UploadController : Controller {
|
|
// DI
|
|
private IHaDocumentWrappper _lib;
|
|
private IReaderService _readerService;
|
|
private readonly long _fileSizeLimit;
|
|
private readonly string _targetFilePath;
|
|
private readonly IXMLService _xmlService;
|
|
private readonly IXMLProvider _xmlProvider;
|
|
|
|
// Options
|
|
private static readonly string[] _permittedExtensions = { ".xml" };
|
|
private static readonly FormOptions _defaultFormOptions = new FormOptions();
|
|
|
|
|
|
public UploadController(IHaDocumentWrappper lib, IReaderService readerService, IXMLService xmlService, IXMLProvider xmlProvider, IConfiguration config) {
|
|
_lib = lib;
|
|
_readerService = readerService;
|
|
_xmlService = xmlService;
|
|
_xmlProvider = xmlProvider;
|
|
_fileSizeLimit = config.GetValue<long>("FileSizeLimit");
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
|
|
_targetFilePath = config.GetValue<string>("StoredFilePathWindows");
|
|
} else {
|
|
_targetFilePath = config.GetValue<string>("StoredFilePathLinux");
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("Admin/Upload/{id?}")]
|
|
[FeatureGate(Features.AdminService)]
|
|
[GenerateAntiforgeryTokenCookie]
|
|
public IActionResult Index(string? id) {
|
|
if (id != null) {
|
|
id = id.ToLower();
|
|
|
|
var root = _xmlService.GetRoot(id);
|
|
if (root == null) return error404();
|
|
|
|
var roots = _xmlService.GetRootsList();
|
|
if (roots == null) return error404();
|
|
|
|
var usedFiles = _xmlService.GetUsedDictionary();
|
|
var availableFiles = _xmlProvider.GetFiles(id);
|
|
|
|
var model = new UploadViewModel(root.Type, id, roots, availableFiles, usedFiles);
|
|
return View("../Admin/Upload/Index", model);
|
|
}
|
|
else {
|
|
var roots = _xmlService.GetRootsList();
|
|
if (roots == null) return error404();
|
|
|
|
var usedFiles = _xmlService.GetUsedDictionary();
|
|
|
|
var model = new UploadViewModel("Upload", id, roots, null, usedFiles);
|
|
return View("../Admin/Upload/Index", model);
|
|
}
|
|
}
|
|
|
|
private IActionResult error404() {
|
|
Response.StatusCode = 404;
|
|
return Redirect("/Error404");
|
|
}
|
|
} |