mirror of
https://github.com/praveentcom/openproxy.git
synced 2026-07-25 21:31:13 +02:00
refactor: use Number.parseInt/Number.isNaN for numeric parsing across API and UI
Co-authored-by: Genie <genie@cosine.sh>
This commit is contained in:
committed by
Genie
parent
01737528aa
commit
beb4ce46f1
@@ -11,12 +11,12 @@ export async function GET(request: NextRequest) {
|
|||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
|
|
||||||
// Validate and sanitize hours parameter
|
// Validate and sanitize hours parameter
|
||||||
const hoursParam = parseInt(searchParams.get('hours') || '24', 10);
|
const hoursParam = Number.parseInt(searchParams.get('hours') || '24', 10);
|
||||||
const hours = !isNaN(hoursParam) && hoursParam > 0 && hoursParam <= 720 ? hoursParam : 24;
|
const hours = !Number.isNaN(hoursParam) && hoursParam > 0 && hoursParam <= 720 ? hoursParam : 24;
|
||||||
|
|
||||||
// Validate and sanitize limit parameter
|
// Validate and sanitize limit parameter
|
||||||
const limitParam = parseInt(searchParams.get('limit') || '100', 10);
|
const limitParam = Number.parseInt(searchParams.get('limit') || '100', 10);
|
||||||
const limit = !isNaN(limitParam) && limitParam > 0 && limitParam <= 1000 ? limitParam : 100;
|
const limit = !Number.isNaN(limitParam) && limitParam > 0 && limitParam <= 1000 ? limitParam : 100;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const client = await pool.connect();
|
const client = await pool.connect();
|
||||||
@@ -95,11 +95,11 @@ export async function GET(request: NextRequest) {
|
|||||||
success: true,
|
success: true,
|
||||||
data: {
|
data: {
|
||||||
summary: {
|
summary: {
|
||||||
totalRequests: parseInt(summary.total_requests ?? '0'),
|
totalRequests: Number.parseInt(summary.total_requests ?? '0'),
|
||||||
totalTokens: parseInt(summary.total_tokens_used ?? '0'),
|
totalTokens: Number.parseInt(summary.total_tokens_used ?? '0'),
|
||||||
totalCost: parseFloat(summary.total_cost ?? '0'),
|
totalCost: parseFloat(summary.total_cost ?? '0'),
|
||||||
avgResponseTime: parseFloat(summary.avg_response_time ?? '0'),
|
avgResponseTime: parseFloat(summary.avg_response_time ?? '0'),
|
||||||
uniqueModels: parseInt(summary.unique_models ?? '0'),
|
uniqueModels: Number.parseInt(summary),
|
||||||
uniqueClients: parseInt(summary.unique_clients ?? '0'),
|
uniqueClients: parseInt(summary.unique_clients ?? '0'),
|
||||||
},
|
},
|
||||||
recentRequests,
|
recentRequests,
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ export default function Dashboard() {
|
|||||||
<div style={styles.controls}>
|
<div style={styles.controls}>
|
||||||
<select
|
<select
|
||||||
value={timeRange}
|
value={timeRange}
|
||||||
onChange={(e) => setTimeRange(parseInt(e.target.value))}
|
onChange={(e) => setTimeRange(Number.parseInt(e.target.value))}
|
||||||
style={styles.select}
|
style={styles.select}
|
||||||
>
|
>
|
||||||
<option value={1}>Last Hour</option>
|
<option value={1}>Last Hour</option>
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ export default function ModelBreakdown({ models }: ModelBreakdownProps) {
|
|||||||
<td style={styles.td}>
|
<td style={styles.td}>
|
||||||
<strong>{model.model}</strong>
|
<strong>{model.model}</strong>
|
||||||
</td>
|
</td>
|
||||||
<td style={styles.td}>{parseInt(model.request_count).toLocaleString()}</td>
|
<td style={styles.td}>{Number.parseInt(model.request_count).toLocaleString()}</td>
|
||||||
<td style={styles.td}>{parseInt(model.total_tokens).toLocaleString()}</td>
|
<td style={styles.td}>{Number.parseInt(model.total_tokens).toLocaleString()}</td>
|
||||||
<td style={styles.td}>${parseFloat(model.total_cost).toFixed(4)}</td>
|
<td style={styles.td}>${parseFloat(model.total_cost).toFixed(4)}</td>
|
||||||
<td style={styles.td}>{Math.round(parseFloat(model.avg_response_time))}ms</td>
|
<td style={styles.td}>{Math.round(parseFloat(model.avg_response_time))}ms</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ export default function TrendsChart({ trends }: TrendsChartProps) {
|
|||||||
day: 'numeric',
|
day: 'numeric',
|
||||||
hour: '2-digit',
|
hour: '2-digit',
|
||||||
}),
|
}),
|
||||||
requests: parseInt(trend.requests),
|
requests: Number.parseInt(trend.requests),
|
||||||
tokens: parseInt(trend.tokens),
|
tokens: Number.parseInt(trend.tokens),
|
||||||
cost: parseFloat(trend.cost),
|
cost: parseFloat(trend.cost),
|
||||||
responseTime: Math.round(parseFloat(trend.avg_response_time)),
|
responseTime: Math.round(parseFloat(trend.avg_response_time)),
|
||||||
}));
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user