From 61fcb53245b87ed26d112ba831214267121ffdbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D1=83=D1=80=D0=BD=D0=B0=D1=82=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9?= Date: Tue, 10 Mar 2026 00:08:20 +0300 Subject: [PATCH] edit --- BookReader/Resources/Raw/wwwroot/index.html | 45 +++++++++++++-------- BookReader/Services/CalibreWebService.cs | 7 +++- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/BookReader/Resources/Raw/wwwroot/index.html b/BookReader/Resources/Raw/wwwroot/index.html index 428baae..636496b 100644 --- a/BookReader/Resources/Raw/wwwroot/index.html +++ b/BookReader/Resources/Raw/wwwroot/index.html @@ -626,9 +626,31 @@ } }; + function applyEpubReaderStyles(palette) { + if (!state.rendition) { + return; + } + + state.rendition.themes.default({ + 'body': { + 'font-family': state.currentFontFamily + ' !important', + 'font-size': state.currentFontSize + 'px !important', + 'line-height': '1.6 !important', + 'padding': '15px !important', + 'background-color': palette.background + ' !important', + 'color': palette.color + ' !important' + }, + 'p': { 'text-indent': '1.5em', 'margin-bottom': '0.5em' } + }); + state.rendition.themes.fontSize(state.currentFontSize + 'px'); + state.rendition.themes.font(state.currentFontFamily); + } + window.setFontSize = function (size) { // Изменение размера шрифта state.currentFontSize = size; - if (state.bookFormat === 'epub' && state.rendition) state.rendition.themes.fontSize(size + 'px'); + if (state.bookFormat === 'epub' && state.rendition) { + applyEpubReaderStyles(getThemePalette(state.currentTheme)); + } else if (state.bookFormat === 'fb2') { const inner = $('fb2-inner'); if (inner) { @@ -640,7 +662,9 @@ window.setFontFamily = function (family) { // Изменение гарнитуры шрифта state.currentFontFamily = family; - if (state.bookFormat === 'epub' && state.rendition) state.rendition.themes.font(family); + if (state.bookFormat === 'epub' && state.rendition) { + applyEpubReaderStyles(getThemePalette(state.currentTheme)); + } else if (state.bookFormat === 'fb2') { const inner = $('fb2-inner'); if (inner) { @@ -667,21 +691,7 @@ els.bookContent.style.backgroundColor = palette.background; els.fb2Content.style.backgroundColor = palette.background; - if (state.rendition) { - state.rendition.themes.default({ - 'body': { - 'font-family': state.currentFontFamily + ' !important', - 'font-size': state.currentFontSize + 'px !important', - 'line-height': '1.6 !important', - 'padding': '15px !important', - 'background-color': palette.background + ' !important', - 'color': palette.color + ' !important' - }, - 'p': { 'text-indent': '1.5em', 'margin-bottom': '0.5em' } - }); - state.rendition.themes.fontSize(state.currentFontSize + 'px'); - state.rendition.themes.font(state.currentFontFamily); - } + applyEpubReaderStyles(palette); const inner = $('fb2-inner'); if (inner) { @@ -748,3 +758,4 @@ + diff --git a/BookReader/Services/CalibreWebService.cs b/BookReader/Services/CalibreWebService.cs index 58b6fa0..3749289 100644 --- a/BookReader/Services/CalibreWebService.cs +++ b/BookReader/Services/CalibreWebService.cs @@ -14,6 +14,7 @@ public class CalibreWebService : ICalibreWebService private const string OpdsAcquisitionRel = "http://opds-spec.org/acquisition"; private const string OpdsImageRel = "http://opds-spec.org/image"; private const string OpdsThumbnailRel = "http://opds-spec.org/image/thumbnail"; + private const string CalibreDownloadUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"; private readonly HttpClient _httpClient; private readonly ICoverCacheService _coverCacheService; @@ -131,7 +132,10 @@ public class CalibreWebService : ICalibreWebService var fileName = $"{Guid.NewGuid()}.{book.Format}"; var filePath = Path.Combine(booksDir, fileName); - using var response = await _httpClient.GetAsync(downloadUri, HttpCompletionOption.ResponseHeadersRead); + using var request = new HttpRequestMessage(HttpMethod.Get, downloadUri); + request.Headers.UserAgent.ParseAdd(CalibreDownloadUserAgent); + + using var response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead); var hasAuthorizationHeader = _httpClient.DefaultRequestHeaders.Authorization != null; if (response.StatusCode == HttpStatusCode.Unauthorized || response.StatusCode == HttpStatusCode.Forbidden) @@ -558,3 +562,4 @@ public class CalibreWebService : ICalibreWebService +