mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-30 01:35:32 +00:00
Deployment v1
This commit is contained in:
@@ -19,88 +19,50 @@ using System.Runtime.InteropServices;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using System.Text;
|
||||
|
||||
public class FileListForm {
|
||||
public string file { get; set; }
|
||||
public string __RequestVerificationToken { get; set; }
|
||||
}
|
||||
|
||||
// Controlling all the API-Endpoints
|
||||
[FeatureGate(Features.AdminService)]
|
||||
[ApiController]
|
||||
public class APIController : Controller {
|
||||
|
||||
// DI
|
||||
private IHaDocumentWrappper _lib;
|
||||
private readonly IHaDocumentWrappper _lib;
|
||||
private readonly IXMLFileProvider _xmlProvider;
|
||||
|
||||
private readonly IXMLInteractionService _xmlService;
|
||||
|
||||
// Options
|
||||
private static readonly FormOptions _defaultFormOptions = new FormOptions();
|
||||
|
||||
|
||||
public APIController(IHaDocumentWrappper lib, IXMLFileProvider xmlProvider) {
|
||||
public APIController(IHaDocumentWrappper lib, IXMLInteractionService xmlService, IXMLFileProvider xmlProvider) {
|
||||
_lib = lib;
|
||||
_xmlProvider = xmlProvider;
|
||||
_xmlService = xmlService;
|
||||
}
|
||||
|
||||
|
||||
// TODO: this is trash
|
||||
[HttpPost]
|
||||
[Route("API/SetInProduction")]
|
||||
[DisableFormValueModelBinding]
|
||||
[ValidateAntiForgeryToken]
|
||||
[FeatureGate(Features.LocalPublishService, Features.AdminService)]
|
||||
public async Task<IActionResult> SetInProduction() {
|
||||
public async Task<IActionResult> SetInProduction([FromForm] FileListForm _form) {
|
||||
var hF = _xmlProvider.GetHamannFiles();
|
||||
if (hF == null) {
|
||||
ModelState.AddModelError("Error", "There are no Hamman.xml files available.");
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType)) {
|
||||
ModelState.AddModelError("Error", $"Wrong / No Content Type on the Request");
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
// Same as above, check Upload()
|
||||
string? filename = null;
|
||||
var boundary = MultipartRequestHelper.GetBoundary(MediaTypeHeaderValue.Parse(Request.ContentType), _defaultFormOptions.MultipartBoundaryLengthLimit);
|
||||
var reader = new MultipartReader(boundary, HttpContext.Request.Body);
|
||||
MultipartSection? section = null;
|
||||
try {
|
||||
section = await reader.ReadNextSectionAsync();
|
||||
} catch (Exception ex) {
|
||||
ModelState.AddModelError("Error", "The Request is bad: " + ex.Message);
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
while (section != null) {
|
||||
var hasContentDispositionHeader = ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out var contentDisposition);
|
||||
|
||||
if (contentDisposition != null && contentDisposition.Name == "__RequestVerificationToken") {
|
||||
try {
|
||||
section = await reader.ReadNextSectionAsync();
|
||||
} catch (Exception ex) {
|
||||
ModelState.AddModelError("Error", "The Request is bad: " + ex.Message);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hasContentDispositionHeader && contentDisposition != null) {
|
||||
if (!MultipartRequestHelper.HasFormDataContentDisposition(contentDisposition)) {
|
||||
ModelState.AddModelError("Error", $"Wrong Content-Dispostion Headers in Multipart Document");
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
filename = XMLFileHelpers.StreamToString(section.Body, ModelState);
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
try {
|
||||
section = await reader.ReadNextSectionAsync();
|
||||
} catch (Exception ex) {
|
||||
ModelState.AddModelError("Error", "The Request is bad: " + ex.Message);
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
}
|
||||
|
||||
if (filename == null) {
|
||||
if (_form == null || String.IsNullOrWhiteSpace(_form.file)) {
|
||||
ModelState.AddModelError("Error", "Kein Dateiname.");
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
var newFile = hF.Where(x => x.Name == filename);
|
||||
var newFile = hF.Where(x => x.Name == _form.file);
|
||||
if (newFile == null || !newFile.Any()) {
|
||||
ModelState.AddModelError("Error", "Versuch, auf eine unverfügbare Datei zuzugreifen.");
|
||||
return BadRequest(ModelState);
|
||||
@@ -110,4 +72,19 @@ public class APIController : Controller {
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
return Created("/", newFile.First());
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("API/SyntaxCheck")]
|
||||
// [ValidateAntiForgeryToken]
|
||||
[DisableFormValueModelBinding]
|
||||
[FeatureGate(Features.SyntaxCheck, Features.AdminService)]
|
||||
public ActionResult<Dictionary<string, SyntaxCheckModel>?> GetSyntaxCheck(string? id) {
|
||||
var SCCache = _xmlService.GetSCCache();
|
||||
if (_xmlProvider.HasChanged() || SCCache == null) {
|
||||
var commit = _xmlProvider.GetGitState();
|
||||
SCCache = _xmlService.Test(_xmlService.GetState(), commit != null ? commit.Commit : string.Empty);
|
||||
_xmlService.SetSCCache(SCCache);
|
||||
}
|
||||
return Ok(SCCache);
|
||||
}
|
||||
}
|
||||
@@ -185,11 +185,11 @@ public class Briefecontroller : Controller {
|
||||
foreach (var str in strlist) {
|
||||
if (str != strlist.First())
|
||||
if (str == strlist.Last())
|
||||
res += " und " + HTMLHelpers.TagHelpers.CreateElement("a", "", "/HKB/Person/" + str.Index) + str.Name + HTMLHelpers.TagHelpers.CreateEndElement("a");
|
||||
res += " und " + (str.Index == "1" ? "" : HTMLHelpers.TagHelpers.CreateElement("a", "", "/HKB/Person/" + str.Index)) + str.Name + (str.Index == "1" ? "" : HTMLHelpers.TagHelpers.CreateEndElement("a"));
|
||||
else
|
||||
res += ", " + HTMLHelpers.TagHelpers.CreateElement("a", "", "/HKB/Person/" + str.Index) + str.Name + HTMLHelpers.TagHelpers.CreateEndElement("a");
|
||||
res += ", " + (str.Index == "1" ? "" :HTMLHelpers.TagHelpers.CreateElement("a", "", "/HKB/Person/" + str.Index)) + str.Name + (str.Index == "1" ? "" : HTMLHelpers.TagHelpers.CreateEndElement("a"));
|
||||
else
|
||||
res += HTMLHelpers.TagHelpers.CreateElement("a", "", "/HKB/Person/" + str.Index) + str.Name + HTMLHelpers.TagHelpers.CreateEndElement("a");
|
||||
res += (str.Index == "1" ? "" : HTMLHelpers.TagHelpers.CreateElement("a", "", "/HKB/Person/" + str.Index)) + str.Name + (str.Index == "1" ? "" : HTMLHelpers.TagHelpers.CreateEndElement("a"));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -25,18 +25,15 @@ public class XMLStateController : Controller {
|
||||
[GenerateAntiforgeryTokenCookie]
|
||||
public IActionResult Index() {
|
||||
var library = _lib.GetLibrary();
|
||||
var roots = _xmlService.GetRootsList();
|
||||
if (roots == null) return error404();
|
||||
|
||||
var hF = _xmlProvider.GetHamannFiles()?.OrderByDescending(x => x.LastModified).ToList();
|
||||
var mF = _xmlService.GetManagedFiles();
|
||||
var gD = _xmlProvider.GetGitData();
|
||||
var mF = _xmlService.GetState() == null ? null : _xmlService.GetState()!.ManagedFiles;
|
||||
var gD = _xmlProvider.GetGitState();
|
||||
var activeF = _lib.GetActiveFile();
|
||||
var vS = _xmlService.GetValidState();
|
||||
var vS = _xmlService.GetState() == null ? false : _xmlService.GetState()!.ValidState;
|
||||
|
||||
var model = new XMLStateViewModel("Dateiübersicht", gD, roots, hF, mF, vS) {
|
||||
var model = new XMLStateViewModel("Dateiübersicht", gD, hF, mF, vS) {
|
||||
ActiveFile = activeF,
|
||||
SyntaxCheck = _xmlService.Test()
|
||||
SyntaxCheck = _xmlService.GetSCCache(),
|
||||
};
|
||||
return View("~/Views/Admin/Dynamic/XMLState.cshtml", model);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user