UNPKG

dce-dev-wizard

Version:

Wizard for managing development apps at Harvard DCE.

51 lines 2.28 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); // Import scraping tool const node_html_parser_1 = require("node-html-parser"); // Constants const titleSelector = 'h2.Subhead-heading'; const descriptionSelector = 'div.markdown-body>p'; /** * Scrapes the GitHub advisory page for a CVE and returns the title and * description of the CVE. * @author Allison Zhang * @author Gabe Abrams * @param githubLink The URL of the GitHub advisory page for the CVE * @returns A promise that contains both the title and description of the CVE */ const scrapeCVE = (githubLink) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d; // Send request let response; try { response = yield fetch(githubLink); } catch (error) { return { title: 'N/A', description: 'N/A', }; } // Get the body text const bodyText = yield response.text(); const root = (0, node_html_parser_1.parse)(bodyText); // Get and trim the title text const heading = ((_b = (_a = root.querySelector(titleSelector)) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim()); // Get and trim the description text const description = ((_d = (_c = root.querySelector(descriptionSelector)) === null || _c === void 0 ? void 0 : _c.textContent) === null || _d === void 0 ? void 0 : _d.trim()); return { title: heading || 'N/A', description: description || 'N/A', }; }); exports.default = scrapeCVE; //# sourceMappingURL=scrapeCVE.js.map