DelphiSolutions/Reflection — pull request #1 by lorenabrams (2013-11-08 09:22:19+00:00)
Title: General refactors to improve screenshot service

Slimmed down the service a bit. Previously a request would be POSTed to an API endpoint, whereby Phantom would fetch a screenshot of the supplied URL, cache it in Mongo, and the return a randomly generated image name UUID such that one could make a subsequent GET request to fetch the image out of Mongo from the API.

In addition, there was fragile home-rolled queue logic to prevent too many concurrent Phantom processes from running. Further, no input validation was being performed -- in essence, a screenshot could be taken of any site on the internet through our service.

This refactor provides:
- Input validation such that URL to be screenshot must be a subdomain of opengov.com.
- Input validation such that width and height are non-negative range.
- Better error handling in general.
- Use of the async module's queue as a replacement for the hand-rolled queue logic that was in place.
- Ditching of the data store.
- A single endpoint that fetches the screenshot inline with the API request and returns the image data as the response.
- (Hopefully!!) cleaner code.. with far fewer unnecessary comments.

A call to this endpoint might look as follows (totally made up the subdomain to host this service from): `http://screenshot.opengov.com/opengov_paloalto.png?width=1600&height=1200&url=http://paloalto.opengov.com/`

Note that the API serves out of a path that includes a sane image name so when the user saves the image the browser will offer up said sane file name to save the image as, as opposed to some randomly generated UUID/hash.