feat: add monthly quota to API response body
Add monthlyQuotaRemaining/monthlyQuotaLimit fields to QRResponseDto populated from X-Quota-* headers set by rate limiter. MCP server now displays quota in tool result text instead of web credits. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
1eb1a3207c
commit
4570e9b70b
@ -114,6 +114,14 @@ namespace QRRapidoApp.Controllers
|
||||
};
|
||||
}
|
||||
|
||||
// Inject monthly quota from response headers (set by ApiKeyAuthorizeAttribute)
|
||||
if (HttpContext.Response.Headers.TryGetValue("X-Quota-Remaining", out var qr) &&
|
||||
int.TryParse(qr, out var quotaRemaining))
|
||||
result.MonthlyQuotaRemaining = quotaRemaining;
|
||||
if (HttpContext.Response.Headers.TryGetValue("X-Quota-Limit", out var ql) &&
|
||||
int.TryParse(ql, out var quotaLimit))
|
||||
result.MonthlyQuotaLimit = quotaLimit;
|
||||
|
||||
// Map format and mimeType into the response
|
||||
result.Format = format;
|
||||
result.MimeType = format switch
|
||||
|
||||
@ -18,5 +18,11 @@ namespace QRRapidoApp.Models.DTOs
|
||||
|
||||
/// <summary>MIME type of the encoded image (e.g. "image/png", "image/webp").</summary>
|
||||
public string MimeType { get; set; } = "image/png";
|
||||
|
||||
/// <summary>Monthly API quota remaining (from rate limiter). -1 = unlimited.</summary>
|
||||
public int MonthlyQuotaRemaining { get; set; } = -1;
|
||||
|
||||
/// <summary>Monthly API quota limit. -1 = unlimited.</summary>
|
||||
public int MonthlyQuotaLimit { get; set; } = -1;
|
||||
}
|
||||
}
|
||||
@ -109,7 +109,9 @@ function successContent(data, label = "qr") {
|
||||
file ? `🖼 Aberto em: ${file}` : "",
|
||||
`⏱ ${data.generationTimeMs}ms`,
|
||||
`💾 Cache: ${data.fromCache ? "hit" : "miss"}`,
|
||||
`📊 Créditos restantes: ${data.remainingCredits ?? "N/A"}`
|
||||
data.monthlyQuotaLimit >= 0
|
||||
? `📊 Quota mensal: ${data.monthlyQuotaRemaining}/${data.monthlyQuotaLimit}`
|
||||
: `📊 Quota mensal: ilimitada`
|
||||
].filter(Boolean).join("\n")
|
||||
}
|
||||
]
|
||||
|
||||
@ -164,7 +164,7 @@ function createMcpServer(apiKey) {
|
||||
return {
|
||||
content: [
|
||||
{ type: "image", data: data.qrCodeBase64, mimeType: data.mimeType || "image/png" },
|
||||
{ type: "text", text: `✅ QR gerado (${type})\n⏱ ${data.generationTimeMs}ms\n💾 cache: ${data.fromCache ? "hit" : "miss"}` }
|
||||
{ type: "text", text: `✅ QR gerado (${type})\n⏱ ${data.generationTimeMs}ms\n💾 cache: ${data.fromCache ? "hit" : "miss"}\n📊 quota: ${data.monthlyQuotaRemaining >= 0 ? `${data.monthlyQuotaRemaining}/${data.monthlyQuotaLimit}` : "ilimitada"}` }
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user