Misc Fixes (#2155)

* Fixed default token key not being long enough and Kavita auto-generating

* When scheduling nightly backup job, make it run at 2am to ensure everything else has ran.

* Made the overlay system work better on mobile. In order to do this, had to implement my own copy button.

* Tweaked the code to ensure we clear the selection doing anything and clicking off the overlay clears more reliably.

* Cleaned up the overlay code

* Added the ability to view the series that a rating is representing. Requires Kavita+ deployment.

* When calculating overall average rating of server, if only review is yours, don't include it.

When calculating overall average rating of server, scale to percentage (* 20) to match all other rating scales.

* Fixed side nav on mobile without donate link not fully covering the height of the screen

* Only trigger the task conversion warning on Media screen if you've touched the appropriate control.

* Fixed a bug where bookmark directory wasn't able to be changed.

* Fixed a bug where see More wouldn't show if there were just characters due to missing that check.

* Fixed a typo in documentation

* If a chapter has a range 1-6 and is fully read, when calculating highest chapter for Scrobbling, use the 6.
This commit is contained in:
Joe Milazzo 2023-07-23 11:53:16 -05:00 committed by GitHub
parent 9e04276dfd
commit 52d19642f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 121 additions and 52 deletions

View file

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using API.Constants;
using API.Data;
using API.DTOs;
using API.Extensions;
using API.Services.Plus;
using EasyCaching.Core;
using Microsoft.AspNetCore.Mvc;
@ -69,7 +70,7 @@ public class RatingController : BaseApiController
return Ok(new RatingDto()
{
Provider = ScrobbleProvider.Kavita,
AverageScore = await _unitOfWork.SeriesRepository.GetAverageUserRating(seriesId),
AverageScore = await _unitOfWork.SeriesRepository.GetAverageUserRating(seriesId, User.GetUserId()),
FavoriteCount = 0
});
}

View file

@ -7,4 +7,5 @@ public class RatingDto
public int AverageScore { get; set; }
public int FavoriteCount { get; set; }
public ScrobbleProvider Provider { get; set; }
public string? ProviderUrl { get; set; }
}

View file

@ -6,6 +6,7 @@ using API.Data.ManualMigrations;
using API.DTOs;
using API.Entities;
using API.Entities.Enums;
using API.Services.Tasks.Scanner.Parser;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using Microsoft.EntityFrameworkCore;
@ -164,9 +165,9 @@ public class AppUserProgressRepository : IAppUserProgressRepository
(appUserProgresses, chapter) => new {appUserProgresses, chapter})
.Where(p => p.appUserProgresses.SeriesId == seriesId && p.appUserProgresses.AppUserId == userId &&
p.appUserProgresses.PagesRead >= p.chapter.Pages)
.Select(p => p.chapter.Number)
.Select(p => p.chapter.Range)
.ToListAsync();
return list.Count == 0 ? 0 : list.DefaultIfEmpty().Where(d => d != null).Max(d => (int) Math.Floor(float.Parse(d)));
return list.Count == 0 ? 0 : list.DefaultIfEmpty().Where(d => d != null).Max(d => (int) Math.Floor(Parser.MaxNumberFromRange(d)));
}
public async Task<int> GetHighestFullyReadVolumeForSeries(int seriesId, int userId)

View file

@ -137,7 +137,7 @@ public interface ISeriesRepository
Task<IList<SeriesMetadataDto>> GetSeriesMetadataForIds(IEnumerable<int> seriesIds);
Task<IList<Series>> GetAllWithCoversInDifferentEncoding(EncodeFormat encodeFormat, bool customOnly = true);
Task<SeriesDto?> GetSeriesDtoByNamesAndMetadataIdsForUser(int userId, IEnumerable<string> names, LibraryType libraryType, string aniListUrl, string malUrl);
Task<int> GetAverageUserRating(int seriesId);
Task<int> GetAverageUserRating(int seriesId, int userId);
Task RemoveFromOnDeck(int seriesId, int userId);
Task ClearOnDeckRemoval(int seriesId, int userId);
}
@ -1682,12 +1682,19 @@ public class SeriesRepository : ISeriesRepository
/// Returns the Average rating for all users within Kavita instance
/// </summary>
/// <param name="seriesId"></param>
public async Task<int> GetAverageUserRating(int seriesId)
public async Task<int> GetAverageUserRating(int seriesId, int userId)
{
// If there is 0 or 1 rating and that rating is you, return 0 back
var countOfRatingsThatAreUser = await _context.AppUserRating
.Where(r => r.SeriesId == seriesId).CountAsync(u => u.AppUserId == userId);
if (countOfRatingsThatAreUser == 1)
{
return 0;
}
var avg = (await _context.AppUserRating
.Where(r => r.SeriesId == seriesId)
.AverageAsync(r => (int?) r.Rating));
return avg.HasValue ? (int) avg.Value : 0;
return avg.HasValue ? (int) (avg.Value * 20) : 0;
}
public async Task RemoveFromOnDeck(int seriesId, int userId)

View file

@ -127,7 +127,13 @@ public class TaskScheduler : ITaskScheduler
if (setting != null)
{
_logger.LogDebug("Scheduling Backup Task for {Setting}", setting);
RecurringJob.AddOrUpdate(BackupTaskId, () => _backupService.BackupDatabase(), () => CronConverter.ConvertToCronNotation(setting), RecurringJobOptions);
var schedule = CronConverter.ConvertToCronNotation(setting);
if (schedule == Cron.Daily())
{
// Override daily and make 2am so that everything on system has cleaned up and no blocking
schedule = Cron.Daily(2);
}
RecurringJob.AddOrUpdate(BackupTaskId, () => _backupService.BackupDatabase(), () => schedule, RecurringJobOptions);
}
else
{

View file

@ -65,7 +65,7 @@ public class PresenceTracker : IPresenceTracker
_unitOfWork.UserRepository.Update(user);
await _unitOfWork.CommitAsync();
}
catch (Exception ex)
catch (Exception)
{
// Swallow the exception
}