Adds support for multiple chapters. The previous version ignored any leading chapter numbers in the uri of {chapterId}/images/{image}. It now accounts for that and is working in a locally run user interface for an epub that was broken. I didn't check in the unit test over the GetBookPage method since it requires a specific file. I'll provide that in the PR description, though.
This commit is contained in:
parent
8ed2fa3829
commit
4ca4723ae9
4 changed files with 134 additions and 13 deletions
|
|
@ -1,4 +1,6 @@
|
|||
using System.IO;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
||||
namespace API.Extensions;
|
||||
#nullable enable
|
||||
|
|
@ -12,4 +14,23 @@ public static class PathExtensions
|
|||
if (string.IsNullOrEmpty(extension)) return filepath;
|
||||
return Path.GetFullPath(filepath.Replace(extension, string.Empty));
|
||||
}
|
||||
|
||||
public static ReadOnlySpan<char> GetFirstSegmentSpan(this string urlKey)
|
||||
{
|
||||
var idx = urlKey.IndexOf('/');
|
||||
return idx < 0 ? urlKey.AsSpan() : urlKey.AsSpan()[..idx];
|
||||
}
|
||||
|
||||
public static ReadOnlySpan<char> GetLastSegmentSpan(this string urlKey)
|
||||
{
|
||||
var idx = urlKey.LastIndexOf('/');
|
||||
return idx < 0 ? urlKey.AsSpan() : urlKey.AsSpan().Slice(idx + 1);
|
||||
}
|
||||
|
||||
public static int? ParseInt(this ReadOnlySpan<char> s)
|
||||
{
|
||||
if (int.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out var value))
|
||||
return value;
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue