(
req: RequestWithAuth<{}, CrawlResponse, CrawlRequest>,
res: Response<CrawlResponse>,
)
| 28 | import { getScrapeZDR } from "../../lib/zdr-helpers"; |
| 29 | |
| 30 | export async function crawlController( |
| 31 | req: RequestWithAuth<{}, CrawlResponse, CrawlRequest>, |
| 32 | res: Response<CrawlResponse>, |
| 33 | ) { |
| 34 | const preNormalizedBody = req.body; |
| 35 | req.body = crawlRequestSchema.parse(req.body); |
| 36 | |
| 37 | const permissions = checkPermissions( |
| 38 | { ...req.body, crawlerOptions: req.body }, |
| 39 | req.acuc?.flags, |
| 40 | ); |
| 41 | if (permissions.error) { |
| 42 | return res.status(403).json({ |
| 43 | success: false, |
| 44 | error: permissions.error, |
| 45 | }); |
| 46 | } |
| 47 | |
| 48 | const zeroDataRetention = |
| 49 | getScrapeZDR(req.acuc?.flags) === "forced" || req.body.zeroDataRetention; |
| 50 | |
| 51 | const id = uuidv7(); |
| 52 | const logger = _logger.child({ |
| 53 | crawlId: id, |
| 54 | module: "api/v2", |
| 55 | method: "crawlController", |
| 56 | teamId: req.auth.team_id, |
| 57 | zeroDataRetention, |
| 58 | }); |
| 59 | |
| 60 | logger.debug("Crawl " + id + " starting", { |
| 61 | request: req.body, |
| 62 | originalRequest: preNormalizedBody, |
| 63 | account: req.account, |
| 64 | }); |
| 65 | |
| 66 | await logRequest({ |
| 67 | id, |
| 68 | kind: "crawl", |
| 69 | api_version: "v2", |
| 70 | team_id: req.auth.team_id, |
| 71 | origin: req.body.origin ?? "api", |
| 72 | integration: req.body.integration, |
| 73 | target_hint: req.body.url, |
| 74 | zeroDataRetention: zeroDataRetention || false, |
| 75 | api_key_id: req.acuc?.api_key_id ?? null, |
| 76 | }); |
| 77 | |
| 78 | let { remainingCredits } = req.account!; |
| 79 | const useDbAuthentication = config.USE_DB_AUTHENTICATION; |
| 80 | if (!useDbAuthentication) { |
| 81 | remainingCredits = Infinity; |
| 82 | } |
| 83 | |
| 84 | const crawlerOptions = { |
| 85 | ...req.body, |
| 86 | url: undefined, |
| 87 | scrapeOptions: undefined, |
nothing calls this directly
no test coverage detected
searching dependent graphs…