Cleanup code and merge conflict left in PR.
This commit is contained in:
parent
180b49b8ea
commit
87b1a807ea
5 changed files with 1337 additions and 109 deletions
|
|
@ -17,8 +17,6 @@
|
||||||
<Exec Command="swagger tofile --output ../openapi.json bin/$(Configuration)/$(TargetFramework)/$(AssemblyName).dll v1" />
|
<Exec Command="swagger tofile --output ../openapi.json bin/$(Configuration)/$(TargetFramework)/$(AssemblyName).dll v1" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
=======
|
|
||||||
>>>>>>> fc7f84f2bffadf9a0127d35fa01166c847b20dc0
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
<DebugSymbols>false</DebugSymbols>
|
<DebugSymbols>false</DebugSymbols>
|
||||||
<ApplicationIcon>../favicon.ico</ApplicationIcon>
|
<ApplicationIcon>../favicon.ico</ApplicationIcon>
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@ public class MangaFile : IEntityDate
|
||||||
public required string FilePath { get; set; }
|
public required string FilePath { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A hash of the document using Koreader's unique hashing algorithm
|
/// A hash of the document using Koreader's unique hashing algorithm
|
||||||
/// <remark> KoreaderHash is only available for epub types </remark>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remark> KoreaderHash is only available for epub types </remark>
|
||||||
public string? KoreaderHash { get; set; }
|
public string? KoreaderHash { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Number of pages for the given file
|
/// Number of pages for the given file
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using API.Entities;
|
using API.Entities;
|
||||||
using API.Entities.Enums;
|
using API.Entities.Enums;
|
||||||
|
|
@ -61,12 +61,15 @@ public class MangaFileBuilder : IEntityBuilder<MangaFile>
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generate the Hash on the underlying file
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Only applicable to Epubs</remarks>
|
||||||
public MangaFileBuilder WithHash()
|
public MangaFileBuilder WithHash()
|
||||||
{
|
{
|
||||||
if (_mangaFile.Format == MangaFormat.Epub)
|
if (_mangaFile.Format != MangaFormat.Epub) return this;
|
||||||
{
|
|
||||||
_mangaFile.KoreaderHash = KoreaderHelper.HashContents(_mangaFile.FilePath);
|
_mangaFile.KoreaderHash = KoreaderHelper.HashContents(_mangaFile.FilePath);
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,8 @@
|
||||||
using API.DTOs.Koreader;
|
|
||||||
using API.DTOs.Progress;
|
using API.DTOs.Progress;
|
||||||
using API.Services;
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace API.Helpers;
|
namespace API.Helpers;
|
||||||
|
|
||||||
|
|
@ -21,17 +17,17 @@ public static class KoreaderHelper
|
||||||
/// <param name="filePath">The path to the file to hash</param>
|
/// <param name="filePath">The path to the file to hash</param>
|
||||||
public static string HashContents(string filePath)
|
public static string HashContents(string filePath)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(filePath))
|
if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
using var file = File.OpenRead(filePath);
|
using var file = File.OpenRead(filePath);
|
||||||
|
|
||||||
var step = 1024;
|
const int step = 1024;
|
||||||
var size = 1024;
|
const int size = 1024;
|
||||||
MD5 md5 = MD5.Create();
|
var md5 = MD5.Create();
|
||||||
byte[] buffer = new byte[size];
|
var buffer = new byte[size];
|
||||||
|
|
||||||
for (var i = -1; i < 10; i++)
|
for (var i = -1; i < 10; i++)
|
||||||
{
|
{
|
||||||
|
|
@ -48,15 +44,14 @@ public static class KoreaderHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
file.Close();
|
file.Close();
|
||||||
md5.TransformFinalBlock(new byte[0], 0, 0);
|
md5.TransformFinalBlock(Array.Empty<byte>(), 0, 0);
|
||||||
|
|
||||||
return BitConverter.ToString(md5.Hash).Replace("-", string.Empty).ToUpper();
|
|
||||||
|
|
||||||
|
return md5.Hash == null ? null : BitConverter.ToString(md5.Hash).Replace("-", string.Empty).ToUpper();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Koreader can identitfy documents based on contents or title.
|
/// Koreader can identify documents based on contents or title.
|
||||||
/// For now we only support by contents.
|
/// For now, we only support by contents.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string HashTitle(string filePath)
|
public static string HashTitle(string filePath)
|
||||||
{
|
{
|
||||||
|
|
@ -74,16 +69,18 @@ public static class KoreaderHelper
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var docNumber = path[2].Replace("DocFragment[", string.Empty).Replace("]", string.Empty);
|
var docNumber = path[2].Replace("DocFragment[", string.Empty).Replace("]", string.Empty);
|
||||||
progress.PageNum = Int32.Parse(docNumber) - 1;
|
progress.PageNum = int.Parse(docNumber) - 1;
|
||||||
var lastTag = path[5].ToUpper();
|
var lastTag = path[5].ToUpper();
|
||||||
|
|
||||||
if (lastTag == "A")
|
if (lastTag == "A")
|
||||||
{
|
{
|
||||||
progress.BookScrollId = null;
|
progress.BookScrollId = null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// The format that Kavita accpets as a progress string. It tells Kavita where Koreader last left off.
|
// The format that Kavita accepts as a progress string. It tells Kavita where Koreader last left off.
|
||||||
progress.BookScrollId = $"//html[1]/BODY/APP-ROOT[1]/DIV[1]/DIV[1]/DIV[1]/APP-BOOK-READER[1]/DIV[1]/DIV[2]/DIV[1]/DIV[1]/DIV[1]/{lastTag}";
|
progress.BookScrollId = $"//html[1]/BODY/APP-ROOT[1]/DIV[1]/DIV[1]/DIV[1]/APP-BOOK-READER[1]/DIV[1]/DIV[2]/DIV[1]/DIV[1]/DIV[1]/{lastTag}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -99,7 +96,8 @@ public static class KoreaderHelper
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lastTag = progressDto.BookScrollId.Split('/').Last().ToLower();
|
var tokens = progressDto.BookScrollId.Split('/');
|
||||||
|
lastTag = tokens[^1].ToLower();
|
||||||
}
|
}
|
||||||
// The format that Koreader accepts as a progress string. It tells Koreader where Kavita last left off.
|
// The format that Koreader accepts as a progress string. It tells Koreader where Kavita last left off.
|
||||||
return $"/body/DocFragment[{koreaderPageNumber}]/body/div/{lastTag}";
|
return $"/body/DocFragment[{koreaderPageNumber}]/body/div/{lastTag}";
|
||||||
|
|
|
||||||
1395
openapi.json
1395
openapi.json
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue