Source: bugreport/index.js

  1. /**
  2. * @module bugreport
  3. */
  4. const mail = require("../mail");
  5. const adminService = require("../admin");
  6. const log = require("../../util/log");
  7. const octokit = require("../octokit");
  8. /**
  9. * Process bugreport submitted by a user
  10. * at a specific route: Send the bugreport
  11. * email to admin, log the bugreport via
  12. * the admin module and create an anonymised
  13. * issue on Github.
  14. * @param {String} originalUrl
  15. * @param {String} ip
  16. * @param {String} email
  17. * @param {String} report text
  18. */
  19. const processBugReport = async (originalUrl, ip, email, report) => {
  20. log.info("Processing bug report for route: '%s'", originalUrl);
  21. const bugreport = {
  22. timestamp: (new Date()).toUTCString(),
  23. originalUrl,
  24. ip,
  25. email,
  26. report,
  27. };
  28. await sendBugReport(bugreport);
  29. adminService.logBugReport(bugreport);
  30. octokit.createBugreportIssue(bugreport);
  31. };
  32. /**
  33. * Send a bug report email to the bug report
  34. * email address specified in .env. This sets the sender
  35. * of the email to be the server email address, but the
  36. * user's email is specified in the body of the email
  37. * if they provided one.
  38. * @param {Object} bugreport
  39. */
  40. const sendBugReport = async (bugreport) => {
  41. await mail.sendEmail(
  42. process.env.BUG_REPORT_EMAIL_ADDRESS,
  43. process.env.BUG_REPORT_EMAIL_ADDRESS,
  44. `[rdfmapped.com] Bug Report for route: ${bugreport.originalUrl}`,
  45. `Bugreport: ${JSON.stringify(bugreport)}`,
  46. `<p>Bugreport: <code>${JSON.stringify(bugreport)}</code></p>`);
  47. };
  48. module.exports = {
  49. processBugReport,
  50. };