From 9e1461374614d271dd5d5699949fd3473002d974 Mon Sep 17 00:00:00 2001 From: Giancarmine Salucci Date: Tue, 12 May 2026 23:19:55 +0200 Subject: [PATCH] fix(auth): always regenerate cookies.txt from auth.json, don't skip if yt-dlp overwrote it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously cookies.txt was only regenerated when auth.json was newer. But yt-dlp overwrites cookies.txt during extraction with its own header ('generated by yt-dlp') and potentially fewer/different cookies, losing the sessionid from auth.json. Fix: remove mtime comparison — always regenerate cookies.txt from auth.json on each extraction call. This ensures the full session cookie set is always present. Also remove the now-unused statSync import. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/lib/server/instagram-extractor.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/lib/server/instagram-extractor.ts b/src/lib/server/instagram-extractor.ts index 3298f8d..2adb47f 100644 --- a/src/lib/server/instagram-extractor.ts +++ b/src/lib/server/instagram-extractor.ts @@ -9,7 +9,7 @@ import { execFile } from 'node:child_process'; import { promisify } from 'node:util'; -import { existsSync, readFileSync, writeFileSync, statSync } from 'node:fs'; +import { existsSync, readFileSync, writeFileSync } from 'node:fs'; import { logError } from './utils/logger'; import type { ExtractedContent, ProgressCallback } from './extraction'; @@ -40,11 +40,7 @@ function maybeConvertAuthJson(): void { const cookiePath = COOKIE_PATHS[i]; if (!existsSync(authPath)) continue; - // Re-generate whenever auth.json is newer than the existing cookies.txt - const authMtime = statSync(authPath).mtimeMs; - const cookieMtime = existsSync(cookiePath) ? statSync(cookiePath).mtimeMs : 0; - if (cookieMtime >= authMtime) continue; - + // Always regenerate from auth.json so yt-dlp cannot overwrite our session cookies try { const auth = JSON.parse(readFileSync(authPath, 'utf8')) as { cookies?: PlaywrightCookie[];