This commit is contained in:
Курнат Андрей
2026-03-10 00:08:20 +03:00
parent c40df55ce7
commit 61fcb53245
2 changed files with 34 additions and 18 deletions

View File

@@ -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 @@
</html>

View File

@@ -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