✨ Features: - Backend FastAPI complete (25 Python files) - 5 SQLAlchemy models (Device, HardwareSnapshot, Benchmark, Link, Document) - Pydantic schemas for validation - 4 API routers (benchmark, devices, links, docs) - Authentication with Bearer token - Automatic score calculation - File upload support - Frontend web interface (13 files) - 4 HTML pages (Dashboard, Devices, Device Detail, Settings) - 7 JavaScript modules - Monokai dark theme CSS - Responsive design - Complete CRUD operations - Client benchmark script (500+ lines Bash) - Hardware auto-detection - CPU, RAM, Disk, Network benchmarks - JSON payload generation - Robust error handling - Docker deployment - Optimized Dockerfile - docker-compose with 2 services - Persistent volumes - Environment variables - Documentation & Installation - Automated install.sh script - README, QUICKSTART, DEPLOYMENT guides - Complete API documentation - Project structure documentation 📊 Stats: - ~60 files created - ~5000 lines of code - Full MVP feature set implemented 🚀 Ready for production deployment! 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
198 lines
4.6 KiB
JavaScript
198 lines
4.6 KiB
JavaScript
// Linux BenchTools - API Client
|
|
|
|
const API_BASE_URL = window.location.protocol + '//' + window.location.hostname + ':8007/api';
|
|
|
|
class BenchAPI {
|
|
constructor(baseURL = API_BASE_URL) {
|
|
this.baseURL = baseURL;
|
|
}
|
|
|
|
// Generic request handler
|
|
async request(endpoint, options = {}) {
|
|
const url = `${this.baseURL}${endpoint}`;
|
|
|
|
try {
|
|
const response = await fetch(url, {
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
...options.headers
|
|
},
|
|
...options
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const errorData = await response.json().catch(() => ({}));
|
|
throw new Error(errorData.detail || `HTTP ${response.status}: ${response.statusText}`);
|
|
}
|
|
|
|
// Handle 204 No Content
|
|
if (response.status === 204) {
|
|
return null;
|
|
}
|
|
|
|
return await response.json();
|
|
} catch (error) {
|
|
console.error(`API Error [${endpoint}]:`, error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
// GET request
|
|
async get(endpoint, params = {}) {
|
|
const queryString = new URLSearchParams(params).toString();
|
|
const url = queryString ? `${endpoint}?${queryString}` : endpoint;
|
|
return this.request(url, { method: 'GET' });
|
|
}
|
|
|
|
// POST request
|
|
async post(endpoint, data) {
|
|
return this.request(endpoint, {
|
|
method: 'POST',
|
|
body: JSON.stringify(data)
|
|
});
|
|
}
|
|
|
|
// PUT request
|
|
async put(endpoint, data) {
|
|
return this.request(endpoint, {
|
|
method: 'PUT',
|
|
body: JSON.stringify(data)
|
|
});
|
|
}
|
|
|
|
// DELETE request
|
|
async delete(endpoint) {
|
|
return this.request(endpoint, { method: 'DELETE' });
|
|
}
|
|
|
|
// Upload file
|
|
async upload(endpoint, formData) {
|
|
const url = `${this.baseURL}${endpoint}`;
|
|
|
|
try {
|
|
const response = await fetch(url, {
|
|
method: 'POST',
|
|
body: formData
|
|
// Don't set Content-Type header, let browser set it with boundary
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const errorData = await response.json().catch(() => ({}));
|
|
throw new Error(errorData.detail || `HTTP ${response.status}: ${response.statusText}`);
|
|
}
|
|
|
|
return await response.json();
|
|
} catch (error) {
|
|
console.error(`Upload Error [${endpoint}]:`, error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
// ==================== Devices ====================
|
|
|
|
// Get all devices
|
|
async getDevices(params = {}) {
|
|
return this.get('/devices', params);
|
|
}
|
|
|
|
// Get device by ID
|
|
async getDevice(deviceId) {
|
|
return this.get(`/devices/${deviceId}`);
|
|
}
|
|
|
|
// Update device
|
|
async updateDevice(deviceId, data) {
|
|
return this.put(`/devices/${deviceId}`, data);
|
|
}
|
|
|
|
// Delete device
|
|
async deleteDevice(deviceId) {
|
|
return this.delete(`/devices/${deviceId}`);
|
|
}
|
|
|
|
// ==================== Benchmarks ====================
|
|
|
|
// Get benchmarks for a device
|
|
async getDeviceBenchmarks(deviceId, params = {}) {
|
|
return this.get(`/devices/${deviceId}/benchmarks`, params);
|
|
}
|
|
|
|
// Get benchmark by ID
|
|
async getBenchmark(benchmarkId) {
|
|
return this.get(`/benchmarks/${benchmarkId}`);
|
|
}
|
|
|
|
// Get all benchmarks
|
|
async getAllBenchmarks(params = {}) {
|
|
return this.get('/benchmarks', params);
|
|
}
|
|
|
|
// ==================== Links ====================
|
|
|
|
// Get links for a device
|
|
async getDeviceLinks(deviceId) {
|
|
return this.get(`/devices/${deviceId}/links`);
|
|
}
|
|
|
|
// Add link to device
|
|
async addDeviceLink(deviceId, data) {
|
|
return this.post(`/devices/${deviceId}/links`, data);
|
|
}
|
|
|
|
// Update link
|
|
async updateLink(linkId, data) {
|
|
return this.put(`/links/${linkId}`, data);
|
|
}
|
|
|
|
// Delete link
|
|
async deleteLink(linkId) {
|
|
return this.delete(`/links/${linkId}`);
|
|
}
|
|
|
|
// ==================== Documents ====================
|
|
|
|
// Get documents for a device
|
|
async getDeviceDocs(deviceId) {
|
|
return this.get(`/devices/${deviceId}/docs`);
|
|
}
|
|
|
|
// Upload document
|
|
async uploadDocument(deviceId, file, docType) {
|
|
const formData = new FormData();
|
|
formData.append('file', file);
|
|
formData.append('doc_type', docType);
|
|
|
|
return this.upload(`/devices/${deviceId}/docs`, formData);
|
|
}
|
|
|
|
// Delete document
|
|
async deleteDocument(docId) {
|
|
return this.delete(`/docs/${docId}`);
|
|
}
|
|
|
|
// Get document download URL
|
|
getDocumentDownloadUrl(docId) {
|
|
return `${this.baseURL}/docs/${docId}/download`;
|
|
}
|
|
|
|
// ==================== Health ====================
|
|
|
|
// Health check
|
|
async healthCheck() {
|
|
return this.get('/health');
|
|
}
|
|
|
|
// ==================== Stats ====================
|
|
|
|
// Get dashboard stats
|
|
async getStats() {
|
|
return this.get('/stats');
|
|
}
|
|
}
|
|
|
|
// Create global API instance
|
|
const api = new BenchAPI();
|
|
|
|
// Export for use in other files
|
|
window.BenchAPI = api;
|