From 3cf1bc825ebda0247f7f648583df9947b7609d90 Mon Sep 17 00:00:00 2001 From: Sucukdeluxe Date: Fri, 6 Mar 2026 12:09:39 +0100 Subject: [PATCH] Release v1.6.81 --- package-lock.json | 4 ++-- package.json | 2 +- src/main/bestdebrid-web.ts | 42 ++++++++++++++++++++++++++++++++++-- tests/bestdebrid-web.test.ts | 25 +++++++++++++++++++++ 4 files changed, 68 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7017f39..da7748d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "real-debrid-downloader", - "version": "1.6.80", + "version": "1.6.81", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "real-debrid-downloader", - "version": "1.6.80", + "version": "1.6.81", "license": "MIT", "dependencies": { "adm-zip": "^0.5.16", diff --git a/package.json b/package.json index 9398894..062a6d7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "real-debrid-downloader", - "version": "1.6.80", + "version": "1.6.81", "description": "Desktop downloader", "main": "build/main/main/main.js", "author": "Sucukdeluxe", diff --git a/src/main/bestdebrid-web.ts b/src/main/bestdebrid-web.ts index 2f6dcc2..6e39e8e 100644 --- a/src/main/bestdebrid-web.ts +++ b/src/main/bestdebrid-web.ts @@ -52,6 +52,32 @@ interface NetscapeCookie { value: string; } +function normalizeCookieDomain(domain: string): string { + return String(domain || "").trim().replace(/^\./, "").toLowerCase(); +} + +function dedupeCookies(cookies: NetscapeCookie[]): NetscapeCookie[] { + const deduped = new Map(); + for (const cookie of cookies) { + const key = `${normalizeCookieDomain(cookie.domain)}\t${cookie.path}\t${cookie.name}`; + const existing = deduped.get(key); + if (!existing) { + deduped.set(key, cookie); + continue; + } + + if (cookie.httpOnly && !existing.httpOnly) { + deduped.set(key, cookie); + continue; + } + + if (cookie.expirationDate > existing.expirationDate) { + deduped.set(key, cookie); + } + } + return [...deduped.values()]; +} + function parseNetscapeCookieFile(text: string): NetscapeCookie[] { const cookies: NetscapeCookie[] = []; for (const line of text.split(/\r?\n/)) { @@ -140,9 +166,9 @@ export class BestDebridWebFallback { public async importCookiesFromFile(filePath: string): Promise { const text = fs.readFileSync(filePath, "utf-8"); const cookies = parseNetscapeCookieFile(text); - const bestDebridCookies = cookies.filter((c) => + const bestDebridCookies = dedupeCookies(cookies.filter((c) => c.domain.includes("bestdebrid.com") - ); + )); if (bestDebridCookies.length === 0) { throw new Error("Keine BestDebrid-Cookies in der Datei gefunden"); @@ -153,6 +179,7 @@ export class BestDebridWebFallback { } const currentSession = session.fromPartition(this.getPartition()); + await this.clearPartitionState(currentSession); for (const cookie of bestDebridCookies) { const url = `https://${cookie.domain.replace(/^\./, "")}${cookie.path}`; @@ -309,4 +336,15 @@ export class BestDebridWebFallback { const text = await response.text(); return isAuthenticatedBestDebridHtml(text); } + + private async clearPartitionState(currentSession: Session): Promise { + await currentSession.clearStorageData({ + storages: ["cookies", "indexdb", "localstorage", "serviceworkers", "cachestorage"] + }); + try { + await currentSession.clearCache(); + } catch { + // ignore cache clear failures + } + } } diff --git a/tests/bestdebrid-web.test.ts b/tests/bestdebrid-web.test.ts index 727b3e9..acbb2cc 100644 --- a/tests/bestdebrid-web.test.ts +++ b/tests/bestdebrid-web.test.ts @@ -90,6 +90,10 @@ describe("bestdebrid-web", () => { const count = await fallback.importCookiesFromFile(filePath); expect(count).toBe(2); + expect(mockClearStorageData).toHaveBeenCalledTimes(1); + expect(mockClearStorageData).toHaveBeenCalledWith({ + storages: ["cookies", "indexdb", "localstorage", "serviceworkers", "cachestorage"] + }); expect(mockCookiesSet).toHaveBeenCalledTimes(2); expect(mockCookiesSet).toHaveBeenCalledWith(expect.objectContaining({ name: "PHPSESSID", @@ -99,6 +103,27 @@ describe("bestdebrid-web", () => { })); }); + it("deduplicates conflicting session cookies and prefers the HttpOnly variant", async () => { + const filePath = createCookieFile([ + "# Netscape HTTP Cookie File", + "bestdebrid.com\tFALSE\t/\tTRUE\t1803585384\tPHPSESSID\tnon-http-only", + "#HttpOnly_.bestdebrid.com\tTRUE\t/\tTRUE\t1803585385\tPHPSESSID\thttp-only" + ].join("\n")); + tempFiles.push(filePath); + + const fallback = new BestDebridWebFallback(() => true); + const count = await fallback.importCookiesFromFile(filePath); + + expect(count).toBe(1); + expect(mockCookiesSet).toHaveBeenCalledTimes(1); + expect(mockCookiesSet).toHaveBeenCalledWith(expect.objectContaining({ + name: "PHPSESSID", + value: "http-only", + httpOnly: true, + domain: ".bestdebrid.com" + })); + }); + it("rejects cookie files that only contain tracking cookies", async () => { const filePath = createCookieFile([ "# Netscape HTTP Cookie File",