2026-02-28 00:07:44 +08:00
|
|
|
/**
|
|
|
|
|
* Admin API Keys API endpoints
|
|
|
|
|
* Handles API key management for administrators
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { apiClient } from '../client'
|
|
|
|
|
import type { ApiKey } from '@/types'
|
|
|
|
|
|
2026-02-28 17:33:30 +08:00
|
|
|
export interface UpdateApiKeyGroupResult {
|
|
|
|
|
api_key: ApiKey
|
|
|
|
|
auto_granted_group_access: boolean
|
|
|
|
|
granted_group_id?: number
|
|
|
|
|
granted_group_name?: string
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-28 00:07:44 +08:00
|
|
|
/**
|
|
|
|
|
* Update an API key's group binding
|
|
|
|
|
* @param id - API Key ID
|
|
|
|
|
* @param groupId - Group ID (0 to unbind, positive to bind, null/undefined to skip)
|
2026-02-28 17:33:30 +08:00
|
|
|
* @returns Updated API key with auto-grant info
|
2026-02-28 00:07:44 +08:00
|
|
|
*/
|
2026-02-28 17:33:30 +08:00
|
|
|
export async function updateApiKeyGroup(id: number, groupId: number | null): Promise<UpdateApiKeyGroupResult> {
|
|
|
|
|
const { data } = await apiClient.put<UpdateApiKeyGroupResult>(`/admin/api-keys/${id}`, {
|
2026-02-28 00:07:44 +08:00
|
|
|
group_id: groupId === null ? 0 : groupId
|
|
|
|
|
})
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const apiKeysAPI = {
|
|
|
|
|
updateApiKeyGroup
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default apiKeysAPI
|