Skip to content

Commit

Permalink
Requested Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Rıza Kat committed Aug 14, 2024
1 parent 863b1a3 commit 8cb8b57
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
41 changes: 22 additions & 19 deletions lib/countly-storage.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
const fs = require('fs');
const path = require('path');
var cc = require("./countly-common");

var storagePath;
var __data = {};
var defaultPath = "../data/"; // Default path
var defaultBulkPath = "../bulk_data/"; // Default path

var setStoragePath = function (path) {
defaultPath = "../data/"; // Default path
storagePath = path || defaultPath;
}
var setStoragePath = function(userPath) {
storagePath = userPath || defaultPath;
};

var setBulkDataPath = function (path) {
defaultPath = "../bulk_data/"; // Default path
storagePath = path || defaultPath;
}
var setBulkDataPath = function(userPath) {
storagePath = userPath || defaultBulkPath;
};

var getStoragePath = function () {
var getStoragePath = function() {
return storagePath;
}
};

var clearStoragePath = function () {
var resetStorage = function() {
storagePath = undefined;
return storagePath;
}
__data = {};
asyncWriteLock = false;
asyncWriteQueue = [];
};

/**
* Read value from file
* @param {String} key - key for file
* @returns {varies} value in file
*/
var readFile = function (key) {
var readFile = function(key) {
var dir = path.resolve(__dirname, `${getStoragePath()}__${key}.json`);

// try reading data file
Expand Down Expand Up @@ -59,7 +62,7 @@ var readFile = function (key) {
/**
* Force store data synchronously on unrecoverable errors to preserve it for next launch
*/
var forceStore = function () {
var forceStore = function() {
for (var i in __data) {
var dir = path.resolve(__dirname, `${getStoragePath()}__${i}.json`);
var ob = {};
Expand All @@ -83,7 +86,7 @@ var asyncWriteQueue = [];
* @param {varies} value - value to store
* @param {Function} callback - callback to call when done storing
*/
var writeFile = function (key, value, callback) {
var writeFile = function(key, value, callback) {
var ob = {};
ob[key] = value;
var dir = path.resolve(__dirname, `${getStoragePath()}__${key}.json`);
Expand Down Expand Up @@ -112,7 +115,7 @@ var writeFile = function (key, value, callback) {
* @param {varies} value - value to store
* @param {Function} callback - callback to call when done storing
*/
var storeSet = function (key, value, callback) {
var storeSet = function(key, value, callback) {
__data[key] = value;
if (!asyncWriteLock) {
asyncWriteLock = true;
Expand All @@ -129,7 +132,7 @@ var storeSet = function (key, value, callback) {
* @param {varies} def - default value to use if not set
* @returns {varies} value for the key
*/
var storeGet = function (key, def) {
var storeGet = function(key, def) {
cc.log(cc.logLevelEnums.DEBUG, `storeGet, Fetching item from storage with key: [${key}].`);
if (typeof __data[key] === "undefined") {
var ob = readFile(key);
Expand Down Expand Up @@ -163,6 +166,6 @@ module.exports = {
getStoragePath,
setStoragePath,
setBulkDataPath,
clearStoragePath,
resetStorage,
readFile,
};
8 changes: 2 additions & 6 deletions lib/countly.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Countly.Bulk = Bulk;
cc.log(cc.logLevelEnums.DEBUG, `init, IP address: [${Countly.ip_address}].`);
}
cc.log(cc.logLevelEnums.DEBUG, `init, Force POST requests: [${Countly.force_post}].`);
cc.log(cc.logLevelEnums.DEBUG, `init, Storage path: [${Countly.storage_path}].`);
cc.log(cc.logLevelEnums.DEBUG, `init, Storage path: [${CountlyStorage.getStoragePath()}].`);
cc.log(cc.logLevelEnums.DEBUG, `init, Require consent: [${Countly.require_consent}].`);
if (Countly.remote_config) {
cc.log(cc.logLevelEnums.DEBUG, `init, Automatic Remote Configuration is on.`);
Expand Down Expand Up @@ -328,7 +328,6 @@ Countly.Bulk = Bulk;
maxBreadcrumbCount = 100;
maxStackTraceLinesPerThread = 30;
maxStackTraceLineLength = 200;
__data = {};
deviceIdType = null;

// cc DEBUG
Expand All @@ -354,12 +353,9 @@ Countly.Bulk = Bulk;
Countly.city = undefined;
Countly.ip_address = undefined;
Countly.force_post = undefined;
Countly.storage_path = CountlyStorage.clearStoragePath();
Countly.require_consent = undefined;
Countly.http_options = undefined;

asyncWriteLock = false;
asyncWriteQueue = [];
CountlyStorage.resetStorage();
};

/**
Expand Down

0 comments on commit 8cb8b57

Please sign in to comment.