feat: firmware registry view

This commit is contained in:
2025-10-21 17:51:22 +02:00
parent aa7467e1ca
commit 7def7bce81
10 changed files with 2287 additions and 1028 deletions

View File

@@ -136,6 +136,98 @@ class ApiClient {
}
});
}
// Registry API methods
async getRegistryBaseUrl() {
// Auto-detect registry server URL based on current location
const currentHost = window.location.hostname;
// If accessing from localhost, use localhost:8080
// If accessing from another device, use the same hostname but port 8080
if (currentHost === 'localhost' || currentHost === '127.0.0.1') {
return 'http://localhost:8080';
} else {
return `http://${currentHost}:8080`;
}
}
async uploadFirmwareToRegistry(metadata, firmwareFile) {
const registryBaseUrl = await this.getRegistryBaseUrl();
const formData = new FormData();
formData.append('metadata', JSON.stringify(metadata));
formData.append('firmware', firmwareFile);
const response = await fetch(`${registryBaseUrl}/firmware`, {
method: 'POST',
body: formData
});
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Registry upload failed: ${errorText}`);
}
return await response.json();
}
async updateFirmwareMetadata(name, version, metadata) {
const registryBaseUrl = await this.getRegistryBaseUrl();
const response = await fetch(`${registryBaseUrl}/firmware/${encodeURIComponent(name)}/${encodeURIComponent(version)}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(metadata)
});
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Registry metadata update failed: ${errorText}`);
}
return await response.json();
}
async listFirmwareFromRegistry(name = null, version = null) {
const registryBaseUrl = await this.getRegistryBaseUrl();
const query = {};
if (name) query.name = name;
if (version) query.version = version;
const response = await fetch(`${registryBaseUrl}/firmware${Object.keys(query).length ? '?' + new URLSearchParams(query).toString() : ''}`);
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Registry list failed: ${errorText}`);
}
return await response.json();
}
async downloadFirmwareFromRegistry(name, version) {
const registryBaseUrl = await this.getRegistryBaseUrl();
const response = await fetch(`${registryBaseUrl}/firmware/${encodeURIComponent(name)}/${encodeURIComponent(version)}`);
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Registry download failed: ${errorText}`);
}
return response.blob();
}
async getRegistryHealth() {
const registryBaseUrl = await this.getRegistryBaseUrl();
const response = await fetch(`${registryBaseUrl}/health`);
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Registry health check failed: ${errorText}`);
}
return await response.json();
}
}
// Global API client instance