* insert_next_page inserts the list of next pages to be crawled. * @param {Object} data - a valid JSON object containing data to be inserted. * @param {function} callback - callback function to be executed on success.
(data, callback)
| 255 | * @param {function} callback - callback function to be executed on success. |
| 256 | */ |
| 257 | function insert_next_page (data, callback) { |
| 258 | let urls = [] |
| 259 | switch (data.type) { |
| 260 | case 'org': |
| 261 | // console.log('data.name', data.name); |
| 262 | urls = data.entries.map((e) => e.url); |
| 263 | urls.push('orgs/' + data.name + '/people'); // list of PUBLIC org members. |
| 264 | urls.push(data.next_page); // if it exists. |
| 265 | break; |
| 266 | case 'profile': |
| 267 | urls = data.pinned.map((e) => e.url); |
| 268 | const orgs = Object.keys(data.orgs); |
| 269 | orgs.forEach(org => urls.push(org)); |
| 270 | urls = profile_next_page(urls, data.username); |
| 271 | break; |
| 272 | case 'repo': |
| 273 | urls.push(data.url + '/stargazers'); |
| 274 | break; |
| 275 | case 'followers': |
| 276 | case 'following': |
| 277 | case 'people': |
| 278 | case 'stars': |
| 279 | urls.push(data.next_page); |
| 280 | data.entries.forEach((e) => { urls = profile_next_page(urls, e.username)}) |
| 281 | break; |
| 282 | } |
| 283 | let len = urls.length; |
| 284 | urls.filter((e) => e !== null) // filter out blanks (if next_page is null) |
| 285 | .forEach((next_page, i) => { // poor person's "async parallel": |
| 286 | insert_log_item(data.url, next_page, (error, data2) => { |
| 287 | if(--len == 0) { |
| 288 | return utils.exec_cb(callback, null, data); |
| 289 | } |
| 290 | }) |
| 291 | }); |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * select_next_page get the next url (page) to crawl |
no test coverage detected