From 1b0c94b9a560f830df534c0779b29ecce6589771 Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Sat, 10 Jan 2026 08:47:12 +0100 Subject: [PATCH] fix(opds): temporary workaround for self-signed cert for OPDS server, closes #2871 (#2900) Related to https://github.com/seanmonstar/reqwest/issues/1554 --- apps/readest-app/src-tauri/src/transfer_file.rs | 6 +++++- apps/readest-app/src/app/opds/page.tsx | 2 ++ apps/readest-app/src/app/opds/utils/opdsReq.ts | 3 +++ apps/readest-app/src/libs/storage.ts | 12 +++++++++++- apps/readest-app/src/utils/transfer.ts | 2 ++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/apps/readest-app/src-tauri/src/transfer_file.rs b/apps/readest-app/src-tauri/src/transfer_file.rs index 4ba7c5b6..6a611b03 100644 --- a/apps/readest-app/src-tauri/src/transfer_file.rs +++ b/apps/readest-app/src-tauri/src/transfer_file.rs @@ -108,6 +108,7 @@ pub async fn download_file( headers: HashMap, body: Option, single_threaded: Option, + skip_ssl_verification: Option, on_progress: Channel, ) -> Result<()> { use futures::stream::{self, StreamExt}; @@ -116,7 +117,10 @@ pub async fn download_file( const PART_SIZE: u64 = 1024 * 1024; - let client = reqwest::Client::new(); + let client = reqwest::ClientBuilder::new() + .danger_accept_invalid_certs(skip_ssl_verification.unwrap_or(false)) + .danger_accept_invalid_hostnames(skip_ssl_verification.unwrap_or(false)) + .build()?; let force_single = single_threaded.unwrap_or(false); async fn single_threaded_download( diff --git a/apps/readest-app/src/app/opds/page.tsx b/apps/readest-app/src/app/opds/page.tsx index 280daf60..8f20368a 100644 --- a/apps/readest-app/src/app/opds/page.tsx +++ b/apps/readest-app/src/app/opds/page.tsx @@ -443,6 +443,7 @@ export default function BrowserPage() { url: downloadUrl, headers, singleThreaded: true, + skipSslVerification: true, onProgress, }); const { library, setLibrary } = useLibraryStore.getState(); @@ -498,6 +499,7 @@ export default function BrowserPage() { cfp: '', url: downloadUrl, singleThreaded: true, + skipSslVerification: true, headers, }); return await appService.getImageURL(cachedPath); diff --git a/apps/readest-app/src/app/opds/utils/opdsReq.ts b/apps/readest-app/src/app/opds/utils/opdsReq.ts index 39eadfc4..09d6640e 100644 --- a/apps/readest-app/src/app/opds/utils/opdsReq.ts +++ b/apps/readest-app/src/app/opds/utils/opdsReq.ts @@ -215,6 +215,7 @@ export const probeAuth = async ( const res = await fetch(fetchURL, { method: 'HEAD', headers, + danger: { acceptInvalidCerts: true, acceptInvalidHostnames: true }, }); // Check if authentication is required @@ -275,6 +276,7 @@ export const fetchWithAuth = async ( ...options, method: options.method || 'GET', headers, + danger: { acceptInvalidCerts: true, acceptInvalidHostnames: true }, }); // Handle authentication if needed @@ -302,6 +304,7 @@ export const fetchWithAuth = async ( ...options, method: options.method || 'GET', headers: useProxy ? headers : { ...headers, Authorization: authHeader }, + danger: { acceptInvalidCerts: true, acceptInvalidHostnames: true }, }); } } diff --git a/apps/readest-app/src/libs/storage.ts b/apps/readest-app/src/libs/storage.ts index a1ae07fc..e5de573e 100644 --- a/apps/readest-app/src/libs/storage.ts +++ b/apps/readest-app/src/libs/storage.ts @@ -111,6 +111,7 @@ type DownloadFileParams = { url?: string; headers?: Record; singleThreaded?: boolean; + skipSslVerification?: boolean; onProgress?: ProgressHandler; }; @@ -121,6 +122,7 @@ export const downloadFile = async ({ url, headers, singleThreaded, + skipSslVerification, onProgress, }: DownloadFileParams) => { try { @@ -150,7 +152,15 @@ export const downloadFile = async ({ const file = await webDownload(downloadUrl, onProgress, headers); await appService.writeFile(dst, 'None', await file.arrayBuffer()); } else { - await tauriDownload(downloadUrl, dst, onProgress, headers, undefined, singleThreaded); + await tauriDownload( + downloadUrl, + dst, + onProgress, + headers, + undefined, + singleThreaded, + skipSslVerification, + ); } } catch (error) { console.error(`File '${dst}' download failed:`, error); diff --git a/apps/readest-app/src/utils/transfer.ts b/apps/readest-app/src/utils/transfer.ts index 49d4b9f8..bab648f7 100644 --- a/apps/readest-app/src/utils/transfer.ts +++ b/apps/readest-app/src/utils/transfer.ts @@ -123,6 +123,7 @@ export const tauriDownload = async ( headers?: Record, body?: string, singleThreaded?: boolean, + skipSslVerification?: boolean, ): Promise => { const ids = new Uint32Array(1); window.crypto.getRandomValues(ids); @@ -141,5 +142,6 @@ export const tauriDownload = async ( onProgress, body, singleThreaded, + skipSslVerification, }); };