|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class APIClient { |
|
|
constructor(baseURL = '') { |
|
|
this.baseURL = baseURL; |
|
|
this.defaultHeaders = { |
|
|
'Content-Type': 'application/json', |
|
|
}; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async request(endpoint, options = {}) { |
|
|
const url = `${this.baseURL}${endpoint}`; |
|
|
const config = { |
|
|
headers: { ...this.defaultHeaders, ...options.headers }, |
|
|
...options, |
|
|
}; |
|
|
|
|
|
try { |
|
|
const response = await fetch(url, config); |
|
|
|
|
|
if (!response.ok) { |
|
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`); |
|
|
} |
|
|
|
|
|
|
|
|
const contentType = response.headers.get('content-type'); |
|
|
if (contentType && contentType.includes('application/json')) { |
|
|
return await response.json(); |
|
|
} else if (contentType && contentType.includes('text')) { |
|
|
return await response.text(); |
|
|
} |
|
|
|
|
|
return response; |
|
|
} catch (error) { |
|
|
console.error(`[APIClient] Error fetching ${endpoint}:`, error); |
|
|
throw error; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async get(endpoint) { |
|
|
return this.request(endpoint, { method: 'GET' }); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async post(endpoint, data) { |
|
|
return this.request(endpoint, { |
|
|
method: 'POST', |
|
|
body: JSON.stringify(data), |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async put(endpoint, data) { |
|
|
return this.request(endpoint, { |
|
|
method: 'PUT', |
|
|
body: JSON.stringify(data), |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async delete(endpoint) { |
|
|
return this.request(endpoint, { method: 'DELETE' }); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getHealth() { |
|
|
return this.get('/api/health'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getStatus() { |
|
|
return this.get('/api/status'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getStats() { |
|
|
return this.get('/api/stats'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getInfo() { |
|
|
return this.get('/api/info'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getMarket() { |
|
|
return this.get('/api/market'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getTrending() { |
|
|
return this.get('/api/trending'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getSentiment() { |
|
|
return this.get('/api/sentiment'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getDefi() { |
|
|
return this.get('/api/defi'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getProviders() { |
|
|
return this.get('/api/providers'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getProvider(providerId) { |
|
|
return this.get(`/api/providers/${providerId}`); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getProvidersByCategory(category) { |
|
|
return this.get(`/api/providers/category/${category}`); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async checkProviderHealth(providerId) { |
|
|
return this.post(`/api/providers/${providerId}/health-check`); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async addProvider(providerData) { |
|
|
return this.post('/api/providers', providerData); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async removeProvider(providerId) { |
|
|
return this.delete(`/api/providers/${providerId}`); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getPools() { |
|
|
return this.get('/api/pools'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getPool(poolId) { |
|
|
return this.get(`/api/pools/${poolId}`); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async createPool(poolData) { |
|
|
return this.post('/api/pools', poolData); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async deletePool(poolId) { |
|
|
return this.delete(`/api/pools/${poolId}`); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async addPoolMember(poolId, providerId) { |
|
|
return this.post(`/api/pools/${poolId}/members`, { provider_id: providerId }); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async removePoolMember(poolId, providerId) { |
|
|
return this.delete(`/api/pools/${poolId}/members/${providerId}`); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async rotatePool(poolId) { |
|
|
return this.post(`/api/pools/${poolId}/rotate`); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getPoolHistory() { |
|
|
return this.get('/api/pools/history'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getLogs(params = {}) { |
|
|
const query = new URLSearchParams(params).toString(); |
|
|
return this.get(`/api/logs${query ? '?' + query : ''}`); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getRecentLogs() { |
|
|
return this.get('/api/logs/recent'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getErrorLogs() { |
|
|
return this.get('/api/logs/errors'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getLogStats() { |
|
|
return this.get('/api/logs/stats'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async exportLogsJSON() { |
|
|
return this.get('/api/logs/export/json'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async exportLogsCSV() { |
|
|
return this.get('/api/logs/export/csv'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clearLogs() { |
|
|
return this.delete('/api/logs'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getResources() { |
|
|
return this.get('/api/resources'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getResourcesByCategory(category) { |
|
|
return this.get(`/api/resources/category/${category}`); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async importResourcesJSON(data) { |
|
|
return this.post('/api/resources/import/json', data); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async exportResourcesJSON() { |
|
|
return this.get('/api/resources/export/json'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async exportResourcesCSV() { |
|
|
return this.get('/api/resources/export/csv'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async backupResources() { |
|
|
return this.post('/api/resources/backup'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async addResourceProvider(providerData) { |
|
|
return this.post('/api/resources/provider', providerData); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async deleteResourceProvider(providerId) { |
|
|
return this.delete(`/api/resources/provider/${providerId}`); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getDiscoveryStatus() { |
|
|
return this.get('/api/resources/discovery/status'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async runDiscovery() { |
|
|
return this.post('/api/resources/discovery/run'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getHFHealth() { |
|
|
return this.get('/api/hf/health'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async runHFSentiment(data) { |
|
|
return this.post('/api/hf/run-sentiment', data); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getDiscoveryReport() { |
|
|
return this.get('/api/reports/discovery'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getModelsReport() { |
|
|
return this.get('/api/reports/models'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async runDiagnostics() { |
|
|
return this.post('/api/diagnostics/run'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getLastDiagnostics() { |
|
|
return this.get('/api/diagnostics/last'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getSessions() { |
|
|
return this.get('/api/sessions'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getSessionStats() { |
|
|
return this.get('/api/sessions/stats'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async broadcast(message) { |
|
|
return this.post('/api/broadcast', { message }); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getFeatureFlags() { |
|
|
return this.get('/api/feature-flags'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getFeatureFlag(flagName) { |
|
|
return this.get(`/api/feature-flags/${flagName}`); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async updateFeatureFlags(flags) { |
|
|
return this.put('/api/feature-flags', { flags }); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async updateFeatureFlag(flagName, value) { |
|
|
return this.put(`/api/feature-flags/${flagName}`, { flag_name: flagName, value }); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async resetFeatureFlags() { |
|
|
return this.post('/api/feature-flags/reset'); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getProxyStatus() { |
|
|
return this.get('/api/proxy-status'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
window.apiClient = new APIClient(); |
|
|
|
|
|
console.log('[APIClient] Initialized'); |
|
|
|