Add detailed cookie debugging and validation

This commit is contained in:
Peter Meier
2025-12-22 14:04:21 +01:00
parent e6ef44c131
commit bbd6ceb084

View File

@@ -30,7 +30,10 @@ export const POST: APIRoute = async ({ request }) => {
let tempCookiesFile: string | null = null; let tempCookiesFile: string | null = null;
try { try {
const { url, cookies } = await request.json(); const body = await request.json();
const { url, cookies } = body;
console.log(`Request erhalten - URL: ${url}, Cookies vorhanden: ${!!cookies}, Cookie-Länge: ${cookies ? cookies.length : 0}`);
if (!url || typeof url !== "string") { if (!url || typeof url !== "string") {
return new Response( return new Response(
@@ -59,6 +62,10 @@ export const POST: APIRoute = async ({ request }) => {
fileContent.length fileContent.length
} Zeichen, erste Zeile: ${fileContent.split("\n")[0]}` } Zeichen, erste Zeile: ${fileContent.split("\n")[0]}`
); );
// Prüfe ob wichtige Cookies vorhanden sind
const hasLoginInfo = fileContent.includes("LOGIN_INFO");
const hasSID = fileContent.includes("SID");
console.log(`Cookie-Prüfung - LOGIN_INFO: ${hasLoginInfo}, SID: ${hasSID}`);
} }
} catch (error) { } catch (error) {
console.error( console.error(
@@ -67,6 +74,8 @@ export const POST: APIRoute = async ({ request }) => {
); );
// Weiter ohne Cookies // Weiter ohne Cookies
} }
} else {
console.log("Keine Cookies im Request oder leer");
} }
// YouTube URL validieren // YouTube URL validieren
@@ -361,11 +370,15 @@ export const POST: APIRoute = async ({ request }) => {
{ status: 500, headers: { "Content-Type": "application/json" } } { status: 500, headers: { "Content-Type": "application/json" } }
); );
} finally { } finally {
// Temporäre Cookie-Datei löschen falls vorhanden // Temporäre Cookie-Datei löschen falls vorhanden (nach einer kurzen Verzögerung, damit Debugging möglich ist)
if (tempCookiesFile && existsSync(tempCookiesFile)) { if (tempCookiesFile && existsSync(tempCookiesFile)) {
await unlink(tempCookiesFile).catch((err) => { // Warte kurz, damit die Datei für Debugging verfügbar bleibt
console.error("Fehler beim Löschen der temporären Cookie-Datei:", err); const fileToDelete = tempCookiesFile;
}); setTimeout(async () => {
await unlink(fileToDelete).catch((err) => {
console.error("Fehler beim Löschen der temporären Cookie-Datei:", err);
});
}, 5000); // 5 Sekunden Verzögerung
} }
} }
}; };