|
@@ -7,21 +7,16 @@ var path = require('path');
|
|
|
|
|
|
var screenshotHandler = function() {
|
|
|
|
|
|
- var tmpFolderPath = 'tmp';
|
|
|
- var tmpFolderFullPath = path.join(__dirname, '..', tmpFolderPath);
|
|
|
- var tmpFileName = 'temp-screenshot.png';
|
|
|
- var tmpFileFullPath = path.join(tmpFolderFullPath, tmpFileName);
|
|
|
-
|
|
|
|
|
|
this.findAndOptimizeScreenshot = function(width) {
|
|
|
var that = this;
|
|
|
|
|
|
debug('Starting screenshot transformation');
|
|
|
|
|
|
- return this.openImage(tmpFileFullPath)
|
|
|
+ return this.openImage(this.getTmpFileRelativePath())
|
|
|
|
|
|
.then(function(image) {
|
|
|
- that.deleteTmpFile(tmpFileFullPath);
|
|
|
+ that.deleteTmpFile(that.getTmpFileRelativePath());
|
|
|
return that.resizeImage(image, width);
|
|
|
})
|
|
|
|
|
@@ -97,7 +92,7 @@ var screenshotHandler = function() {
|
|
|
this.deleteTmpFile = function(tmpFilePath) {
|
|
|
var deferred = Q.defer();
|
|
|
|
|
|
- fs.unlink(tmpFilePath, function (err) {
|
|
|
+ fs.unlink(this.getTmpFileRelativePath(), function (err) {
|
|
|
if (err) {
|
|
|
debug('Screenshot temporary file not found, could not be deleted. But it is not a problem.');
|
|
|
} else {
|
|
@@ -110,31 +105,17 @@ var screenshotHandler = function() {
|
|
|
return deferred.promise;
|
|
|
};
|
|
|
|
|
|
- // Create a /tmp folder on the project's root directory
|
|
|
- this.createTmpScreenshotFolder = function() {
|
|
|
- var deferred = Q.defer();
|
|
|
-
|
|
|
- // Create the folder if it doesn't exist
|
|
|
- fs.exists(tmpFolderFullPath, function(exists) {
|
|
|
- if (exists) {
|
|
|
- deferred.resolve();
|
|
|
- } else {
|
|
|
- debug('Creating the tmp image folder', tmpFolderFullPath);
|
|
|
- fs.mkdir(tmpFolderFullPath, function(err) {
|
|
|
- if (err) {
|
|
|
- deferred.reject(err);
|
|
|
- } else {
|
|
|
- deferred.resolve();
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- return deferred.promise;
|
|
|
- };
|
|
|
|
|
|
this.getTmpFileRelativePath = function() {
|
|
|
- return tmpFolderPath + '/' + tmpFileName;
|
|
|
+
|
|
|
+ // Chrome saves a temporary file on the disk, which is then removed.
|
|
|
+ // Its default folder is /tmp, but it can be changed in server_config/settings.json
|
|
|
+ var serverSettings = require('../server_config/settings.json');
|
|
|
+ var tmpFolderPath = serverSettings.screenshotTempPath || '/tmp';
|
|
|
+ var tmpFileName = 'temp-chrome-screenshot.png';
|
|
|
+ var tmpFileFullPath = path.join(tmpFolderPath, tmpFileName);
|
|
|
+
|
|
|
+ return tmpFileFullPath;
|
|
|
};
|
|
|
};
|
|
|
|