فهرست منبع

The screenshot is now saved in the system /tmp folder

Gaël Métais 4 سال پیش
والد
کامیت
2da4371847
4فایلهای تغییر یافته به همراه24 افزوده شده و 42 حذف شده
  1. 12 31
      lib/screenshotHandler.js
  2. 0 3
      lib/server/controllers/apiController.js
  3. 6 4
      server_config/settings-prod.json
  4. 6 4
      server_config/settings.json

+ 12 - 31
lib/screenshotHandler.js

@@ -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;
     };
 };
 

+ 0 - 3
lib/server/controllers/apiController.js

@@ -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
server_config/settings-prod.json

@@ -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
server_config/settings.json

@@ -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": [],