mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-18 02:30:51 +08:00
refactor: centralize usage stats and refine api key cache
This commit is contained in:
@@ -271,7 +271,7 @@ export const apiKeysModule = {
|
||||
body: JSON.stringify(currentKeys)
|
||||
});
|
||||
|
||||
this.clearCache(); // 清除缓存
|
||||
this.clearCache('api-keys'); // 仅清除 api-keys 段缓存
|
||||
this.closeModal();
|
||||
this.loadApiKeys();
|
||||
this.showNotification(i18n.t('notification.api_key_added'), 'success');
|
||||
@@ -315,7 +315,7 @@ export const apiKeysModule = {
|
||||
body: JSON.stringify({ index, value: newKey })
|
||||
});
|
||||
|
||||
this.clearCache(); // 清除缓存
|
||||
this.clearCache('api-keys'); // 仅清除 api-keys 段缓存
|
||||
this.closeModal();
|
||||
this.loadApiKeys();
|
||||
this.showNotification(i18n.t('notification.api_key_updated'), 'success');
|
||||
@@ -330,7 +330,7 @@ export const apiKeysModule = {
|
||||
|
||||
try {
|
||||
await this.makeRequest(`/api-keys?index=${index}`, { method: 'DELETE' });
|
||||
this.clearCache(); // 清除缓存
|
||||
this.clearCache('api-keys'); // 仅清除 api-keys 段缓存
|
||||
this.loadApiKeys();
|
||||
this.showNotification(i18n.t('notification.api_key_deleted'), 'success');
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
// 获取API密钥的统计信息
|
||||
export async function getKeyStats() {
|
||||
export async function getKeyStats(usageData = null) {
|
||||
try {
|
||||
const response = await this.makeRequest('/usage');
|
||||
const usage = response?.usage || null;
|
||||
|
||||
let usage = usageData;
|
||||
if (!usage) {
|
||||
const response = await this.makeRequest('/usage');
|
||||
usage = response?.usage || null;
|
||||
}
|
||||
|
||||
if (!usage) {
|
||||
return {};
|
||||
}
|
||||
@@ -20,7 +23,7 @@ export async function getKeyStats() {
|
||||
details.forEach(detail => {
|
||||
const source = detail.source;
|
||||
if (!source) return;
|
||||
|
||||
|
||||
if (!sourceStats[source]) {
|
||||
sourceStats[source] = {
|
||||
success: 0,
|
||||
|
||||
Reference in New Issue
Block a user