mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-29 09:15:33 +00:00
Migitated some null risks
This commit is contained in:
@@ -52,7 +52,7 @@ public class APIController : Controller {
|
|||||||
[DisableFormValueModelBinding]
|
[DisableFormValueModelBinding]
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
[FeatureGate(Features.UploadService, Features.AdminService)]
|
[FeatureGate(Features.UploadService, Features.AdminService)]
|
||||||
public async Task<IActionResult> SyntaxCheck(string id) {
|
public IActionResult SyntaxCheck(string id) {
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,9 +49,10 @@ public class RegisterController : Controller {
|
|||||||
ViewData["SEODescription"] = "Johann Georg Hamann: Kommentierte Briefausgabe. Personen-, Sach- und Ortsregister.";
|
ViewData["SEODescription"] = "Johann Georg Hamann: Kommentierte Briefausgabe. Personen-, Sach- und Ortsregister.";
|
||||||
|
|
||||||
// Normalisation and validation
|
// Normalisation and validation
|
||||||
if (id == null) return Redirect(url + defaultLetter);
|
if (String.IsNullOrWhiteSpace(id)) return Redirect(url + defaultLetter);
|
||||||
id = normalizeID(id, defaultLetter);
|
id = normalizeID(id, defaultLetter);
|
||||||
if (!lib.CommentsByCategoryLetter[category].Contains(id)) return error404();
|
if (String.IsNullOrWhiteSpace(id)) return Redirect(url + defaultLetter);
|
||||||
|
if (!lib.CommentsByCategoryLetter[category].Contains(id!)) return error404();
|
||||||
|
|
||||||
// Data aquisition and validation
|
// Data aquisition and validation
|
||||||
var comments = lib.CommentsByCategoryLetter[category][id].OrderBy(x => x.Index);
|
var comments = lib.CommentsByCategoryLetter[category][id].OrderBy(x => x.Index);
|
||||||
@@ -115,8 +116,9 @@ public class RegisterController : Controller {
|
|||||||
ViewData["SEODescription"] = "Johann Georg Hamann: Kommentierte Briefausgabe. Forschungsbibliographie.";
|
ViewData["SEODescription"] = "Johann Georg Hamann: Kommentierte Briefausgabe. Forschungsbibliographie.";
|
||||||
|
|
||||||
// Normalisation and Validation
|
// Normalisation and Validation
|
||||||
if (id == null) return Redirect(url + defaultLetter);
|
if (String.IsNullOrWhiteSpace(id)) return Redirect(url + defaultLetter);
|
||||||
id = normalizeID(id, defaultLetter);
|
id = normalizeID(id, defaultLetter);
|
||||||
|
if (String.IsNullOrWhiteSpace(id)) return Redirect(url + defaultLetter);
|
||||||
if (id != "EDITIONEN" && !lib.CommentsByCategoryLetter[category].Contains(id)) return error404();
|
if (id != "EDITIONEN" && !lib.CommentsByCategoryLetter[category].Contains(id)) return error404();
|
||||||
if (id == "EDITIONEN" && !lib.CommentsByCategoryLetter.Keys.Contains(id.ToLower())) return error404();
|
if (id == "EDITIONEN" && !lib.CommentsByCategoryLetter.Keys.Contains(id.ToLower())) return error404();
|
||||||
|
|
||||||
@@ -175,6 +177,7 @@ public class RegisterController : Controller {
|
|||||||
private List<CommentModel> _createCommentModelForschungRegister(string category, IOrderedEnumerable<Comment>? comments) {
|
private List<CommentModel> _createCommentModelForschungRegister(string category, IOrderedEnumerable<Comment>? comments) {
|
||||||
var lib = _lib.GetLibrary();
|
var lib = _lib.GetLibrary();
|
||||||
var res = new List<CommentModel>();
|
var res = new List<CommentModel>();
|
||||||
|
if (comments == null) return res;
|
||||||
foreach (var comm in comments) {
|
foreach (var comm in comments) {
|
||||||
var parsedComment = HTMLHelpers.CommentHelpers.CreateHTML(lib, _readerService, comm, category, Settings.ParsingState.CommentType.Comment);
|
var parsedComment = HTMLHelpers.CommentHelpers.CreateHTML(lib, _readerService, comm, category, Settings.ParsingState.CommentType.Comment);
|
||||||
List<string>? parsedSubComments = null;
|
List<string>? parsedSubComments = null;
|
||||||
@@ -192,6 +195,7 @@ public class RegisterController : Controller {
|
|||||||
private List<CommentModel> _createCommentModelBibel(string category, IOrderedEnumerable<Comment>? comments) {
|
private List<CommentModel> _createCommentModelBibel(string category, IOrderedEnumerable<Comment>? comments) {
|
||||||
var lib = _lib.GetLibrary();
|
var lib = _lib.GetLibrary();
|
||||||
var res = new List<CommentModel>();
|
var res = new List<CommentModel>();
|
||||||
|
if (comments == null) return res;
|
||||||
foreach (var comm in comments) {
|
foreach (var comm in comments) {
|
||||||
var parsedComment = HTMLHelpers.CommentHelpers.CreateHTML(lib, _readerService, comm, category, Settings.ParsingState.CommentType.Comment);
|
var parsedComment = HTMLHelpers.CommentHelpers.CreateHTML(lib, _readerService, comm, category, Settings.ParsingState.CommentType.Comment);
|
||||||
List<string>? parsedSubComments = null;
|
List<string>? parsedSubComments = null;
|
||||||
|
|||||||
@@ -68,8 +68,6 @@ public class SucheController : Controller {
|
|||||||
List<IGrouping<int, Meta>>? metasbyyear = null;
|
List<IGrouping<int, Meta>>? metasbyyear = null;
|
||||||
if (search != null) {
|
if (search != null) {
|
||||||
search = search.Trim();
|
search = search.Trim();
|
||||||
var sw = new System.Diagnostics.Stopwatch();
|
|
||||||
sw.Start();
|
|
||||||
var res = _lib.SearchLetters(search, _readerService);
|
var res = _lib.SearchLetters(search, _readerService);
|
||||||
if (res == null || !res.Any()) return _error404();
|
if (res == null || !res.Any()) return _error404();
|
||||||
var ret = res.ToDictionary(
|
var ret = res.ToDictionary(
|
||||||
@@ -80,8 +78,6 @@ public class SucheController : Controller {
|
|||||||
);
|
);
|
||||||
var keys = res.Select(x => x.Index).Where(x => lib.Metas.ContainsKey(x)).Select(x => lib.Metas[x]);
|
var keys = res.Select(x => x.Index).Where(x => lib.Metas.ContainsKey(x)).Select(x => lib.Metas[x]);
|
||||||
var letters = keys.ToLookup(x => x.Sort.Year).OrderBy(x => x.Key).ToList();
|
var letters = keys.ToLookup(x => x.Sort.Year).OrderBy(x => x.Key).ToList();
|
||||||
sw.Stop();
|
|
||||||
Console.WriteLine(sw.ElapsedMilliseconds);
|
|
||||||
return _paginateSend(lib, page, letters, null, null, null, search, ret);
|
return _paginateSend(lib, page, letters, null, null, null, search, ret);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,11 +72,11 @@ public class HaDocumentWrapper : IHaDocumentWrappper {
|
|||||||
rd.Read();
|
rd.Read();
|
||||||
if (state.Results != null)
|
if (state.Results != null)
|
||||||
res.Add((
|
res.Add((
|
||||||
letter.Index,
|
letter.Index,
|
||||||
state.Results.Select(x => (
|
state.Results.Select(x => (
|
||||||
x.Page,
|
x.Page,
|
||||||
x.Line,
|
x.Line,
|
||||||
parser.Lines != null ?
|
parser.Lines != null ?
|
||||||
parser.Lines
|
parser.Lines
|
||||||
.Where(y => y.Page == x.Page && y.Line == x.Line)
|
.Where(y => y.Page == x.Page && y.Line == x.Line)
|
||||||
.Select(x => x.Text)
|
.Select(x => x.Text)
|
||||||
|
|||||||
@@ -7,5 +7,5 @@ public interface IHaDocumentWrappper {
|
|||||||
public ILibrary ResetLibrary();
|
public ILibrary ResetLibrary();
|
||||||
public ILibrary? SetLibrary(string filepath, ModelStateDictionary ModelState);
|
public ILibrary? SetLibrary(string filepath, ModelStateDictionary ModelState);
|
||||||
public ILibrary GetLibrary();
|
public ILibrary GetLibrary();
|
||||||
public List<(string Index, List<(string Page, string Line, string Preview)> Results)>? SearchLetters(string searchword, IReaderService reader);
|
public List<(string Index, List<(string Page, string Line, string Preview)> Results)>? SearchLetters(string searchword, IReaderService reader);
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ public class LinkHelper {
|
|||||||
reader.Tag += OnTag;
|
reader.Tag += OnTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTag(object _, Tag tag) {
|
private void OnTag(object? _, Tag tag) {
|
||||||
if (tag.Name == "wwwlink" || tag.Name == "intlink" || tag.Name == "link") {
|
if (tag.Name == "wwwlink" || tag.Name == "intlink" || tag.Name == "link") {
|
||||||
if (tag.EndTag && _followlinksinthis) {
|
if (tag.EndTag && _followlinksinthis) {
|
||||||
_sb.Append(HTMLHelpers.TagHelpers.CreateEndElement("a"));
|
_sb.Append(HTMLHelpers.TagHelpers.CreateEndElement("a"));
|
||||||
@@ -68,7 +68,7 @@ public class LinkHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tag.Name == "link" && tag.Values != null) {
|
if (tag.Name == "link" && tag.Values != null) {
|
||||||
Comment comment = null;
|
Comment? comment = null;
|
||||||
if (tag.Values.ContainsKey("subref") && _lib.SubCommentsByID.ContainsKey(tag["subref"]))
|
if (tag.Values.ContainsKey("subref") && _lib.SubCommentsByID.ContainsKey(tag["subref"]))
|
||||||
comment = _lib.SubCommentsByID[tag["subref"]];
|
comment = _lib.SubCommentsByID[tag["subref"]];
|
||||||
else if (tag.Values.ContainsKey("ref"))
|
else if (tag.Values.ContainsKey("ref"))
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public class LineXMLHelper<T> {
|
|||||||
_CTag_Funcs = CTag_Funcs;
|
_CTag_Funcs = CTag_Funcs;
|
||||||
_Text_Funcs = Text_Funcs;
|
_Text_Funcs = Text_Funcs;
|
||||||
_WS_Funcs = WS_Funcs;
|
_WS_Funcs = WS_Funcs;
|
||||||
|
|
||||||
OpenTags = new Stack<Tag>();
|
OpenTags = new Stack<Tag>();
|
||||||
LastSingleTags = new Dictionary<string, List<Tag>>();
|
LastSingleTags = new Dictionary<string, List<Tag>>();
|
||||||
LastText = new StringBuilder();
|
LastText = new StringBuilder();
|
||||||
|
|||||||
@@ -13,5 +13,6 @@ public class FileModel {
|
|||||||
IsUsed = isUsed;
|
IsUsed = isUsed;
|
||||||
LastModified = lastModified;
|
LastModified = lastModified;
|
||||||
InProduction = inProduction;
|
InProduction = inProduction;
|
||||||
|
Prefix = prefix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@ public class SucheViewModel {
|
|||||||
public int Count { get; private set; }
|
public int Count { get; private set; }
|
||||||
public int ActiveYear { get; private set; }
|
public int ActiveYear { get; private set; }
|
||||||
public List<(int StartYear, int EndYear)>? AvailableYears { get; private set; }
|
public List<(int StartYear, int EndYear)>? AvailableYears { get; private set; }
|
||||||
public string? ActivePerson {get; set; }
|
public string? ActivePerson { get; set; }
|
||||||
public List<(string Key, string Name)>? AvailablePersons { get; private set; }
|
public List<(string Key, string Name)>? AvailablePersons { get; private set; }
|
||||||
public List<(string Volume, List<string> Pages)>? AvailablePages { get; private set; }
|
public List<(string Volume, List<string> Pages)>? AvailablePages { get; private set; }
|
||||||
public string? ActiveVolume { get; private set; }
|
public string? ActiveVolume { get; private set; }
|
||||||
@@ -15,10 +15,10 @@ public class SucheViewModel {
|
|||||||
public Dictionary<string, List<SearchResult>>? SearchResults { get; private set; }
|
public Dictionary<string, List<SearchResult>>? SearchResults { get; private set; }
|
||||||
|
|
||||||
public SucheViewModel(
|
public SucheViewModel(
|
||||||
List<(int Year, List<BriefeMetaViewModel> LetterList)>? letters,
|
List<(int Year, List<BriefeMetaViewModel> LetterList)>? letters,
|
||||||
int activeYear,
|
int activeYear,
|
||||||
List<(int StartYear, int EndYear)>? availableYears,
|
List<(int StartYear, int EndYear)>? availableYears,
|
||||||
List<(string Key, string Name)>? availablePersons,
|
List<(string Key, string Name)>? availablePersons,
|
||||||
List<(string Volume, List<string> Pages)>? availablePages,
|
List<(string Volume, List<string> Pages)>? availablePages,
|
||||||
string? activeVolume,
|
string? activeVolume,
|
||||||
string? activePage,
|
string? activePage,
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ public class SearchRules {
|
|||||||
public static readonly TextFuncList TextRules = new TextFuncList() {
|
public static readonly TextFuncList TextRules = new TextFuncList() {
|
||||||
( (x, _) => true, (sb, text, reader) => {
|
( (x, _) => true, (sb, text, reader) => {
|
||||||
var t = text.Value;
|
var t = text.Value;
|
||||||
if (reader.State.Normalize)
|
if (reader.State.Normalize)
|
||||||
t = HaWeb.SearchHelpers.StringHelpers.NormalizeWhiteSpace(t);
|
t = HaWeb.SearchHelpers.StringHelpers.NormalizeWhiteSpace(t);
|
||||||
sb.Append(t);
|
sb.Append(t);
|
||||||
var sw = reader.State.SearchWord;
|
var sw = reader.State.SearchWord;
|
||||||
if (sb.Length >= sw.Length) {
|
if (sb.Length >= sw.Length) {
|
||||||
if (sb.ToString().ToLower().Contains(sw)) {
|
if (sb.ToString().ToLower().Contains(sw)) {
|
||||||
if (reader.State.Results == null)
|
if (reader.State.Results == null)
|
||||||
reader.State.Results = new List<(string Page, string Line)>();
|
reader.State.Results = new List<(string Page, string Line)>();
|
||||||
reader.State.Results.Add((reader.CurrentPage, reader.CurrentLine));
|
reader.State.Results.Add((reader.CurrentPage, reader.CurrentLine));
|
||||||
}
|
}
|
||||||
@@ -26,16 +26,16 @@ public class SearchRules {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
public static readonly WhitespaceFuncList WhitespaceRules= new WhitespaceFuncList() {
|
public static readonly WhitespaceFuncList WhitespaceRules = new WhitespaceFuncList() {
|
||||||
( (x, _) => true, (sb, text, reader) => {
|
( (x, _) => true, (sb, text, reader) => {
|
||||||
var t = text.Value;
|
var t = text.Value;
|
||||||
if (reader.State.Normalize)
|
if (reader.State.Normalize)
|
||||||
t = HaWeb.SearchHelpers.StringHelpers.NormalizeWhiteSpace(t);
|
t = HaWeb.SearchHelpers.StringHelpers.NormalizeWhiteSpace(t);
|
||||||
sb.Append(t);
|
sb.Append(t);
|
||||||
var sw = reader.State.SearchWord;
|
var sw = reader.State.SearchWord;
|
||||||
if (sb.Length >= sw.Length) {
|
if (sb.Length >= sw.Length) {
|
||||||
if (sb.ToString().Contains(sw)) {
|
if (sb.ToString().Contains(sw)) {
|
||||||
if (reader.State.Results == null)
|
if (reader.State.Results == null)
|
||||||
reader.State.Results = new List<(string Page, string Line)>();
|
reader.State.Results = new List<(string Page, string Line)>();
|
||||||
reader.State.Results.Add((reader.CurrentPage, reader.CurrentLine));
|
reader.State.Results.Add((reader.CurrentPage, reader.CurrentLine));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<div class="ha-searchhead">
|
<div class="ha-searchhead">
|
||||||
<h1>Briefauswahl</h1>
|
<h1>Briefauswahl</h1>
|
||||||
<div class="ha-searchnav">
|
<div class="ha-searchnav">
|
||||||
@if (Model.AvailableYears != null && Model.AvailableYears.Any()) {
|
@if (Model.AvailableYears != null && Model.AvailableYears.Any() && Model.AvailableYears.Count > 1) {
|
||||||
@for(var i = 0; i < Model.AvailableYears.Count; i++) {
|
@for(var i = 0; i < Model.AvailableYears.Count; i++) {
|
||||||
<a class="@(Model.ActiveYear == i ? "active" : "")" asp-route-person="@Model.ActivePerson" asp-route-search="@Model.ActiveSearch" asp-controller="Suche" asp-route-page="@i">
|
<a class="@(Model.ActiveYear == i ? "active" : "")" asp-route-person="@Model.ActivePerson" asp-route-search="@Model.ActiveSearch" asp-controller="Suche" asp-route-page="@i">
|
||||||
@if (Model.AvailableYears[i].StartYear != Model.AvailableYears[i].EndYear) {
|
@if (Model.AvailableYears[i].StartYear != Model.AvailableYears[i].EndYear) {
|
||||||
|
|||||||
Reference in New Issue
Block a user