Permalink
Browse files

Code cleanup

  • Loading branch information...
1 parent 25c2e58 commit 98a179ae6b3402f112dfae7ffdfb5812471af5c1 @DMarby committed Nov 3, 2014
Showing with 235 additions and 232 deletions.
  1. +25 −25 buildcache.js
  2. +5 −5 config.js
  3. +39 −39 imageProcessor.js
  4. +109 −109 index.js
  5. +57 −54 server.js
View
@@ -1,39 +1,39 @@
-var sharp = require('sharp');
-var path = require('path');
-var config = require('./config')();
-var fs = require('fs');
+var sharp = require('sharp')
+var path = require('path')
+var config = require('./config')()
+var fs = require('fs')
-var imageProcessor = require('./imageProcessor')(sharp, path, config, fs);
-var images = require(config.image_store_path);
+var imageProcessor = require('./imageProcessor')(sharp, path, config, fs)
+var images = require(config.image_store_path)
-var index = process.argv[2] || 0;
-console.log('Start: %s', index);
+var index = process.argv[2] || 0
+console.log('Start: %s', index)
-sharp.cache(0);
+sharp.cache(0)
var nextImage = function (the_index, callback) {
- var width = 458;
- var height = 354;
- var filePath = images[the_index].filename;
- var blur = false;
- imageProcessor.getProcessedImage(width, height, null, false, false, filePath, false, function (err, imagePath) {
- if (err) {
- console.log('filePath: ' + filePath);
- console.log('imagePath: ' + imagePath);
- console.log('error: ' + err);
+ var width = 458
+ var height = 354
+ var filePath = images[the_index].filename
+ var blur = false
+ imageProcessor.getProcessedImage(width, height, null, false, false, filePath, false, function (error, imagePath) {
+ if (error) {
+ console.log('filePath: ' + filePath)
+ console.log('imagePath: ' + imagePath)
+ console.log('error: ' + err)
}
- console.log('%s done', the_index);
- callback();
+ console.log('%s done', the_index)
+ callback()
})
}
var imageLinksCallback = function () {
- index++;
+ index++
if (index >= images.length) {
- console.log('Done!');
- return;
+ console.log('Done!')
+ return
}
- nextImage(index, imageLinksCallback);
+ nextImage(index, imageLinksCallback)
}
-nextImage(index, imageLinksCallback);
+nextImage(index, imageLinksCallback)
View
@@ -1,7 +1,7 @@
module.exports = exports = function () {
- var configFile = require('./config.json');
- var node_env = process.env.NODE_ENV || 'production';
- var config = configFile[node_env];
- config.env = node_env;
- return config;
+ var configFile = require('./config.json')
+ var node_env = process.env.NODE_ENV || 'production'
+ var config = configFile[node_env]
+ config.env = node_env
+ return config
}
View
@@ -1,90 +1,90 @@
module.exports = exports = function (sharp, path, config, fs) {
- var gm = require('gm');
+ var gm = require('gm')
var ImageProcessor = {
'getGravity': function(gravity) {
- gravity = gravity ? gravity : 'center';
- gravity = gravity == 'centre' ? 'center' : gravity;
- return gravity;
+ gravity = gravity ? gravity : 'center'
+ gravity = gravity == 'centre' ? 'center' : gravity
+ return gravity
},
'getDestination': function (width, height, gravity, blur, filePath, prefix) {
- return config.cache_folder_path + '/' + prefix + path.basename(filePath, path.extname(filePath)) + '-' + width + 'x' + height + '-' + gravity + (blur ? '-blur' : '') + '.jpeg';
+ return config.cache_folder_path + '/' + prefix + path.basename(filePath, path.extname(filePath)) + '-' + width + 'x' + height + '-' + gravity + (blur ? '-blur' : '') + '.jpeg'
},
'getShortDestination': function (width, height, gravity, blur, filePath, prefix) {
- return config.cache_folder_path + '/' + prefix + width + '^' + height + '-' + gravity + (blur ? '-blurred' : '') + '.jpeg';
+ return config.cache_folder_path + '/' + prefix + width + '^' + height + '-' + gravity + (blur ? '-blurred' : '') + '.jpeg'
},
'getAndCheckDestination': function (width, height, gravity, blur, filePath, prefix, shortName, callback) {
- var destination = shortName ? ImageProcessor.getShortDestination(width, height, gravity, blur, filePath, prefix) : ImageProcessor.getDestination(width, height, gravity, blur, filePath, prefix);
+ var destination = shortName ? ImageProcessor.getShortDestination(width, height, gravity, blur, filePath, prefix) : ImageProcessor.getDestination(width, height, gravity, blur, filePath, prefix)
fs.exists(destination, function (exists) {
- callback(exists, destination);
+ callback(exists, destination)
})
},
'imageResize': function (width, height, gravity, filePath, destination, callback) {
try {
- sharp(filePath).rotate().resize(width, height).crop(sharp.gravity[gravity]).jpeg().progressive().toFile(destination, function (err) {
- callback(err, destination);
- });
- } catch (e) {
- callback(e, null);
+ sharp(filePath).rotate().resize(width, height).crop(sharp.gravity[gravity]).jpeg().progressive().toFile(destination, function (error) {
+ callback(error, destination)
+ })
+ } catch (error) {
+ callback(error, null)
}
},
'getProcessedImage': function (width, height, gravity, gray, blur, filePath, shortName, callback) {
- gravity = ImageProcessor.getGravity(gravity);
+ gravity = ImageProcessor.getGravity(gravity)
ImageProcessor.getAndCheckDestination(width, height, gravity, blur, filePath, gray ? 'gray-' : '', shortName, function (exists, destination) {
if (exists) {
- return callback(null, destination);
+ return callback(null, destination)
}
- ImageProcessor.imageResize(width, height, gravity, filePath, destination, function (err, destination) {
- if (err) {
- fs.unlink(destination, function (err) {
- console.log('Error, deleted file');
+ ImageProcessor.imageResize(width, height, gravity, filePath, destination, function (error, destination) {
+ if (error) {
+ fs.unlink(destination, function (error) {
+ console.log('Error, deleted file')
})
- return callback(err);
+ return callback(error)
}
if (gray) {
- var modifyImage = gm(destination).colorspace('GRAY');
+ var modifyImage = gm(destination).colorspace('GRAY')
if (blur) {
- modifyImage.blur(0, 5);
+ modifyImage.blur(0, 5)
}
- modifyImage.write(destination, function (err) {
- if (err) {
- fs.unlink(destination, function (err) {
- console.log('Error, deleted file');
+ modifyImage.write(destination, function (error) {
+ if (error) {
+ fs.unlink(destination, function (error) {
+ console.log('Error, deleted file')
})
- return callback(err);
+ return callback(error)
}
- callback(null, destination);
+ callback(null, destination)
})
} else {
if (blur) {
- gm(destination).blur(0, 5).write(destination, function (err) {
- if (err) {
- fs.unlink(destination, function (err) {
- console.log('Error, deleted file');
+ gm(destination).blur(0, 5).write(destination, function (error) {
+ if (error) {
+ fs.unlink(destination, function (error) {
+ console.log('Error, deleted file')
})
- return callback(err);
+ return callback(error)
}
- callback(null, destination);
+ callback(null, destination)
})
} else {
- callback(null, destination);
+ callback(null, destination)
}
}
})
})
},
'getWidthAndHeight': function (params, square, callback) {
- var width = square ? params.size : params.width;
- var height = square ? params.size : params.height;
- callback(width, height);
+ var width = square ? params.size : params.width
+ var height = square ? params.size : params.height
+ callback(width, height)
}
}
- return ImageProcessor;
+ return ImageProcessor
}
Oops, something went wrong.

0 comments on commit 98a179a

Please sign in to comment.