Files
EvoFirewall/apps/web/src/lib/stats-csv.ts
T
Denozordec 9fa6269174
quality / changes (push) Successful in 7s
quality / commitlint (push) Skipped
quality / openapi (push) Successful in 30s
quality / web (push) Successful in 1m3s
quality / api (push) Successful in 1m15s
quality / linux-agent-smoke (push) Failing after 27s
quality / docker-check (push) Failing after 2m28s
CD / quality (push) Failing after 5m52s
CD / publish (push) Skipped
feat: harden firewall policies telemetry and operations
Implement reliable agent apply, telemetry v2, analytics retention, guarded rollouts, enrollment, labels and webhooks. Improve ReUI frontend data safety and bounded list loading, and add Docker smoke, recovery and resource checks. Document local verification and pending native acceptance.
2026-10-26 13:10:58 +07:00

28 lines
1.4 KiB
TypeScript

import { apiRequest } from '@/lib/api'
import { timeseriesSearch, type TimeseriesRequest } from './timeseries'
const MAX_CSV_BYTES = 2 * 1024 * 1024
/** Uses the same authorization, HTTP errors and bounded request as JSON. A
* bearer token never appears in an export URL or download filename. */
export async function fetchStatsCsv(request: TimeseriesRequest, signal?: AbortSignal): Promise<Blob> {
const search = timeseriesSearch(request)
const response = await apiRequest(`/api/v1/stats/timeseries.csv?${search}`, { signal, headers: { Accept: 'text/csv' } })
if (!response.headers.get('Content-Type')?.toLowerCase().includes('text/csv')) throw new Error('Сервер не вернул CSV')
if (Number(response.headers.get('Content-Length')) > MAX_CSV_BYTES) throw new Error('CSV превышает допустимый размер')
const blob = await response.blob()
if (blob.size > MAX_CSV_BYTES) throw new Error('CSV превышает допустимый размер')
return blob
}
export function saveStatsCsv(blob: Blob, request: TimeseriesRequest) {
const url = URL.createObjectURL(blob)
const anchor = document.createElement('a')
anchor.href = url
anchor.download = `evofw-packets-${request.resolution}-${request.from.slice(0, 10)}-${request.to.slice(0, 10)}.csv`
document.body.appendChild(anchor)
anchor.click()
anchor.remove()
window.setTimeout(() => URL.revokeObjectURL(url), 1000)
}