feat(token): add batch API for fetching token keys
Add new endpoint POST /api/token/batch/keys to fetch multiple token keys in a single request, improving performance when exporting or copying multiple tokens. - Backend: Add GetTokenKeysBatch controller and GetTokenKeysByIds model - Backend: Add route with CriticalRateLimit and DisableCache middleware - Frontend: Add fetchTokenKeysBatch helper function - Frontend: Update useTokensData to use batch API for token export
This commit is contained in:
Vendored
+14
@@ -33,6 +33,20 @@ export async function fetchTokenKey(tokenId) {
|
||||
return data.key;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量获取多个令牌的真实 key
|
||||
* @param {number[]} tokenIds
|
||||
* @returns {Promise<Record<number, string>>} 返回 {id: key} map,key 不带 sk- 前缀
|
||||
*/
|
||||
export async function fetchTokenKeysBatch(tokenIds) {
|
||||
const response = await API.post('/api/token/batch/keys', { ids: tokenIds });
|
||||
const { success, data, message } = response.data || {};
|
||||
if (!success || !data?.keys) {
|
||||
throw new Error(message || 'Failed to fetch token keys');
|
||||
}
|
||||
return data.keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取可用的 token keys
|
||||
* @returns {Promise<string[]>} 返回 active 状态的不带 sk- 前缀的真实 token key 数组
|
||||
|
||||
Reference in New Issue
Block a user