You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
788 B

11 months ago
  1. const { validURL } = require("../utils/url");
  2. const { scrapeGenericUrl } = require("./convert/generic");
  3. async function processLink(link) {
  4. if (!validURL(link)) return { success: false, reason: "Not a valid URL." };
  5. return await scrapeGenericUrl(link);
  6. }
  7. /**
  8. * Get the text content of a link
  9. * @param {string} link - The link to get the text content of
  10. * @param {('html' | 'text' | 'json')} captureAs - The format to capture the page content as
  11. * @returns {Promise<{success: boolean, content: string}>} - Response from collector
  12. */
  13. async function getLinkText(link, captureAs = "text") {
  14. if (!validURL(link)) return { success: false, reason: "Not a valid URL." };
  15. return await scrapeGenericUrl(link, captureAs, false);
  16. }
  17. module.exports = {
  18. processLink,
  19. getLinkText,
  20. };