fix(web): исправить некорректное отображение подписи 'Н/Д' для токенов и улучшить regex санитаризации
This commit is contained in:
parent
e738dd0c5d
commit
c9c9586bff
2 changed files with 9 additions and 4 deletions
|
|
@ -78,7 +78,7 @@ def health_check():
|
||||||
def sanitize_snapshot(snap_dict: Any) -> Any:
|
def sanitize_snapshot(snap_dict: Any) -> Any:
|
||||||
import re
|
import re
|
||||||
secret_patterns = [
|
secret_patterns = [
|
||||||
re.compile(r'(access_token|refresh_token|api_key|token|password|secret|key)=([^\s&,"]+)', re.IGNORECASE),
|
re.compile(r'((?:access_token|refresh_token|api_key|token|password|secret|key)=)([^\s&,"]+)', re.IGNORECASE),
|
||||||
re.compile(r'(sk-[a-zA-Z0-9_\-]{8,})'),
|
re.compile(r'(sk-[a-zA-Z0-9_\-]{8,})'),
|
||||||
re.compile(r'(gho_[a-zA-Z0-9_\-]{8,})'),
|
re.compile(r'(gho_[a-zA-Z0-9_\-]{8,})'),
|
||||||
re.compile(r'(Bearer\s+)([a-zA-Z0-9_\-\.]{8,})', re.IGNORECASE),
|
re.compile(r'(Bearer\s+)([a-zA-Z0-9_\-\.]{8,})', re.IGNORECASE),
|
||||||
|
|
@ -88,7 +88,7 @@ def sanitize_snapshot(snap_dict: Any) -> Any:
|
||||||
res = val
|
res = val
|
||||||
for pat in secret_patterns:
|
for pat in secret_patterns:
|
||||||
if pat.groups == 2:
|
if pat.groups == 2:
|
||||||
res = pat.sub(r'\1=***', res)
|
res = pat.sub(r'\g<1>***', res)
|
||||||
elif pat.groups == 1:
|
elif pat.groups == 1:
|
||||||
res = pat.sub(r'***', res)
|
res = pat.sub(r'***', res)
|
||||||
return res
|
return res
|
||||||
|
|
|
||||||
|
|
@ -777,16 +777,21 @@ function renderAnalyticsView() {
|
||||||
// KPI 4: Tokens (Honesty rule: null means N/D, never 0)
|
// KPI 4: Tokens (Honesty rule: null means N/D, never 0)
|
||||||
const tokensEl = document.getElementById('analytics-tokens-total');
|
const tokensEl = document.getElementById('analytics-tokens-total');
|
||||||
const tokensSubEl = document.getElementById('analytics-tokens-sub');
|
const tokensSubEl = document.getElementById('analytics-tokens-sub');
|
||||||
|
const hasTokens = global.total_tokens !== null && global.total_tokens !== undefined;
|
||||||
if (tokensEl) {
|
if (tokensEl) {
|
||||||
if (global.total_tokens !== null && global.total_tokens !== undefined) {
|
if (hasTokens) {
|
||||||
tokensEl.textContent = global.total_tokens.toLocaleString('ru-RU');
|
tokensEl.textContent = global.total_tokens.toLocaleString('ru-RU');
|
||||||
} else {
|
} else {
|
||||||
tokensEl.textContent = 'Н/Д';
|
tokensEl.textContent = 'Н/Д';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tokensSubEl) {
|
if (tokensSubEl) {
|
||||||
|
if (hasTokens) {
|
||||||
|
tokensSubEl.textContent = 'Учитывается провайдером';
|
||||||
|
} else {
|
||||||
tokensSubEl.textContent = 'Н/Д: провайдеры не отдают данные о токенах';
|
tokensSubEl.textContent = 'Н/Д: провайдеры не отдают данные о токенах';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Providers Table
|
// Providers Table
|
||||||
const provTableBox = document.getElementById('analytics-providers-table');
|
const provTableBox = document.getElementById('analytics-providers-table');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue