Added Upload functionality; still a bit janky in selecting the files to use...

This commit is contained in:
schnulller
2022-06-05 21:04:22 +02:00
parent 0d33dcd4e5
commit b5aae5ddf0
27 changed files with 188456 additions and 40 deletions

View File

@@ -50,7 +50,7 @@ public class APIController : Controller {
[Route("API/Syntaxcheck/{id}")]
[DisableFormValueModelBinding]
[ValidateAntiForgeryToken]
[FeatureGate(Features.AdminService)]
[FeatureGate(Features.UploadService, Features.AdminService)]
public async Task<IActionResult> SyntaxCheck(string id) {
return Ok();
}
@@ -60,8 +60,8 @@ public class APIController : Controller {
[Route("API/Upload")]
[DisableFormValueModelBinding]
[ValidateAntiForgeryToken]
[FeatureGate(Features.UploadService)]
public async Task<IActionResult> Upload(string? id) {
[FeatureGate(Features.UploadService, Features.AdminService)]
public async Task<IActionResult> Upload() {
List<XMLRootDocument>? docs = null;
//// 1. Stage: Check Request format and request spec
// Checks the Content-Type Field (must be multipart + Boundary)
@@ -114,19 +114,18 @@ public class APIController : Controller {
return UnprocessableEntity(ModelState);
//// 4. Stage: Is it a Hamann-Document? What kind?
var retdocs = await _xmlService.ProbeHamannFile(xdocument, ModelState);
var retdocs = _xmlService.ProbeHamannFile(xdocument, ModelState);
if (!ModelState.IsValid || retdocs == null || !retdocs.Any())
return UnprocessableEntity(ModelState);
//// 5. Stage: Saving the File(s)
foreach (var doc in retdocs) {
// Physical saving
var task = _xmlProvider.Save(doc, _targetFilePath, ModelState);
await _xmlProvider.Save(doc, _targetFilePath, ModelState);
// Setting the new docuemnt as used
_xmlService.Use(doc);
// Unsetting all old docuemnts as ununsed
_xmlService.AutoUse(doc.Prefix);
await task;
if (!ModelState.IsValid) return StatusCode(500, ModelState);
if (docs == null) docs = new List<XMLRootDocument>();
docs.Add(doc);
@@ -137,6 +136,7 @@ public class APIController : Controller {
section = await reader.ReadNextSectionAsync();
} catch (Exception ex) {
ModelState.AddModelError("Error", "The Request is bad: " + ex.Message);
return BadRequest(ModelState);
}
}
@@ -151,4 +151,24 @@ public class APIController : Controller {
string json = JsonSerializer.Serialize(docs);
return Created(nameof(UploadController), json);
}
//// PUBLISH ////
[HttpPost]
[Route("API/LocalPublish")]
[DisableFormValueModelBinding]
[ValidateAntiForgeryToken]
[FeatureGate(Features.LocalPublishService, Features.AdminService, Features.UploadService)]
public async Task<IActionResult> LocalPublish() {
var element = _xmlService.MergeUsedDocuments(ModelState);
if (!ModelState.IsValid || element == null)
return BadRequest(ModelState);
var savedfile = await _xmlProvider.SaveHamannFile(element, _targetFilePath, ModelState);
if (!ModelState.IsValid || savedfile == null)
return BadRequest(ModelState);
_ = _lib.SetLibrary(savedfile.PhysicalPath, ModelState);
if (!ModelState.IsValid)
return BadRequest(ModelState);
return Ok();
}
}

View File

@@ -31,8 +31,8 @@ public class Briefecontroller : Controller {
// Normalisation and Validation, (some) data aquisition
if (id == null) return Redirect(url + defaultID);
this.id = id.ToLower();
var preliminarymeta = lib.Metas.Where(x => x.Value.Autopsic == this.id);
id = id.ToLower();
var preliminarymeta = lib.Metas.Where(x => x.Value.Autopsic == id);
if (preliminarymeta == null || !preliminarymeta.Any()) return error404();
// Get all neccessary data
@@ -54,7 +54,7 @@ public class Briefecontroller : Controller {
// Model creation
var hasMarginals = false;
if (marginals != null && marginals.Any()) hasMarginals = true;
var model = new BriefeViewModel(this.id, index, generateMetaViewModel(lib, meta, hasMarginals));
var model = new BriefeViewModel(id, index, generateMetaViewModel(lib, meta, hasMarginals));
if (nextmeta != null) model.MetaData.Next = (generateMetaViewModel(lib, nextmeta, false), url + nextmeta.Autopsic);
if (prevmeta != null) model.MetaData.Prev = (generateMetaViewModel(lib, prevmeta, false), url + prevmeta.Autopsic);
if (hands != null && hands.Any()) model.ParsedHands = HaWeb.HTMLHelpers.LetterHelpers.CreateHands(lib, hands);