Spaces:
Build error
Build error
fix: set-cookie
Browse files
backend/functions/src/cloud-functions/searcher.ts
CHANGED
|
@@ -12,9 +12,6 @@ import { Request, Response } from 'express';
|
|
| 12 |
import { JinaEmbeddingsAuthDTO } from '../shared/dto/jina-embeddings-auth';
|
| 13 |
import { BraveSearchExplicitOperatorsDto, BraveSearchService } from '../services/brave-search';
|
| 14 |
import { CrawlerHost, ExtraScrappingOptions, FormattedPage } from './crawler';
|
| 15 |
-
import { CookieParam } from 'puppeteer';
|
| 16 |
-
|
| 17 |
-
import { parseString as parseSetCookieString } from 'set-cookie-parser';
|
| 18 |
import { WebSearchQueryParams } from '../shared/3rd-party/brave-search';
|
| 19 |
import { SearchResult } from '../db/searched';
|
| 20 |
import { WebSearchApiResponse, SearchResult as WebSearchResult } from '../shared/3rd-party/brave-types';
|
|
@@ -152,19 +149,6 @@ export class SearcherHost extends RPCHost {
|
|
| 152 |
delete crawlerOptions.html;
|
| 153 |
|
| 154 |
const crawlOpts = this.crawler.configure(crawlerOptions);
|
| 155 |
-
const cookies: CookieParam[] = [];
|
| 156 |
-
const setCookieHeaders = ctx.req.headers['x-set-cookie'];
|
| 157 |
-
if (Array.isArray(setCookieHeaders)) {
|
| 158 |
-
for (const setCookie of setCookieHeaders) {
|
| 159 |
-
cookies.push({
|
| 160 |
-
...parseSetCookieString(setCookie, { decodeValues: false }) as CookieParam,
|
| 161 |
-
});
|
| 162 |
-
}
|
| 163 |
-
} else if (setCookieHeaders) {
|
| 164 |
-
cookies.push({
|
| 165 |
-
...parseSetCookieString(setCookieHeaders, { decodeValues: false }) as CookieParam,
|
| 166 |
-
});
|
| 167 |
-
}
|
| 168 |
const searchQuery = braveSearchExplicitOperators.addTo(ctx.req.path.slice(1));
|
| 169 |
const r = await this.cachedWebSearch({
|
| 170 |
q: searchQuery,
|
|
|
|
| 12 |
import { JinaEmbeddingsAuthDTO } from '../shared/dto/jina-embeddings-auth';
|
| 13 |
import { BraveSearchExplicitOperatorsDto, BraveSearchService } from '../services/brave-search';
|
| 14 |
import { CrawlerHost, ExtraScrappingOptions, FormattedPage } from './crawler';
|
|
|
|
|
|
|
|
|
|
| 15 |
import { WebSearchQueryParams } from '../shared/3rd-party/brave-search';
|
| 16 |
import { SearchResult } from '../db/searched';
|
| 17 |
import { WebSearchApiResponse, SearchResult as WebSearchResult } from '../shared/3rd-party/brave-types';
|
|
|
|
| 149 |
delete crawlerOptions.html;
|
| 150 |
|
| 151 |
const crawlOpts = this.crawler.configure(crawlerOptions);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
const searchQuery = braveSearchExplicitOperators.addTo(ctx.req.path.slice(1));
|
| 153 |
const r = await this.cachedWebSearch({
|
| 154 |
q: searchQuery,
|
backend/functions/src/dto/scrapping-options.ts
CHANGED
|
@@ -266,6 +266,7 @@ export class CrawlerOptions extends AutoCastable {
|
|
| 266 |
...parseSetCookieString(setCookieHeaders, { decodeValues: false }) as CookieParam,
|
| 267 |
});
|
| 268 |
}
|
|
|
|
| 269 |
|
| 270 |
const proxyUrl = ctx?.req.get('x-proxy-url');
|
| 271 |
instance.proxyUrl ??= proxyUrl;
|
|
|
|
| 266 |
...parseSetCookieString(setCookieHeaders, { decodeValues: false }) as CookieParam,
|
| 267 |
});
|
| 268 |
}
|
| 269 |
+
instance.setCookies = cookies;
|
| 270 |
|
| 271 |
const proxyUrl = ctx?.req.get('x-proxy-url');
|
| 272 |
instance.proxyUrl ??= proxyUrl;
|
backend/functions/src/services/puppeteer.ts
CHANGED
|
@@ -476,7 +476,14 @@ document.addEventListener('load', handlePageLoad);
|
|
| 476 |
await page.useProxy(options.proxyUrl);
|
| 477 |
}
|
| 478 |
if (options?.cookies) {
|
| 479 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 480 |
}
|
| 481 |
if (options?.overrideUserAgent) {
|
| 482 |
await page.setUserAgent(options.overrideUserAgent);
|
|
|
|
| 476 |
await page.useProxy(options.proxyUrl);
|
| 477 |
}
|
| 478 |
if (options?.cookies) {
|
| 479 |
+
const mapped = options.cookies.map((x) => {
|
| 480 |
+
if (x.domain || x.url) {
|
| 481 |
+
return x;
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
return { ...x, url: parsedUrl.toString() };
|
| 485 |
+
});
|
| 486 |
+
await page.setCookie(...mapped);
|
| 487 |
}
|
| 488 |
if (options?.overrideUserAgent) {
|
| 489 |
await page.setUserAgent(options.overrideUserAgent);
|