diff options
author | RaindropsSys <contact@minteck.org> | 2023-04-06 22:18:28 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-04-06 22:18:28 +0200 |
commit | 83354b2b88218090988dd6e526b0a2505b57e0f1 (patch) | |
tree | e3c73c38a122a78bb7e66fbb99056407edd9d4b9 /includes/external/addressbook/node_modules/open-graph-scraper/dist/lib/openGraphScraper.js | |
parent | 47b8f2299a483024c4a6a8876af825a010954caa (diff) | |
download | pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.tar.gz pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.tar.bz2 pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.zip |
Updated 5 files and added 1110 files (automated)
Diffstat (limited to 'includes/external/addressbook/node_modules/open-graph-scraper/dist/lib/openGraphScraper.js')
-rw-r--r-- | includes/external/addressbook/node_modules/open-graph-scraper/dist/lib/openGraphScraper.js | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/includes/external/addressbook/node_modules/open-graph-scraper/dist/lib/openGraphScraper.js b/includes/external/addressbook/node_modules/open-graph-scraper/dist/lib/openGraphScraper.js new file mode 100644 index 0000000..b95a5eb --- /dev/null +++ b/includes/external/addressbook/node_modules/open-graph-scraper/dist/lib/openGraphScraper.js @@ -0,0 +1,63 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const extract_1 = require("./extract"); +const request_1 = require("./request"); +const utils = require("./utils"); +/** + * sets up options for the got request and calls extract on html + * + * @param {object} options - options for ogs + * @return {object} object with ogs results + * + */ +async function setOptionsAndReturnOpenGraphResults(options) { + const { ogsOptions, gotOptions } = utils.optionSetupAndSplit(options); + if (ogsOptions.html) { + if (ogsOptions.url) + throw new Error('Must specify either `url` or `html`, not both'); + const ogObject = (0, extract_1.default)(ogsOptions.html, ogsOptions, null); + ogObject.requestUrl = null; + ogObject.success = true; + return { ogObject, response: { body: ogsOptions.html } }; + } + const formattedUrl = utils.validateAndFormatURL(ogsOptions.url, ogsOptions.urlValidatorSettings); + if (!formattedUrl.url) + throw new Error('Invalid URL'); + ogsOptions.url = formattedUrl.url; + gotOptions.url = formattedUrl.url; + // trying to limit non html pages + if (utils.isThisANonHTMLUrl(ogsOptions.url)) + throw new Error('Must scrape an HTML page'); + // eslint-disable-next-line max-len + if (ogsOptions.blacklist && ogsOptions.blacklist.some((blacklistedHostname) => ogsOptions.url.includes(blacklistedHostname))) { + throw new Error('Host name has been black listed'); + } + try { + const { decodedBody, response } = await (0, request_1.default)(gotOptions, ogsOptions); + const ogObject = (0, extract_1.default)(decodedBody, ogsOptions, response.rawBody); + ogObject.requestUrl = ogsOptions.url; + ogObject.success = true; + return { ogObject, response }; + } + catch (exception) { + if (exception && (exception.code === 'ENOTFOUND' || exception.code === 'EHOSTUNREACH' || exception.code === 'ENETUNREACH')) { + throw new Error('Page not found'); + } + else if (exception && (exception.code === 'ERR_INVALID_URL' || exception.code === 'EINVAL')) { + throw new Error('Page not found'); + } + else if (exception && exception.code === 'ETIMEDOUT') { + throw new Error('Time out'); + } + else if (exception && exception.message && exception.message.startsWith('Response code 5')) { + throw new Error('Web server is returning error'); + } + else if (exception && exception.message && exception.message === 'Promise was canceled') { + throw new Error(`Exceeded the download limit of ${ogsOptions.downloadLimit} bytes`); + } + if (exception instanceof Error) + throw exception; + throw new Error('Page not found'); + } +} +exports.default = setOptionsAndReturnOpenGraphResults; |