mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
* Fixed a bug where cache TTL was using a field which always was 0. * Updated Scan Series task (from UI) to always re-calculate what's on file and not rely on last update. This leads to more reliable results, despite extra overhead. * Added image range processing on images for the reader, for slower networks or large files * On manga (single) try to use prefetched image, rather than re-requesting an image on pagination * Reduced some more latency when rendering first page of next chapter via continuous reading mode * Fixed a bug where metadata filter, after updating a typeahead, collapsing filter area then re-opening, the filter would still be applied, but the typeahead wouldn't show the modification. * Coded an idea around download reporting, commiting for history, might not go with it. * Refactored the download indicator into it's own component. Cleaning up some code for download within card component * Another throw away commit. Put in some temp code, not working but not sure if I'm ditching entirely. * Updated download service to enable range processing (so downloads can resume) and to reduce re-zipping if we've just downloaded something. * Refactored events widget download indicator to the correct design. I will be moving forward with this new functionality. * Added Required fields to ProgressDTO * Cleaned up the event widget and updated existing download progress to indicate preparing the download, rather than the download itself. * Updated dependencies for security alerts * Refactored all download code to be streamlined and globally handled * Updated ScanSeries to find the highest folder path before library, not just within the files. This could lead to scan series missing files due to nested folders on same parent level. * Updated the caching code to use a builtin annotation. Images are now caching correctly. * Fixed a bad redirect on an auth guard * Tweaked how long we allow cache for, as the cover update now doesn't work well. * Fixed a bug on downloading bookmarks from multiple series, where it would just choose the first series id for the temp file. * Added an extra check for downloading bookmarks * UI Security updates, Fixed a bug on bookmark reader, the reader on last page would throw some errors and not show No Next Chapter toast. * After scan, clear temp * Code smells
44 lines
1.6 KiB
C#
44 lines
1.6 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using API.Helpers;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Net.Http.Headers;
|
|
|
|
namespace API.Extensions
|
|
{
|
|
public static class HttpExtensions
|
|
{
|
|
public static void AddPaginationHeader(this HttpResponse response, int currentPage,
|
|
int itemsPerPage, int totalItems, int totalPages)
|
|
{
|
|
var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages);
|
|
var options = new JsonSerializerOptions()
|
|
{
|
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
|
};
|
|
|
|
response.Headers.Add("Pagination", JsonSerializer.Serialize(paginationHeader, options));
|
|
response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Calculates SHA256 hash for a byte[] and sets as ETag. Ensures Cache-Control: private header is added.
|
|
/// </summary>
|
|
/// <param name="response"></param>
|
|
/// <param name="content">If byte[] is null or empty, will only add cache-control</param>
|
|
public static void AddCacheHeader(this HttpResponse response, byte[] content)
|
|
{
|
|
if (content is not {Length: > 0}) return;
|
|
using var sha1 = SHA256.Create();
|
|
|
|
response.Headers.Add(HeaderNames.ETag, string.Concat(sha1.ComputeHash(content).Select(x => x.ToString("X2"))));
|
|
response.Headers.CacheControl = $"private,max-age=100";
|
|
}
|
|
}
|
|
}
|