padavan 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +6 -2
- package/src/utils/sanitizers.js +26 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { debuglog, inspect } from 'util';
|
|
|
2
2
|
import jszip from 'jszip';
|
|
3
3
|
import HttpClient from './transport/http.js';
|
|
4
4
|
import GitHubClient from './transport/github.js';
|
|
5
|
+
import { sanitizeObject } from './utils/sanitizers.js';
|
|
5
6
|
import {
|
|
6
7
|
parsePageInputs, parseNvramOutput, parseLooseJson, normalizeTrafficHistory,
|
|
7
8
|
extractJsVariable, extractTextareaValue, extractMacsFromTextarea, extractCurrentChannel
|
|
@@ -118,13 +119,16 @@ export default class Padavan {
|
|
|
118
119
|
* @param {Config} config Конфигурация для подключения.
|
|
119
120
|
*/
|
|
120
121
|
constructor(config = {}) {
|
|
121
|
-
|
|
122
|
+
const sanitized = sanitizeObject(config, ['credentials', 'logLevel']);
|
|
123
|
+
if (sanitized.credentials)
|
|
124
|
+
sanitized.credentials = sanitizeObject(sanitized.credentials, ['host', 'port', 'username', 'password', 'repo', 'branch', 'token']);
|
|
125
|
+
this.config = sanitized;
|
|
122
126
|
this.#debugLog = debuglog(LIB_ID);
|
|
123
127
|
this.#isDebugEnvEnabled = process.env.NODE_DEBUG && new RegExp(`\\b${LIB_ID}\\b`, 'i').test(process.env.NODE_DEBUG);
|
|
124
128
|
this.#logLevelNumber = LOG_LEVELS[config?.logLevel] || LOG_LEVELS[DEFAULT_LOG_LEVEL];
|
|
125
129
|
this.#http = new HttpClient(this.config?.credentials, this.log.bind(this));
|
|
126
130
|
this.#github = new GitHubClient(this.config?.credentials, this.log.bind(this));
|
|
127
|
-
this.log('debug', 'Padavan instance created with config:', config);
|
|
131
|
+
this.log('debug', 'Padavan instance created with config:', this.config);
|
|
128
132
|
};
|
|
129
133
|
|
|
130
134
|
/**
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Рекурсивно очищает объект от пустых значений и неразрешенных ключей
|
|
3
|
+
* @param {Object} obj Исходный объект.
|
|
4
|
+
* @param {string[]} [allowedKeys] Список разрешенных ключей (если null - разрешены все).
|
|
5
|
+
* @returns {Object} Очищенный объект.
|
|
6
|
+
*/
|
|
7
|
+
export function sanitizeObject(obj, allowedKeys = null) {
|
|
8
|
+
if (!obj || typeof obj !== 'object' || Array.isArray(obj))
|
|
9
|
+
return obj;
|
|
10
|
+
|
|
11
|
+
const result = {};
|
|
12
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
13
|
+
if (allowedKeys && !allowedKeys.includes(key))
|
|
14
|
+
continue;
|
|
15
|
+
if (value === '' || value === null || value === undefined)
|
|
16
|
+
continue;
|
|
17
|
+
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
18
|
+
const cleaned = sanitizeObject(value);
|
|
19
|
+
if (Object.keys(cleaned).length > 0)
|
|
20
|
+
result[key] = cleaned;
|
|
21
|
+
} else
|
|
22
|
+
result[key] = value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return result;
|
|
26
|
+
};
|