From bd1a339dcd2ea188a723a4c2554fc4af5c97fbb4 Mon Sep 17 00:00:00 2001 From: Arturs Sosins Date: Thu, 1 Apr 2021 19:27:24 +0300 Subject: [PATCH] [export] use internal request processor instead of making localhost requests --- CHANGELOG.md | 2 + api/parts/data/exports.js | 61 ++++++++----------- .../public/javascripts/countly.views.js | 2 +- 3 files changed, 29 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e996b9de72..107c92bd873 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * [configs] fix refreshing value when updating config * [config] subdirectory cases for localhost calls * [crashes] updated app version column header +* [export] use internal request processor instead of localhost for request exports * [logger] remove sdk mismatch warning as they should be fully cross compatible * [populator] add populator tag to all generated users * [push] batched sent messages deletion @@ -22,6 +23,7 @@ * [sources] fixed direct calculation logic * [star-rating] feedback sticker style bug fixed * [views] fix view postprocessing with dots in names +* [views] fixed view export file name * [views] show view names in graph tooltips **Enterprise fixes** diff --git a/api/parts/data/exports.js b/api/parts/data/exports.js index 3bbf6cb9f5f..16bf46556c5 100644 --- a/api/parts/data/exports.js +++ b/api/parts/data/exports.js @@ -8,10 +8,8 @@ var exports = {}, common = require('./../../utils/common.js'), moment = require('moment-timezone'), plugin = require('./../../../plugins/pluginManager.js'), - countlyConfig = require("../../../frontend/express/config.js"), json2csv = require('json2csv'), - json2xls = require('json2xls'), - request = require("request"); + json2xls = require('json2xls'); //npm install node-xlsx-stream !!!!! var xlsx = require("node-xlsx-stream"); @@ -483,44 +481,37 @@ exports.fromRequest = function(options) { if (!options.path.startsWith("/")) { options.path = "/" + options.path; } - var opts = { - uri: "http://" + (process.env.COUNTLY_CONFIG_HOSTNAME || "localhost") + (countlyConfig.path || "") + options.path, - method: options.method || 'POST', - json: options.data || {}, - strictSSL: false - }; options.filename = options.filename || options.path.replace(/\//g, "_") + "_on_" + moment().format("DD-MMM-YYYY"); - /** - * Make request to get data - */ - function makeRequest() { - request(opts, function(error, response, body) { - //we got a redirect, we need to follow it - if (response && response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) { - opts.uri = response.headers.location; - makeRequest(); - } - else { - var data = []; - try { - if (options.prop) { - var path = options.prop.split("."); - for (var i = 0; i < path.length; i++) { - body = body[path[i]]; - } + //creating request context + var params = { + //providing data in request object + 'req': { + url: options.path, + body: options.data || {}, + method: "export" + }, + //adding custom processing for API responses + 'APICallback': function(err, body) { + var data = []; + try { + if (options.prop) { + var path = options.prop.split("."); + for (var i = 0; i < path.length; i++) { + body = body[path[i]]; } - data = body; } - catch (ex) { - data = []; - } - exports.fromData(data, options); + data = body; } - }); - } + catch (ex) { + data = []; + } + exports.fromData(data, options); + } + }; - makeRequest(); + //processing request + common.processRequest(params); }; /** diff --git a/plugins/views/frontend/public/javascripts/countly.views.js b/plugins/views/frontend/public/javascripts/countly.views.js index fa2eff27105..af1cb0d22a2 100644 --- a/plugins/views/frontend/public/javascripts/countly.views.js +++ b/plugins/views/frontend/public/javascripts/countly.views.js @@ -55,7 +55,7 @@ window.ViewsView = countlyView.extend({ app_id: countlyCommon.ACTIVE_APP_ID, path: requestPath, method: "GET", - filename: "Systemlogs_on_" + moment().format("DD-MMM-YYYY"), + filename: "Views_on_" + moment().format("DD-MMM-YYYY"), prop: ['aaData'] }; return apiQueryData;