globeandmail / chart-tool

A responsive charting application
http://globeandmail.github.io/chart-tool
MIT License
250 stars 35 forks source link

Fallback image hosting #170

Open abrambailey opened 6 years ago

abrambailey commented 6 years ago

We just launched this amazing tool, and wondering if it's possible to just save fallback images to our own server rather than AWS?

tomcardoso commented 6 years ago

Hm! Interesting suggestion, it's certainly possible. How would you upload the images to your server? There's almost definitely a node package that could handle something like this…

abrambailey commented 6 years ago

We launched the chart tool on it's own server, so it could just save the fallback images locally and reference them in the embed rather than the AWS image?

tomcardoso commented 6 years ago

That's definitely doable, would require a bit of tweaking to the image generation file. You'd need to install the fs module by doing meteor npm install --save fs, create a thumbnail folder in the public Meteor folder, then add some logic sort of like this to the generateThumb function. This code probably won't exactly work out of the box, but gives you a rough idea:

import { writeFile } from 'fs';

if (app_settings.local.enable) {
  const path = `public/thumbnail/${app_settings.local.filename}.${app_settings.local.extension}`;
  const res = await writeFile(path, png);
  return path;
}

One important thing to note about why we use S3 uploads: we keep our Chart Tool instance behind our corporate firewall so that random people can't go into our Chart Tool install and mess with charts, since there's no login/logout functionality right now. Also, using S3 means our server doesn't get hammered with thumbnail requests if chart start breaking, which is a nice plus. So if you do decide to go this route, I'd recommend considering some basic login/logout functionality.

Let me know how this works for you. If you find the thumbnails-on-the-server solution (esp. if it includes a usering/login system) works well, let me know and we can chat about a pull request, perhaps!

abrambailey commented 6 years ago

Curious. Why would charts start breaking? Thanks!

tomcardoso commented 6 years ago

It basically never happens anymore. Used to be a big deal for us when we first built Chart Tool in 2015 because of spotty SVG 1.1 support by certain browsers (cough IE cough). These days, our readers are all on SVG-capable browsers and everyone's browsers supports the Web APIs we need (like getBoundingClientRect), so the amount of fallback image use has fallen to basically zero. In the future, I may just remove the fallback image logic entirely, to be honest (though we'd still capture thumbnails for the archive page, etc).