refactor: remove facebook cookie overrides

This commit is contained in:
2026-04-21 21:45:42 -04:00
parent 847ce28590
commit a7a5eca7ad
2 changed files with 25 additions and 34 deletions

View File

@@ -25,7 +25,6 @@ const FACEBOOK_COOKIE_CONFIG: CookieConfig = {
name: "Facebook",
domain: ".facebook.com",
envVar: "FACEBOOK_COOKIE",
filePath: "./cookies/facebook.json",
};
interface FacebookAdNode {
@@ -211,20 +210,10 @@ export function parseFacebookCookieString(cookieString: string): Cookie[] {
}
/**
* Load Facebook cookies with priority: URL param > ENV var > file
* @param cookiesSource - Optional cookie JSON string from URL parameter (highest priority)
* @param _cookiePath - Deprecated, uses default path from config
* Load Facebook cookies from FACEBOOK_COOKIE
*/
export async function ensureFacebookCookies(
cookiesSource?: string,
_cookiePath?: string,
): Promise<Cookie[]> {
return ensureCookies(
_cookiePath
? { ...FACEBOOK_COOKIE_CONFIG, filePath: _cookiePath }
: FACEBOOK_COOKIE_CONFIG,
cookiesSource,
);
export async function ensureFacebookCookies(): Promise<Cookie[]> {
return ensureCookies(FACEBOOK_COOKIE_CONFIG);
}
class HttpError extends Error {
@@ -825,11 +814,8 @@ export default async function fetchFacebookItems(
REQUESTS_PER_SECOND = 1,
LOCATION = "toronto",
MAX_ITEMS = 25,
cookiesSource?: string,
cookiePath?: string,
) {
// Load Facebook cookies with priority: URL param > ENV var > file
const cookies = await ensureFacebookCookies(cookiesSource, cookiePath);
const cookies = await ensureFacebookCookies();
// Format cookies for HTTP header
const domain = "www.facebook.com";
@@ -871,7 +857,7 @@ export default async function fetchFacebookItems(
);
if (err.status === 400 || err.status === 401 || err.status === 403) {
console.warn(
"This might indicate invalid or expired cookies. Please update ./cookies/facebook.json with fresh session cookies.",
"This might indicate invalid or expired cookies. Update FACEBOOK_COOKIE with a fresh raw Cookie header string.",
);
}
return [];
@@ -914,11 +900,8 @@ export default async function fetchFacebookItems(
*/
export async function fetchFacebookItem(
itemId: string,
cookiesSource?: string,
_cookiePath?: string,
): Promise<FacebookListingDetails | null> {
// Load Facebook cookies - required for Facebook Marketplace access
const cookies = await ensureFacebookCookies(cookiesSource, _cookiePath);
const cookies = await ensureFacebookCookies();
// Format cookies for HTTP header
const cookiesHeader = formatCookiesForHeader(cookies, "www.facebook.com");
@@ -956,10 +939,7 @@ export async function fetchFacebookItem(
case 401:
case 403:
console.warn(
"Authentication error: Invalid or expired cookies. Please update ./cookies/facebook.json with fresh session cookies.",
);
console.warn(
"Try logging out and back into Facebook, then export fresh cookies.",
"Authentication error: Invalid or expired cookies. Update FACEBOOK_COOKIE with a fresh raw Cookie header string.",
);
break;
case 404: