The screenshot is now saved in the system /tmp folder

This commit is contained in:
Gaël Métais
2021-03-14 01:35:26 +00:00
parent 791bf9fc8d
commit 2da4371847
4 changed files with 24 additions and 42 deletions
+12 -31
View File
@@ -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;
};
};
-3
View File
@@ -51,9 +51,6 @@ var ApiController = function(app) {
}
};
// Create the tmp folder if it doesn't exist
ScreenshotHandler.createTmpScreenshotFolder(run.runId);
// Add test to the testQueue
debug('Adding test %s to the queue', run.runId);
var queuePromise = queue.push(run.runId);
+6 -4
View File
@@ -1,16 +1,18 @@
{
"serverPort": 80,
"baseUrl": "/",
"googleAnalyticsId": "",
"screenshotWidth": {
"phone": 360,
"tablet": 420,
"desktop": 600,
"desktop-hd": 600
},
"baseUrl": "/",
"authorizedKeys": {
},
"screenshotTempPath": "/tmp/",
"authorizedKeys": {},
"maxAnonymousRunsPerDay": 1000,
"maxAnonymousCallsPerDay": 100000,
"blockedUrls": [],
+6 -4
View File
@@ -1,16 +1,18 @@
{
"serverPort": 8383,
"baseUrl": "/",
"googleAnalyticsId": "",
"screenshotWidth": {
"phone": 360,
"tablet": 420,
"desktop": 600,
"desktop-hd": 600
},
"baseUrl": "/",
"authorizedKeys": {
},
"screenshotTempPath": "/tmp/",
"authorizedKeys": {},
"maxAnonymousRunsPerDay": 99999999,
"maxAnonymousCallsPerDay": 99999999,
"blockedUrls": [],