chore: fix eslint errors
This commit is contained in:
parent
e7d8e65718
commit
e63714e9f4
15
app.js
15
app.js
@ -1,12 +1,10 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const rateLimit = require('express-rate-limit');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const bodyParser = require('body-parser');
|
const bodyParser = require('body-parser');
|
||||||
const API = require('./src/js/index.js');
|
const API = require('./src/js/index.js');
|
||||||
const demoTracker = require('./src/js/demoTracker.js');
|
const demoTracker = require('./src/js/demoTracker.js');
|
||||||
const { logger } = require('./src/js/logger.js');
|
const { logger } = require('./src/js/logger.js');
|
||||||
const favicon = require('serve-favicon');
|
const favicon = require('serve-favicon');
|
||||||
const fs = require('fs');
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = process.env.PORT || 3512;
|
const port = process.env.PORT || 3512;
|
||||||
const {
|
const {
|
||||||
@ -116,8 +114,7 @@ app.post('/api/stats', async (req, res) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let { username, ssoToken, platform, game, apiCall, sanitize, replaceKeys } =
|
let { username, ssoToken, platform, game, apiCall } = req.body;
|
||||||
req.body;
|
|
||||||
|
|
||||||
const defaultToken = demoTracker.getDefaultSsoToken();
|
const defaultToken = demoTracker.getDefaultSsoToken();
|
||||||
if (!ssoToken && defaultToken) {
|
if (!ssoToken && defaultToken) {
|
||||||
@ -375,8 +372,7 @@ app.post('/api/matches', async (req, res) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let { username, ssoToken, platform, game, sanitize, replaceKeys } =
|
let { username, ssoToken, platform, game } = req.body;
|
||||||
req.body;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
logger.debug(
|
logger.debug(
|
||||||
@ -539,7 +535,7 @@ app.post('/api/matchInfo', async (req, res) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let { matchId, ssoToken, platform, game, sanitize, replaceKeys } = req.body;
|
let { matchId, ssoToken, platform, game } = req.body;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
logger.debug(
|
logger.debug(
|
||||||
@ -688,8 +684,7 @@ app.post('/api/user', async (req, res) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let { username, ssoToken, platform, userCall, sanitize, replaceKeys } =
|
let { username, ssoToken, platform, userCall } = req.body;
|
||||||
req.body;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
logger.debug(
|
logger.debug(
|
||||||
@ -830,7 +825,7 @@ app.post('/api/search', async (req, res) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let { username, ssoToken, platform, sanitize, replaceKeys } = req.body;
|
let { username, ssoToken, platform } = req.body;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
@ -15,7 +15,9 @@
|
|||||||
"build:win64": "pkg . --targets node18-win-x64 --experimental-modules --icon src/images/favicon.ico --output dist/codtrackerjs-aio-win-amd64.exe",
|
"build:win64": "pkg . --targets node18-win-x64 --experimental-modules --icon src/images/favicon.ico --output dist/codtrackerjs-aio-win-amd64.exe",
|
||||||
"build:linux64": "pkg . --targets node18-linux-x64 --experimental-modules --output dist/codtrackerjs-aio-linux-amd64",
|
"build:linux64": "pkg . --targets node18-linux-x64 --experimental-modules --output dist/codtrackerjs-aio-linux-amd64",
|
||||||
"start": "node app.js",
|
"start": "node app.js",
|
||||||
"lint": "prettier --write .",
|
"prettify": "prettier --write .",
|
||||||
|
"lint": "eslint --no-config-lookup .",
|
||||||
|
"lint:fix": "eslint --no-config-lookup . --fix",
|
||||||
"dev": "nodemon app.js"
|
"dev": "nodemon app.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -107,7 +107,7 @@ const clientLogger = {
|
|||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
...data,
|
...data,
|
||||||
}),
|
}),
|
||||||
}).catch((e) => logger.error('Logging error:', e));
|
}).catch((e) => console.error('Logging error:', e));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -315,9 +315,7 @@ function setupProcessingOptions() {
|
|||||||
if (window.appState.currentData) {
|
if (window.appState.currentData) {
|
||||||
// Call window.appState
|
// Call window.appState
|
||||||
// Re-fetch with new options
|
// Re-fetch with new options
|
||||||
const activeTab = document
|
document.querySelector('.tab.active').getAttribute('data-tab');
|
||||||
.querySelector('.tab.active')
|
|
||||||
.getAttribute('data-tab');
|
|
||||||
triggerActiveTabButton();
|
triggerActiveTabButton();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -327,9 +325,7 @@ function setupProcessingOptions() {
|
|||||||
.addEventListener('change', function () {
|
.addEventListener('change', function () {
|
||||||
if (window.appState.currentData) {
|
if (window.appState.currentData) {
|
||||||
// Re-fetch with new options
|
// Re-fetch with new options
|
||||||
const activeTab = document
|
document.querySelector('.tab.active').getAttribute('data-tab');
|
||||||
.querySelector('.tab.active')
|
|
||||||
.getAttribute('data-tab');
|
|
||||||
triggerActiveTabButton();
|
triggerActiveTabButton();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -516,6 +512,7 @@ function initializeSessionTracking() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
// Helper function to extract data attributes
|
// Helper function to extract data attributes
|
||||||
function getDataAttributes(element) {
|
function getDataAttributes(element) {
|
||||||
if (!element.dataset) return {};
|
if (!element.dataset) return {};
|
||||||
@ -523,7 +520,7 @@ function initializeSessionTracking() {
|
|||||||
acc[key] = value;
|
acc[key] = value;
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
}
|
} */
|
||||||
|
|
||||||
// Track tab visibility changes
|
// Track tab visibility changes
|
||||||
document.addEventListener('visibilitychange', () => {
|
document.addEventListener('visibilitychange', () => {
|
||||||
|
@ -26,37 +26,42 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Optimized replaceJsonKeys function
|
// Optimized replaceJsonKeys function
|
||||||
const replaceJsonKeys = (obj, replacements) => {
|
const replaceJsonKeys = (obj) => {
|
||||||
// Handle non-objects early
|
|
||||||
if (!obj || typeof obj !== 'object') return obj;
|
if (!obj || typeof obj !== 'object') return obj;
|
||||||
|
|
||||||
// Fast path for arrays
|
// Fast-path for arrays
|
||||||
if (Array.isArray(obj)) {
|
if (Array.isArray(obj)) {
|
||||||
return obj.length === 0 ?
|
// Only process array if it has items
|
||||||
obj
|
return obj.length > 0 ? obj.map(replaceJsonKeys) : obj;
|
||||||
: obj.map((item) => replaceJsonKeys(item, replacements));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fast path for empty objects
|
|
||||||
const keys = Object.keys(obj);
|
|
||||||
if (keys.length === 0) return obj;
|
|
||||||
|
|
||||||
// Process normal objects
|
|
||||||
const newObj = {};
|
const newObj = {};
|
||||||
for (let i = 0; i < keys.length; i++) {
|
const objKeys = Object.keys(obj);
|
||||||
const key = keys[i];
|
|
||||||
const newKey = replacements[key] || key;
|
// Fast-path for empty objects
|
||||||
|
if (objKeys.length === 0) return obj;
|
||||||
|
|
||||||
|
// Cache key check
|
||||||
|
const hasKeyReplacements = Object.keys(keyReplacements).length > 0;
|
||||||
|
|
||||||
|
for (const key of objKeys) {
|
||||||
|
// Replace key if replacements exist
|
||||||
|
const newKey =
|
||||||
|
hasKeyReplacements && keyReplacements[key] ? keyReplacements[key] : key;
|
||||||
let value = obj[key];
|
let value = obj[key];
|
||||||
|
|
||||||
// Replace string values if they match a key in replacements
|
// Replace string values if needed
|
||||||
if (typeof value === 'string' && replacements[value]) {
|
if (
|
||||||
value = replacements[value];
|
hasKeyReplacements &&
|
||||||
} else if (value && typeof value === 'object') {
|
typeof value === 'string' &&
|
||||||
// Only recurse for objects/arrays
|
keyReplacements[value]
|
||||||
value = replaceJsonKeys(value, replacements);
|
) {
|
||||||
|
value = keyReplacements[value];
|
||||||
}
|
}
|
||||||
|
|
||||||
newObj[newKey] = value;
|
// Process recursively only if object/array
|
||||||
|
newObj[newKey] =
|
||||||
|
value && typeof value === 'object' ? replaceJsonKeys(value) : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return newObj;
|
return newObj;
|
||||||
@ -88,18 +93,27 @@ const sanitizeJsonOutput = (data) => {
|
|||||||
// Replace the processJsonOutput function with this more efficient version
|
// Replace the processJsonOutput function with this more efficient version
|
||||||
const processJsonOutput = (
|
const processJsonOutput = (
|
||||||
data,
|
data,
|
||||||
options = {
|
options = { sanitize: true, replaceKeys: true }
|
||||||
sanitize: true,
|
|
||||||
replaceKeys: true,
|
|
||||||
keyReplacements: {},
|
|
||||||
}
|
|
||||||
) => {
|
) => {
|
||||||
// Early return for null or non-objects
|
// Use a more efficient deep clone approach instead of JSON.parse(JSON.stringify())
|
||||||
if (data === null || typeof data !== 'object') {
|
function deepClone(obj) {
|
||||||
return data;
|
if (obj === null || typeof obj !== 'object') {
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy data first to avoid reference issues
|
if (Array.isArray(obj)) {
|
||||||
|
return obj.map((item) => deepClone(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
const clone = {};
|
||||||
|
Object.keys(obj).forEach((key) => {
|
||||||
|
clone[key] = deepClone(obj[key]);
|
||||||
|
});
|
||||||
|
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a deep copy of the data to avoid reference issues
|
||||||
let processedData = deepClone(data);
|
let processedData = deepClone(data);
|
||||||
|
|
||||||
// Apply sanitization if needed
|
// Apply sanitization if needed
|
||||||
@ -107,48 +121,14 @@ const processJsonOutput = (
|
|||||||
processedData = sanitizeJsonOutput(processedData);
|
processedData = sanitizeJsonOutput(processedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply key replacement if needed - pass replacements directly
|
// Apply key replacement if needed
|
||||||
if (
|
if (options.replaceKeys) {
|
||||||
options.replaceKeys &&
|
processedData = replaceJsonKeys(processedData);
|
||||||
Object.keys(options.keyReplacements || {}).length > 0
|
|
||||||
) {
|
|
||||||
processedData = replaceJsonKeys(processedData, options.keyReplacements);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return processedData;
|
return processedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Optimized deep clone function
|
|
||||||
* @param {any} obj - The object to clone
|
|
||||||
* @returns {any} - The cloned object
|
|
||||||
*/
|
|
||||||
const deepClone = (obj) => {
|
|
||||||
if (obj === null || typeof obj !== 'object') {
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fast path for arrays
|
|
||||||
if (Array.isArray(obj)) {
|
|
||||||
const length = obj.length;
|
|
||||||
const clone = new Array(length);
|
|
||||||
for (let i = 0; i < length; i++) {
|
|
||||||
clone[i] = deepClone(obj[i]);
|
|
||||||
}
|
|
||||||
return clone;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fast path for objects
|
|
||||||
const clone = {};
|
|
||||||
const keys = Object.keys(obj);
|
|
||||||
for (let i = 0; i < keys.length; i++) {
|
|
||||||
const key = keys[i];
|
|
||||||
clone[key] = deepClone(obj[key]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return clone;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Store active sessions to avoid repeated logins
|
// Store active sessions to avoid repeated logins
|
||||||
const activeSessions = new Map();
|
const activeSessions = new Map();
|
||||||
|
|
||||||
@ -190,6 +170,7 @@ class ApiTimeoutError extends Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
class ApiAuthError extends Error {
|
class ApiAuthError extends Error {
|
||||||
constructor(message = 'Authentication failed') {
|
constructor(message = 'Authentication failed') {
|
||||||
super(message);
|
super(message);
|
||||||
@ -202,7 +183,7 @@ class ApiDataError extends Error {
|
|||||||
super(message);
|
super(message);
|
||||||
this.name = 'ApiDataError';
|
this.name = 'ApiDataError';
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
|
|
||||||
// Helper function to handle API errors
|
// Helper function to handle API errors
|
||||||
const handleApiError = (error, res) => {
|
const handleApiError = (error, res) => {
|
||||||
|
@ -3,7 +3,7 @@ import fs from 'fs';
|
|||||||
|
|
||||||
// Login using the SSO token
|
// Login using the SSO token
|
||||||
const ssoToken =
|
const ssoToken =
|
||||||
'MTk1NjgyNzA6MTc0NDQ4OTcxNDE4MDpiOGE2MDEwMzY1ZWQ5OTM0NGM3ZjA0MWQxMTFjMTExNA';
|
'<YOUR_SSO_TOKEN>';
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user