mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-06-05 14:25:17 -04:00
Koreader Progress Sync Issues (#4319)
This commit is contained in:
@@ -19,10 +19,8 @@ namespace API.Controllers;
|
||||
/// Koreader uses a different form of authentication. It stores the username and password in headers.
|
||||
/// https://github.com/koreader/koreader/blob/master/plugins/kosync.koplugin/KOSyncClient.lua
|
||||
/// </remarks>
|
||||
[AllowAnonymous]
|
||||
public class KoreaderController : BaseApiController
|
||||
{
|
||||
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly IKoreaderService _koreaderService;
|
||||
@@ -37,23 +35,10 @@ public class KoreaderController : BaseApiController
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
// We won't allow users to be created from Koreader. Rather, they
|
||||
// must already have an account.
|
||||
/*
|
||||
[HttpPost("/users/create")]
|
||||
public IActionResult CreateUser(CreateUserRequest request)
|
||||
{
|
||||
}
|
||||
*/
|
||||
|
||||
[HttpGet("{apiKey}/users/auth")]
|
||||
public async Task<IActionResult> Authenticate(string apiKey)
|
||||
public IActionResult Authenticate(string apiKey)
|
||||
{
|
||||
var userId = await GetUserId(apiKey);
|
||||
var user = await _unitOfWork.UserRepository.GetUserByIdAsync(userId);
|
||||
if (user == null) return Unauthorized();
|
||||
|
||||
return Ok(new { username = user.UserName });
|
||||
return Ok(new { username = Username });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -67,8 +52,7 @@ public class KoreaderController : BaseApiController
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = await GetUserId(apiKey);
|
||||
await _koreaderService.SaveProgress(request, userId);
|
||||
await _koreaderService.SaveProgress(request, UserId);
|
||||
|
||||
return Ok(new KoreaderProgressUpdateDto{ Document = request.document, Timestamp = DateTime.UtcNow });
|
||||
}
|
||||
@@ -89,9 +73,8 @@ public class KoreaderController : BaseApiController
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = await GetUserId(apiKey);
|
||||
var response = await _koreaderService.GetProgress(ebookHash, userId);
|
||||
_logger.LogDebug("Koreader response progress for User ({UserId}): {Progress}", userId, response.progress.Sanitize());
|
||||
var response = await _koreaderService.GetProgress(ebookHash, UserId);
|
||||
_logger.LogDebug("Koreader response progress for User ({UserName}): {Progress}", Username, response.progress.Sanitize());
|
||||
|
||||
|
||||
// We must pack this manually for Koreader due to a bug in their code: https://github.com/koreader/koreader/issues/13629
|
||||
@@ -109,16 +92,4 @@ public class KoreaderController : BaseApiController
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<int> GetUserId(string apiKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _unitOfWork.UserRepository.GetUserIdByAuthKeyAsync(apiKey);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new KavitaException(await _localizationService.Get("en", "user-doesnt-exist"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user