mirror of
				https://git.sleeping.town/mirrors/foxy-moxy
				synced 2025-11-03 10:02:34 -08:00 
			
		
		
		
	Minor syntax changes.
This commit is contained in:
		
							parent
							
								
									82926bfd4e
								
							
						
					
					
						commit
						478ed6b5f7
					
				
					 1 changed files with 19 additions and 20 deletions
				
			
		
							
								
								
									
										37
									
								
								server.js
									
										
									
									
									
								
							
							
						
						
									
										37
									
								
								server.js
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -4,43 +4,42 @@ try {
 | 
			
		|||
  console.error("WARNING unable to load newrelic")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var fs = require('fs');
 | 
			
		||||
var express = require('express');
 | 
			
		||||
var uuid = require('uuid/v4');
 | 
			
		||||
var sanitize = require('sanitize-filename');
 | 
			
		||||
var Canvas = require('canvas');
 | 
			
		||||
const express = require('express');
 | 
			
		||||
const uuid = require('uuid/v4');
 | 
			
		||||
const sanitize = require('sanitize-filename');
 | 
			
		||||
const Canvas = require('canvas');
 | 
			
		||||
 | 
			
		||||
var Fox = require('./js/fox.js');
 | 
			
		||||
var renderFox = require('./js/render-fox.js');
 | 
			
		||||
const Fox = require('./js/fox.js');
 | 
			
		||||
const renderFox = require('./js/render-fox.js');
 | 
			
		||||
 | 
			
		||||
function composeImage(width, height, seed) {
 | 
			
		||||
    seed = seed || uuid();
 | 
			
		||||
    var fox = Fox(width, height, seed);
 | 
			
		||||
    var canvas = new Canvas(width, height);
 | 
			
		||||
    var ctx = canvas.getContext('2d');
 | 
			
		||||
    const fox = Fox(width, height, seed);
 | 
			
		||||
    const canvas = new Canvas(width, height);
 | 
			
		||||
    renderFox(canvas, fox);
 | 
			
		||||
    return canvas;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var app = express();
 | 
			
		||||
const app = express();
 | 
			
		||||
 | 
			
		||||
var cacheTimeout = 60 * 60 * 24 * 30;
 | 
			
		||||
const cacheTimeout = 60 * 60 * 24 * 30;
 | 
			
		||||
 | 
			
		||||
app.get('/healthcheck', function(req, res) {
 | 
			
		||||
app.get('/healthcheck', (req, res) => {
 | 
			
		||||
    res.status(200).end();
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
app.get('/:width/:seed', function(req, res) {
 | 
			
		||||
    var width = parseInt(req.params.width) || 400;
 | 
			
		||||
app.get('/:width/:seed', (req, res) => {
 | 
			
		||||
    let width = parseInt(req.params.width) || 400;
 | 
			
		||||
    if (width > 400) width = 400;
 | 
			
		||||
    var seed = sanitize(req.params.seed) || uuid();
 | 
			
		||||
    var canvas = composeImage(width, width, seed);
 | 
			
		||||
    var buffer = canvas.toBuffer();
 | 
			
		||||
    const seed = sanitize(req.params.seed) || uuid();
 | 
			
		||||
    const canvas = composeImage(width, width, seed);
 | 
			
		||||
    const buffer = canvas.toBuffer();
 | 
			
		||||
    res.set('Cache-Control', 'max-age=' + cacheTimeout);
 | 
			
		||||
    res.set('Content-length', buffer.length);
 | 
			
		||||
    res.type('png');
 | 
			
		||||
    res.end(buffer, 'binary');
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
app.listen(process.env.PORT || 3000);
 | 
			
		||||
app.listen(process.env.PORT || 3000, () => {
 | 
			
		||||
    console.log('listening on http://localhost:3000');
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue