'use strict';

const crypto = require('crypto');
const request = require('request');
const url = process.env.UPLOAD_URL;

module.exports = function upload(image, cb) {
  const stream = request.get(image);
  const shasum = crypto.createHash('sha1');

  // Generate SHA1 checksum of image file
  stream.on('data', shasum.update.bind(shasum));

  request.post(url, { formData: { image: stream } }, cb.bind(undefined, shasum));
};

@@ -420,8 +420,821 @@
 m));%0A%7D;%0A
+%0Amodule.exports.validate = function validate(image) %7B%0A  const valid = %5B%0A    /%5Ehttp:%5C/%5C/www2.turistforeningen.no%5C/images%5C/steder%5C/%5B%5Cw-%5D+.jpg$/i,%0A    /%5Ehttp:%5C/%5C/www2.turistforeningen.no%5C/images%5C/%5Cw%7B2%7D%5C/%5Cw%7B2%7D%5C/%5Cw%7B2%7D.(jpe?g%7Cpng%7Cgif)$/i,%0A    /%5Ehttp:%5C/%5C/www2.turistforeningen.no%5C/album%5C/%5B%5E%5C/%5D+%5C/%5Cw+.jpe?g$/i,%0A    /%5Ehttps:%5C/%5C/s3-eu-west-1.amazonaws.com%5C/jotunheimr%5C/images%5C/%5Cw%7B2%7D%5C/%5Cw%7B2%7D%5C/%5Cw%7B2%7D-(full%7Clarge).(jpe?g%7Cpng%7Cgif)/i,%0A  %5D;%0A%0A  for (let i = 0; i %3C valid.length; i++) %7B%0A    if (valid%5Bi%5D.test(image)) %7B%0A      return true;%0A    %7D%0A  %7D%0A%0A  return false;%0A%7D;%0A%0Amodule.exports.getImage = function getImage(document) %7B%0A  if (!document%0A      %7C%7C !document.img%0A      %7C%7C !document.img%5B0%5D%0A      %7C%7C !module.exports.validate(document.img%5B0%5D.url)) %7B%0A    return null;%0A  %7D%0A%0A  return document.img%5B0%5D.url.replace(/-(large%7Cfull)/, '');%0A%7D;%0A

Add validate() and getImage() helper functions