api update

This commit is contained in:
Mateusz Gruszczyński
2026-02-25 10:02:37 +01:00
parent 9ccb1651b6
commit 1d8071966b
3 changed files with 257 additions and 69 deletions

View File

@@ -94,6 +94,217 @@
</div>
</div>
<!-- Cache Status - Redis-->
<div class="card mb-3">
<div class="card-header api-header-get" onclick="toggleEndpoint('endpoint-cache-redis-status')">
<div class="d-flex justify-content-between align-items-center">
<div>
<span class="badge bg-info me-2">GET</span>
<code class="api-path">/api/cache/redis/status</code>
<span class="ms-3 text-muted">Redis L1 cache</span>
</div>
<i class="fas fa-chevron-down"></i>
</div>
</div>
<div class="card-body collapse" id="endpoint-cache-redis-status">
<h6 class="fw-bold">Description</h6>
<p>Redis (L1: configs/networks)</p>
<h6 class="fw-bold mt-3">Response Schema</h6>
<pre><code>{
"success": <span class="text-success">true</span>,
"enabled": <span class="text-success">true</span>,
"health": {
"connected": <span class="text-success">true</span>,
"memory_peak_mb": <span class="text-info">474.25</span>,
"memory_used_mb": <span class="text-info">241.38</span>,
"status": <span class="text-success">"healthy"</span>
},
"stats": {
"country_keys": <span class="text-info">119</span>,
"config_keys": <span class="text-info">0</span>,
"total_keys": <span class="text-info">119</span>,
"total_size_mb": <span class="text-info">240.4</span>
}
}
</code></pre>
<h6 class="fw-bold mt-3">Fields</h6>
<table class="table table-sm">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>enabled</code></td>
<td>boolean</td>
<td>Redis configured (REDISENABLED=false)</td>
</tr>
<tr>
<td><code>health.connected</code></td>
<td>boolean</td>
<td>TCP connection OK</td>
</tr>
<tr>
<td><code>health.memory_peak_mb</code></td>
<td>float</td>
<td>Redis peak memory usage</td>
</tr>
<tr>
<td><code>stats.country_keys</code></td>
<td>integer</td>
<td><code>geobancountry*</code> keys (119 networks cached)</td>
</tr>
<tr>
<td><code>stats.config_keys</code></td>
<td>integer</td>
<td><code>geoipconfig*</code> + <code>geobanconfig*</code> (0 configs)</td>
</tr>
</tbody>
</table>
<h6 class="fw-bold mt-3">Cache Flow</h6>
<div class="alert alert-info">
<strong>L1 Redis:</strong> configs/networks (&lt;1s) →
<strong>L2 SQLite:</strong> fallback networks →
<strong>L3 MaxMind:</strong> live scan
</div>
<h6 class="fw-bold mt-3">Error Handling</h6>
<div class="alert alert-warning">
Redis offline? → Returns partial stats + <code>"error": "Connection refused"</code><br>
Logs: <code>ConnectionError: Error 111 connecting to localhost:6379</code>
</div>
<h6 class="fw-bold mt-3">Try it out</h6>
<button class="btn btn-sm btn-primary" onclick="tryEndpoint('cache/redis/status')">
<i class="fas fa-play me-1"></i>Execute
</button>
<div id="response-cache-redis-status" class="mt-3" style="display:none;">
<h6 class="fw-bold">Response</h6>
<pre><code id="response-cache-redis-status-body"></code></pre>
</div>
</div>
</div>
<!-- SQLite Status (L2 Cache) -->
<div class="card mb-3">
<div class="card-header api-header-get" onclick="toggleEndpoint('endpoint-cache-sqlite-status')">
<div class="d-flex justify-content-between align-items-center">
<div>
<span class="badge bg-info me-2">GET</span>
<code class="api-path">/api/cache/sqlite/status</code>
<span class="ms-3 text-muted">SQLite L2 cache</span>
</div>
<i class="fas fa-chevron-down"></i>
</div>
</div>
<div class="card-body collapse" id="endpoint-cache-sqlite-status">
<h6 class="fw-bold">Description</h6>
<p>SQLite L2 cache (`networks_cache.db`): country networks from MaxMind scans.</p>
<h6 class="fw-bold mt-3">Response Schema</h6>
<pre><code>{
"success": <span class="text-success">true</span>,
"exists": <span class="text-success">true</span>,
"file_size_mb": <span class="text-info">1439.54</span>,
"total_countries": <span class="text-info">123</span>,
"total_networks": <span class="text-info">13728494</span>,
"top_countries": [
{"code": <span class="text-warning">"US"</span>, "networks": <span class="text-info">5801506</span>}
]
}</code></pre>
<h6 class="fw-bold mt-3">Fields</h6>
<table class="table table-sm">
<thead>
<tr><th>Name</th><th>Type</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><code>exists</code></td><td>boolean</td><td>DB file exists</td></tr>
<tr><td><code>file_size_mb</code></td><td>float</td><td>DB size on disk</td></tr>
<tr><td><code>total_countries</code></td><td>integer</td><td>Countries with cached networks</td></tr>
<tr><td><code>top_countries</code></td><td>array</td><td>Top 5 by network count</td></tr>
</tbody>
</table>
<h6 class="fw-bold mt-3">Try it out</h6>
<button class="btn btn-sm btn-primary" onclick="tryEndpoint('cache/sqlite/status')">
<i class="fas fa-play me-1"></i>Execute
</button>
<!-- ID: response-cache-sqlite-status -->
<div id="response-cache-sqlite-status" class="mt-3" style="display:none;">
<h6 class="fw-bold">Response</h6>
<pre><code id="response-cache-sqlite-status-body"></code></pre>
</div>
</div>
</div>
<!-- Cache Invalidate -->
<div class="card mb-3">
<div class="card-header api-header-post" onclick="toggleEndpoint('endpoint-cache-invalidate')">
<div class="d-flex justify-content-between align-items-center">
<div>
<span class="badge bg-success me-2">POST</span>
<code class="api-path">/api/cache/invalidate/&lt;country_code&gt;</code>
<span class="ms-3 text-muted">Invalidate country cache</span>
</div>
<i class="fas fa-chevron-down"></i>
</div>
</div>
<div class="card-body collapse" id="endpoint-cache-invalidate">
<h6 class="fw-bold">Description</h6>
<p>Clears Redis L1 cache for specific country: networks + all configs containing it. Forces fresh SQLite/MaxMind scan next time.</p>
<h6 class="fw-bold mt-3">Path Parameter</h6>
<table class="table table-sm">
<thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>country_code</code></td><td>string</td><td>ISO 3166-1 alpha-2 (e.g. <code>CN</code>, <code>RU</code>)</td></tr>
</tbody>
</table>
<h6 class="fw-bold mt-3">Response Schema</h6>
<pre><code>{
"success": <span class="text-success">true</span>,
"deleted": <span class="text-info">5</span>,
"country": <span class="text-warning">"CN"</span>,
"details": {
"country_cache": <span class="text-info">1</span>,
"config_caches": <span class="text-info">4</span>
}
}</code></pre>
<h6 class="fw-bold mt-3">What it deletes</h6>
<ul>
<li><code>geoban:country:CN</code> - country networks</li>
<li><code>geoban:config:*[CN]</code> - configs with CN</li>
</ul>
<h6 class="fw-bold mt-3">Try it out</h6>
<p>Enter country code (e.g. <code>CN</code>):
<input type="text" id="invalidateCountry" class="form-control form-control-sm d-inline w-auto" maxlength="2" placeholder="CN">
<button class="btn btn-sm btn-warning ms-2" onclick="tryInvalidateCountry()">
<i class="fas fa-trash me-1"></i>Invalidate
</button>
</p>
<div id="response-cache-invalidate" class="mt-3" style="display:none;">
<h6 class="fw-bold">Response</h6>
<pre><code id="response-cache-invalidate-body"></code></pre>
</div>
<h6 class="fw-bold mt-3">cURL Example</h6>
<pre><code>curl -X POST <span id="curlUrl-invalidate"></span>/api/cache/invalidate/CN</code></pre>
</div>
</div>
<!-- Endpoint 3: Update Database -->
<div class="card mb-3">
<div class="card-header api-header-post" onclick="toggleEndpoint('endpoint3')">