Deprecate v1 urls, upgraded things

This commit is contained in:
Liran Nuna 2018-10-19 14:29:06 -07:00
parent 21a47e0c45
commit a674d6a79c
5 changed files with 32 additions and 151 deletions

View file

@ -5,22 +5,12 @@ const sanitize = require('sanitize-filename')
const Canvas = require('canvas')
const Fox = require('./js/fox.js')
const FoxAmerica = require('./js/fox-america.js')
const renderFox = require('./js/render-fox.js')
function composeImage (width, height, seed, version) {
seed = seed || uuid()
let fox
switch (version) {
case 2:
// America-color bg and fox
fox = FoxAmerica(width, height, seed)
break
default:
// original fox
fox = Fox(width, height, seed)
}
const canvas = new Canvas(width, height)
const fox = Fox(width, height, seed)
const canvas = Canvas.createCanvas(width, height)
renderFox(canvas, fox)
return canvas
}
@ -30,7 +20,7 @@ function getFox (req, res, version) {
if (width > 400) width = 400
const seed = sanitize(req.params.seed) || uuid()
const canvas = composeImage(width, width, seed, version)
const buffer = canvas.toBuffer()
const buffer = canvas.toBuffer('image/png')
res.set('Cache-Control', 'max-age=' + cacheTimeout)
res.set('Content-length', buffer.length)
res.type('png')
@ -46,11 +36,11 @@ app.get('/healthcheck', (req, res) => {
})
app.get('/:width/:seed', (req, res) => {
getFox(req, res, 1)
getFox(req, res)
})
app.get('/2/:width/:seed', (req, res) => {
getFox(req, res, 2)
getFox(req, res)
})
module.exports = app