MCPcopy Index your code
hub / github.com/omkarcloud/botasaurus / scrapingFunction

Function scrapingFunction

js/botasaurus-server-js/src/api-config.ts:122–351  ·  view source on GitHub ↗
(request: any, reply: any)

Source from the content-addressed store, hash-verified

120 : scraper.scraper_type;
121
122 const scrapingFunction = async (request: any, reply: any) => {
123 // Track if request was aborted by client
124 let aborted = false;
125 const onAbort = () => { aborted = true; };
126 request.raw.on('close', onAbort);
127 const isAborted = () => aborted;
128
129 try {
130 const params: Record<string, any> = {};
131 for (const [key, value] of Object.entries(
132 request.query as any
133 )) {
134 if (key.endsWith("[]")) {
135 params[key.slice(0, -2)] = Array.isArray(value)
136 ? value
137 : [value];
138 } else {
139 params[key] = value;
140 }
141 }
142
143 // Validate params against scraper's input definition
144 const [validatedData, metadata, enableCache] = validateDirectCallRequest(
145 scraper.scraper_name,
146 params
147 );
148
149 // Check if scraper has split_task
150 const splitTask = scraper.split_task;
151 const scraperName = scraper.scraper_name;
152
153 // If split_task exists, split the data
154 let dataItems: any[];
155 if (splitTask) {
156 dataItems = await splitTask(validatedData);
157 } else {
158 dataItems = [validatedData];
159 }
160
161 const mt = isNotEmptyObject(metadata) ? { metadata } : {};
162 let shouldDecrementCapacity = false;
163
164 function restoreCapacity() {
165 if (shouldDecrementCapacity) {
166 getExecutor().decrementCapacity(key);
167 shouldDecrementCapacity = false;
168 }
169 }
170
171 // Collect results with metadata
172 let collectedResults: Array<{
173 isFromCache: boolean;
174 isDontCache: boolean;
175 result: any;
176 cacheKey?: string;
177 }> = [];
178 try {
179 // Execute function for each data item

Callers

nothing calls this directly

Calls 15

isNotEmptyObjectFunction · 0.90
getExecutorFunction · 0.90
sleepFunction · 0.90
isDontCacheFunction · 0.90
isObjectFunction · 0.90
cleanDataInPlaceFunction · 0.90
removeDuplicatesByKeyFunction · 0.90
pushDataFunction · 0.85
restoreCapacityFunction · 0.85
createCacheKeyMethod · 0.80
hasCapacityMethod · 0.80

Tested by

no test coverage detected