mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-07-09 03:04:19 -04:00
Enable response compression (br and gzip) for images and static assets. After we scan a library, kick of a cleanup of cache to ensure if archives were changed, the cache is cleared too.
This commit is contained in:
parent
2a8931406d
commit
d3b42081cb
@ -152,6 +152,46 @@ namespace API.Controllers
|
||||
return BadRequest("There was an issue saving progress");
|
||||
}
|
||||
|
||||
[HttpPost("mark-volume-read")]
|
||||
public async Task<ActionResult> MarkVolumeAsRead(MarkVolumeReadDto markVolumeReadDto)
|
||||
{
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
|
||||
_logger.LogDebug("Saving {UserName} progress for Volume {VolumeID} to read", user.UserName, markVolumeReadDto.VolumeId);
|
||||
|
||||
var chapters = await _unitOfWork.VolumeRepository.GetChaptersAsync(markVolumeReadDto.VolumeId);
|
||||
foreach (var chapter in chapters)
|
||||
{
|
||||
user.Progresses ??= new List<AppUserProgress>();
|
||||
var userProgress = user.Progresses.SingleOrDefault(x => x.ChapterId == chapter.Id && x.AppUserId == user.Id);
|
||||
|
||||
if (userProgress == null)
|
||||
{
|
||||
user.Progresses.Add(new AppUserProgress
|
||||
{
|
||||
PagesRead = chapter.Pages,
|
||||
VolumeId = markVolumeReadDto.VolumeId,
|
||||
SeriesId = markVolumeReadDto.SeriesId,
|
||||
ChapterId = chapter.Id
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
userProgress.PagesRead = chapter.Pages;
|
||||
userProgress.SeriesId = markVolumeReadDto.SeriesId;
|
||||
userProgress.VolumeId = markVolumeReadDto.VolumeId;
|
||||
}
|
||||
}
|
||||
|
||||
_unitOfWork.UserRepository.Update(user);
|
||||
|
||||
if (await _unitOfWork.Complete())
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
return BadRequest("Could not save progress");
|
||||
}
|
||||
|
||||
[HttpPost("bookmark")]
|
||||
public async Task<ActionResult> Bookmark(BookmarkDto bookmarkDto)
|
||||
{
|
||||
|
8
API/DTOs/MarkVolumeReadDto.cs
Normal file
8
API/DTOs/MarkVolumeReadDto.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace API.DTOs
|
||||
{
|
||||
public class MarkVolumeReadDto
|
||||
{
|
||||
public int SeriesId { get; init; }
|
||||
public int VolumeId { get; init; }
|
||||
}
|
||||
}
|
@ -35,9 +35,22 @@ namespace API.Data
|
||||
{
|
||||
return await _context.Chapter
|
||||
.Include(c => c.Files)
|
||||
.AsNoTracking()
|
||||
.SingleOrDefaultAsync(c => c.Id == chapterId);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns Chapters for a volume id.
|
||||
/// </summary>
|
||||
/// <param name="volumeId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IList<Chapter>> GetChaptersAsync(int volumeId)
|
||||
{
|
||||
return await _context.Chapter
|
||||
.Where(c => c.VolumeId == volumeId)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
public async Task<ChapterDto> GetChapterDtoAsync(int chapterId)
|
||||
{
|
||||
|
@ -11,5 +11,6 @@ namespace API.Interfaces
|
||||
Task<Chapter> GetChapterAsync(int chapterId);
|
||||
Task<ChapterDto> GetChapterDtoAsync(int chapterId);
|
||||
Task<IList<MangaFile>> GetFilesForChapter(int chapterId);
|
||||
Task<IList<Chapter>> GetChaptersAsync(int volumeId);
|
||||
}
|
||||
}
|
@ -78,6 +78,8 @@ namespace API.Services
|
||||
{
|
||||
_logger.LogInformation("Enqueuing library scan for: {LibraryId}", libraryId);
|
||||
BackgroundJob.Enqueue(() => _scannerService.ScanLibrary(libraryId, forceUpdate));
|
||||
BackgroundJob.Enqueue(() => _cleanupService.Cleanup()); // When we do a scan, force cache to re-unpack in case page numbers change
|
||||
|
||||
}
|
||||
|
||||
public void CleanupChapters(int[] chapterIds)
|
||||
|
@ -41,17 +41,19 @@ namespace API
|
||||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" });
|
||||
});
|
||||
// This doesn't seem to work.
|
||||
// services.AddResponseCompression(options =>
|
||||
// {
|
||||
// options.Providers.Add<BrotliCompressionProvider>();
|
||||
// options.MimeTypes =
|
||||
// ResponseCompressionDefaults.MimeTypes.Concat(
|
||||
// new[] { "image/jpeg", "image/jpg" });
|
||||
// });
|
||||
// services.Configure<BrotliCompressionProviderOptions>(options =>
|
||||
// {
|
||||
// options.Level = CompressionLevel.Fastest;
|
||||
// });
|
||||
services.AddResponseCompression(options =>
|
||||
{
|
||||
options.Providers.Add<BrotliCompressionProvider>();
|
||||
options.Providers.Add<GzipCompressionProvider>();
|
||||
options.MimeTypes =
|
||||
ResponseCompressionDefaults.MimeTypes.Concat(
|
||||
new[] { "image/jpeg", "image/jpg" });
|
||||
options.EnableForHttps = true;
|
||||
});
|
||||
services.Configure<BrotliCompressionProviderOptions>(options =>
|
||||
{
|
||||
options.Level = CompressionLevel.Fastest;
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
@ -67,6 +69,7 @@ namespace API
|
||||
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1"));
|
||||
app.UseHangfireDashboard();
|
||||
}
|
||||
app.UseResponseCompression();
|
||||
|
||||
app.UseForwardedHeaders();
|
||||
|
||||
@ -85,7 +88,7 @@ namespace API
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseDefaultFiles();
|
||||
|
||||
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
ContentTypeProvider = new FileExtensionContentTypeProvider()
|
||||
|
@ -8,7 +8,8 @@
|
||||
"Default": "Debug",
|
||||
"Microsoft": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Error",
|
||||
"Hangfire": "Information"
|
||||
"Hangfire": "Information",
|
||||
"Microsoft.AspNetCore.Hosting.Internal.WebHost": "Information"
|
||||
},
|
||||
"File": {
|
||||
"Path": "kavita.log",
|
||||
|
Loading…
x
Reference in New Issue
Block a user