Skip to content

Commit cbe1706

Browse files
Merge pull request #6641 from Countly/fix-home-download
[Fix] Home download
2 parents 5179f1b + f1360c0 commit cbe1706

File tree

5 files changed

+52
-49
lines changed

5 files changed

+52
-49
lines changed

api/utils/requestProcessor.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const validateUserForGlobalAdmin = validateGlobalAdmin;
2424
const validateUserForMgmtReadAPI = validateUser;
2525
const request = require('countly-request')(plugins.getConfig("security"));
2626
const Handle = require('../../api/parts/jobs/index.js');
27+
const render = require('../../api/utils/render.js');
2728

2829
var loaded_configs_time = 0;
2930

@@ -466,6 +467,45 @@ const processRequest = (params) => {
466467
}
467468
break;
468469
}
470+
case '/o/render': {
471+
validateUserForRead(params, function() {
472+
var options = {};
473+
var view = params.qstring.view || "";
474+
var route = params.qstring.route || "";
475+
var id = params.qstring.id || "";
476+
477+
options.view = view + "#" + route;
478+
options.id = id ? "#" + id : "";
479+
480+
var imageName = "screenshot_" + common.crypto.randomBytes(16).toString("hex") + ".png";
481+
482+
options.savePath = path.resolve(__dirname, "../../frontend/express/public/images/screenshots/" + imageName);
483+
options.source = "core";
484+
485+
authorize.save({
486+
db: common.db,
487+
multi: false,
488+
owner: params.member._id,
489+
ttl: 300,
490+
purpose: "LoginAuthToken",
491+
callback: function(err2, token) {
492+
if (err2) {
493+
common.returnMessage(params, 400, 'Error creating token: ' + err2);
494+
return false;
495+
}
496+
options.token = token;
497+
render.renderView(options, function(err3) {
498+
if (err3) {
499+
common.returnMessage(params, 400, 'Error creating screenshot: ' + err3);
500+
return false;
501+
}
502+
common.returnOutput(params, {path: common.config.path + "/images/screenshots/" + imageName});
503+
});
504+
}
505+
});
506+
});
507+
break;
508+
}
469509
case '/i/app_users': {
470510
switch (paths[3]) {
471511
case 'create': {

frontend/express/app.js

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ var versionInfo = require('./version.info'),
5252
url = require('url'),
5353
authorize = require('../../api/utils/authorizer.js'), //for token validations
5454
languages = require('../../frontend/express/locale.conf'),
55-
render = require('../../api/utils/render.js'),
5655
rateLimit = require("express-rate-limit"),
5756
membersUtility = require("./libs/members.js"),
5857
argon2 = require('argon2'),
@@ -1831,48 +1830,6 @@ Promise.all([plugins.dbConnection(countlyConfig), plugins.dbConnection("countly_
18311830
}
18321831
});
18331832

1834-
app.get(countlyConfig.path + '/render', function(req, res) {
1835-
if (!req.session.uid) {
1836-
return res.redirect(countlyConfig.path + '/login');
1837-
}
1838-
1839-
var options = {};
1840-
var view = req.query.view || "";
1841-
var route = req.query.route || "";
1842-
var id = req.query.id || "";
1843-
1844-
options.view = view + "#" + route;
1845-
options.id = id ? "#" + id : "";
1846-
1847-
var randomString = (+new Date()).toString() + (Math.random()).toString();
1848-
var imageName = "screenshot_" + sha1Hash(randomString) + ".png";
1849-
1850-
options.savePath = path.resolve(__dirname, "./public/images/screenshots/" + imageName);
1851-
options.source = "core";
1852-
1853-
authorize.save({
1854-
db: countlyDb,
1855-
multi: false,
1856-
owner: req.session.uid,
1857-
ttl: 300,
1858-
purpose: "LoginAuthToken",
1859-
callback: function(err2, token) {
1860-
if (err2) {
1861-
console.log(err2);
1862-
return res.send(false);
1863-
}
1864-
options.token = token;
1865-
render.renderView(options, function(err3) {
1866-
if (err3) {
1867-
return res.send(false);
1868-
}
1869-
1870-
return res.send({path: countlyConfig.path + "/images/screenshots/" + imageName});
1871-
});
1872-
}
1873-
});
1874-
});
1875-
18761833
app.get(countlyConfig.path + '/login/token/:token', function(req, res) {
18771834
membersUtility.loginWithToken(req, function(member) {
18781835
if (member) {

frontend/express/public/core/home/javascripts/countly.models.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global countlyVue,CV,countlyCommon*/
1+
/* global countlyVue,CV,countlyCommon,countlyGlobal*/
22

33
(function(countlyHomeView) {
44
countlyHomeView.getVuexModule = function() {
@@ -12,11 +12,12 @@
1212
var HomeViewActions = {
1313
downloadScreen: function(context) {
1414
return CV.$.ajax({
15-
type: "GET",
16-
url: "/render?view=/dashboard&route=/" + countlyCommon.ACTIVE_APP_ID + "/",
15+
type: "POST",
16+
url: "/o/render?view=/dashboard&route=/" + countlyCommon.ACTIVE_APP_ID + "/",
1717
data: {
1818
app_id: countlyCommon.ACTIVE_APP_ID,
1919
"id": "main_home_view",
20+
api_key: countlyGlobal.member.api_key,
2021
options: JSON.stringify({"dimensions": {"width": 2000, "padding": 25}})
2122
},
2223
dataType: "json"
@@ -92,4 +93,4 @@
9293
mutations: HomeViewMutations
9394
});
9495
};
95-
}(window.countlyHomeView = window.countlyHomeView || {}));
96+
}(window.countlyHomeView = window.countlyHomeView || {}));

frontend/express/public/core/home/javascripts/countly.views.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ var HomeViewView = countlyVue.views.create({
222222
CountlyHelpers.notify({type: "ok", title: jQuery.i18n.map["common.success"], message: "Starting the image generation process. You will be notified when it is ready. Please do not leave the website while the process is running.", sticky: true, clearAll: true});
223223
this.$store.dispatch("countlyHomeView/downloadScreen").then(function() {
224224
if (self.$store.state.countlyHomeView.image) {
225-
CountlyHelpers.notify({type: "ok", title: jQuery.i18n.map["common.success"], message: "<a href='" + self.$store.state.countlyHomeView.image + "'>Download</a>", sticky: true, clearAll: true});
225+
CountlyHelpers.notify({type: "ok", title: jQuery.i18n.map["common.success"], message: "<a href='" + self.$store.state.countlyHomeView.image + "' target='_blank'>" + jQuery.i18n.map["common.download"] + "</a>", sticky: true, clearAll: true, html: true});
226226
}
227227
else {
228228
CountlyHelpers.notify({type: "error", title: jQuery.i18n.map["common.success"], message: "ERROR", sticky: false, clearAll: true});

frontend/express/public/javascripts/countly/countly.helpers.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,12 @@
337337
}
338338
var payload = {};
339339
var persistent = msg.persistent;
340-
payload.text = countlyCommon.encodeHtml(msg.message);
340+
if (msg.html) {
341+
payload.text = msg.message;
342+
}
343+
else {
344+
payload.text = countlyCommon.encodeHtml(msg.message);
345+
}
341346
payload.autoHide = !msg.sticky;
342347
payload.id = msg.id;
343348
payload.width = msg.width;

0 commit comments

Comments
 (0)