ISOs need version AND schema

This commit is contained in:
2025-11-08 22:24:46 +00:00
parent dfc7694fb9
commit ee63423cab
5 changed files with 116 additions and 117 deletions

View File

@@ -11,19 +11,17 @@ import {
BookOpen, BookOpen,
ExternalLink, ExternalLink,
CheckCircle, CheckCircle,
XCircle,
Usb, Usb,
ArrowLeft, ArrowLeft,
CloudLightning, CloudLightning,
} from 'lucide-react'; } from 'lucide-react';
import { useAssetList, useDownloadAsset, useAssetStatus } from '../../services/api/hooks/useAssets'; import { useAssetList, useDownloadAsset, useAssetStatus } from '../../services/api/hooks/useAssets';
import { assetsApi } from '../../services/api/assets'; import { assetsApi } from '../../services/api/assets';
import type { AssetType } from '../../services/api/types/asset';
export function AssetsIsoPage() { export function AssetsIsoPage() {
const { data, isLoading, error } = useAssetList(); const { data, isLoading, error } = useAssetList();
const downloadAsset = useDownloadAsset(); const downloadAsset = useDownloadAsset();
const [selectedSchematicId, setSelectedSchematicId] = useState<string | null>(null); const [selectedSchematicId] = useState<string | null>(null);
const [selectedVersion, setSelectedVersion] = useState('v1.8.0'); const [selectedVersion, setSelectedVersion] = useState('v1.8.0');
const { data: statusData } = useAssetStatus(selectedSchematicId); const { data: statusData } = useAssetStatus(selectedSchematicId);

View File

@@ -15,22 +15,20 @@ import {
} from 'lucide-react'; } from 'lucide-react';
import { useAssetList, useDownloadAsset, useDeleteAsset } from '../../services/api/hooks/useAssets'; import { useAssetList, useDownloadAsset, useDeleteAsset } from '../../services/api/hooks/useAssets';
import { assetsApi } from '../../services/api/assets'; import { assetsApi } from '../../services/api/assets';
import type { Platform } from '../../services/api/types/asset'; import type { Platform, Asset } from '../../services/api/types/asset';
// Helper function to extract version from ISO filename // Helper function to extract platform from filename
// Filename format: talos-v1.11.2-metal-amd64.iso // Filename format: metal-amd64.iso
function extractVersionFromPath(path: string): string { function extractPlatformFromPath(path: string): string {
const filename = path.split('/').pop() || ''; const filename = path.split('/').pop() || '';
const match = filename.match(/talos-(v\d+\.\d+\.\d+)-metal/); const match = filename.match(/-(amd64|arm64)\./);
return match ? match[1] : 'unknown'; return match ? match[1] : 'unknown';
} }
// Helper function to extract platform from ISO filename // Type for ISO asset with schematic and version info
// Filename format: talos-v1.11.2-metal-amd64.iso interface IsoAssetWithMetadata extends Asset {
function extractPlatformFromPath(path: string): string { schematic_id: string;
const filename = path.split('/').pop() || ''; version: string;
const match = filename.match(/-(amd64|arm64)\.iso$/);
return match ? match[1] : 'unknown';
} }
export function IsoPage() { export function IsoPage() {
@@ -38,8 +36,8 @@ export function IsoPage() {
const downloadAsset = useDownloadAsset(); const downloadAsset = useDownloadAsset();
const deleteAsset = useDeleteAsset(); const deleteAsset = useDeleteAsset();
const [schematicId, setSchematicId] = useState(''); const [schematicId, setSchematicId] = useState('434a0300db532066f1098e05ac068159371d00f0aba0a3103a0e826e83825c82');
const [selectedVersion, setSelectedVersion] = useState('v1.11.2'); const [selectedVersion, setSelectedVersion] = useState('v1.11.5');
const [selectedPlatform, setSelectedPlatform] = useState<Platform>('amd64'); const [selectedPlatform, setSelectedPlatform] = useState<Platform>('amd64');
const [isDownloading, setIsDownloading] = useState(false); const [isDownloading, setIsDownloading] = useState(false);
@@ -53,10 +51,10 @@ export function IsoPage() {
try { try {
await downloadAsset.mutateAsync({ await downloadAsset.mutateAsync({
schematicId, schematicId,
request: {
version: selectedVersion, version: selectedVersion,
request: {
platform: selectedPlatform, platform: selectedPlatform,
assets: ['iso'] asset_types: ['iso']
}, },
}); });
// Refresh the list after download // Refresh the list after download
@@ -69,13 +67,13 @@ export function IsoPage() {
} }
}; };
const handleDelete = async (schematicIdToDelete: string) => { const handleDelete = async (schematicIdToDelete: string, versionToDelete: string) => {
if (!confirm('Are you sure you want to delete this schematic and all its assets? This action cannot be undone.')) { if (!confirm(`Are you sure you want to delete ${schematicIdToDelete}@${versionToDelete} and all its assets? This action cannot be undone.`)) {
return; return;
} }
try { try {
await deleteAsset.mutateAsync(schematicIdToDelete); await deleteAsset.mutateAsync({ schematicId: schematicIdToDelete, version: versionToDelete });
await refetch(); await refetch();
} catch (err) { } catch (err) {
console.error('Delete failed:', err); console.error('Delete failed:', err);
@@ -83,15 +81,14 @@ export function IsoPage() {
} }
}; };
// Find all ISO assets from all schematics (including multiple ISOs per schematic) // Find all ISO assets from all assets (schematic@version combinations)
const isoAssets = data?.schematics const isoAssets = data?.assets?.flatMap(asset => {
.flatMap(schematic => { // Get ALL ISO assets for this schematic@version
// Get ALL ISO assets for this schematic (not just the first one) const isoAssetsForAsset = asset.assets.filter(a => a.type === 'iso');
const isoAssetsForSchematic = schematic.assets.filter(asset => asset.type === 'iso'); return isoAssetsForAsset.map(isoAsset => ({
return isoAssetsForSchematic.map(isoAsset => ({
...isoAsset, ...isoAsset,
schematic_id: schematic.schematic_id, schematic_id: asset.schematic_id,
version: schematic.version version: asset.version
})); }));
}) || []; }) || [];
@@ -146,46 +143,6 @@ export function IsoPage() {
</div> </div>
</CardHeader> </CardHeader>
<CardContent className="space-y-4"> <CardContent className="space-y-4">
{/* Schematic ID Input */}
<div>
<label className="text-sm font-medium mb-2 block">
Schematic ID
<span className="text-muted-foreground ml-2">(64-character hex string)</span>
</label>
<input
type="text"
value={schematicId}
onChange={(e) => setSchematicId(e.target.value)}
placeholder="e.g., 434a0300db532066f1098e05ac068159371d00f0aba0a3103a0e826e83825c82"
className="w-full px-3 py-2 border rounded-lg bg-background font-mono text-sm"
/>
<p className="text-xs text-muted-foreground mt-1">
Get your schematic ID from the{' '}
<a
href="https://factory.talos.dev"
target="_blank"
rel="noopener noreferrer"
className="text-primary hover:underline"
>
Talos Image Factory
</a>
</p>
</div>
{/* Version Selection */}
<div>
<label className="text-sm font-medium mb-2 block">Talos Version</label>
<select
value={selectedVersion}
onChange={(e) => setSelectedVersion(e.target.value)}
className="w-full md:w-64 px-3 py-2 border rounded-lg bg-background"
>
<option value="v1.11.2">v1.11.2</option>
<option value="v1.11.1">v1.11.1</option>
<option value="v1.11.0">v1.11.0</option>
</select>
</div>
{/* Platform Selection */} {/* Platform Selection */}
<div> <div>
<label className="text-sm font-medium mb-2 block">Platform</label> <label className="text-sm font-medium mb-2 block">Platform</label>
@@ -215,6 +172,49 @@ export function IsoPage() {
</div> </div>
</div> </div>
{/* Version Selection */}
<div>
<label className="text-sm font-medium mb-2 block">Talos Version</label>
<select
value={selectedVersion}
onChange={(e) => setSelectedVersion(e.target.value)}
className="w-full md:w-64 px-3 py-2 border rounded-lg bg-background"
>
<option value="v1.11.5">v1.11.5</option>
<option value="v1.11.4">v1.11.4</option>
<option value="v1.11.3">v1.11.3</option>
<option value="v1.11.2">v1.11.2</option>
<option value="v1.11.1">v1.11.1</option>
<option value="v1.11.0">v1.11.0</option>
</select>
</div>
{/* Schematic ID Input */}
<div>
<label className="text-sm font-medium mb-2 block">
Schematic ID
<span className="text-muted-foreground ml-2">(64-character hex string)</span>
</label>
<input
type="text"
value={schematicId}
onChange={(e) => setSchematicId(e.target.value)}
placeholder="e.g., 434a0300db532066f1098e05ac068159371d00f0aba0a3103a0e826e83825c82"
className="w-full px-3 py-2 border rounded-lg bg-background font-mono text-sm"
/>
<p className="text-xs text-muted-foreground mt-1">
Get your schematic ID from the{' '}
<a
href="https://factory.talos.dev"
target="_blank"
rel="noopener noreferrer"
className="text-primary hover:underline"
>
Talos Image Factory
</a>
</p>
</div>
{/* Download Button */} {/* Download Button */}
<Button <Button
onClick={handleDownload} onClick={handleDownload}
@@ -264,11 +264,12 @@ export function IsoPage() {
</div> </div>
) : ( ) : (
<div className="space-y-3"> <div className="space-y-3">
{isoAssets.map((asset: any) => { {isoAssets.map((asset: IsoAssetWithMetadata) => {
const version = extractVersionFromPath(asset.path || '');
const platform = extractPlatformFromPath(asset.path || ''); const platform = extractPlatformFromPath(asset.path || '');
// Use composite key for React key
const compositeKey = `${asset.schematic_id}@${asset.version}`;
return ( return (
<Card key={asset.schematic_id} className="p-4"> <Card key={compositeKey} className="p-4">
<div className="flex items-center gap-4"> <div className="flex items-center gap-4">
<div className="p-2 bg-muted rounded-lg"> <div className="p-2 bg-muted rounded-lg">
<Disc className="h-5 w-5 text-primary" /> <Disc className="h-5 w-5 text-primary" />
@@ -276,7 +277,7 @@ export function IsoPage() {
<div className="flex-1"> <div className="flex-1">
<div className="flex items-center gap-2 mb-1"> <div className="flex items-center gap-2 mb-1">
<h5 className="font-medium">Talos ISO</h5> <h5 className="font-medium">Talos ISO</h5>
<Badge variant="outline">{version}</Badge> <Badge variant="outline">{asset.version}</Badge>
<Badge variant="outline" className="uppercase">{platform}</Badge> <Badge variant="outline" className="uppercase">{platform}</Badge>
{asset.downloaded ? ( {asset.downloaded ? (
<Badge variant="success" className="flex items-center gap-1"> <Badge variant="success" className="flex items-center gap-1">
@@ -292,7 +293,7 @@ export function IsoPage() {
</div> </div>
<div className="text-sm text-muted-foreground space-y-1"> <div className="text-sm text-muted-foreground space-y-1">
<div className="font-mono text-xs truncate"> <div className="font-mono text-xs truncate">
Schematic: {asset.schematic_id} {asset.schematic_id}@{asset.version}
</div> </div>
{asset.size && ( {asset.size && (
<div>Size: {(asset.size / 1024 / 1024).toFixed(2)} MB</div> <div>Size: {(asset.size / 1024 / 1024).toFixed(2)} MB</div>
@@ -305,7 +306,7 @@ export function IsoPage() {
size="sm" size="sm"
variant="outline" variant="outline"
onClick={() => { onClick={() => {
window.location.href = assetsApi.getAssetUrl(asset.schematic_id, 'iso'); window.location.href = assetsApi.getAssetUrl(asset.schematic_id, asset.version, 'iso');
}} }}
> >
<Download className="h-4 w-4 mr-1" /> <Download className="h-4 w-4 mr-1" />
@@ -315,7 +316,7 @@ export function IsoPage() {
size="sm" size="sm"
variant="outline" variant="outline"
className="text-red-600 hover:text-red-700 hover:bg-red-50" className="text-red-600 hover:text-red-700 hover:bg-red-50"
onClick={() => handleDelete(asset.schematic_id)} onClick={() => handleDelete(asset.schematic_id, asset.version)}
> >
<Trash2 className="h-4 w-4" /> <Trash2 className="h-4 w-4" />
</Button> </Button>

View File

@@ -1,42 +1,42 @@
import { apiClient } from './client'; import { apiClient } from './client';
import type { AssetListResponse, Schematic, DownloadAssetRequest, AssetStatusResponse } from './types/asset'; import type { AssetListResponse, PXEAsset, DownloadAssetRequest, AssetStatusResponse } from './types/asset';
// Get API base URL // Get API base URL
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:5055'; const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:5055';
export const assetsApi = { export const assetsApi = {
// List all schematics // List all assets (schematic@version combinations)
list: async (): Promise<AssetListResponse> => { list: async (): Promise<AssetListResponse> => {
const response = await apiClient.get('/api/v1/assets'); const response = await apiClient.get('/api/v1/pxe/assets');
return response as AssetListResponse; return response as AssetListResponse;
}, },
// Get schematic details // Get asset details for specific schematic@version
get: async (schematicId: string): Promise<Schematic> => { get: async (schematicId: string, version: string): Promise<PXEAsset> => {
const response = await apiClient.get(`/api/v1/assets/${schematicId}`); const response = await apiClient.get(`/api/v1/pxe/assets/${schematicId}/${version}`);
return response as Schematic; return response as PXEAsset;
}, },
// Download assets for a schematic // Download assets for a schematic@version
download: async (schematicId: string, request: DownloadAssetRequest): Promise<{ message: string }> => { download: async (schematicId: string, version: string, request: DownloadAssetRequest): Promise<{ message: string }> => {
const response = await apiClient.post(`/api/v1/assets/${schematicId}/download`, request); const response = await apiClient.post(`/api/v1/pxe/assets/${schematicId}/${version}/download`, request);
return response as { message: string }; return response as { message: string };
}, },
// Get download status // Get download status
status: async (schematicId: string): Promise<AssetStatusResponse> => { status: async (schematicId: string, version: string): Promise<AssetStatusResponse> => {
const response = await apiClient.get(`/api/v1/assets/${schematicId}/status`); const response = await apiClient.get(`/api/v1/pxe/assets/${schematicId}/${version}/status`);
return response as AssetStatusResponse; return response as AssetStatusResponse;
}, },
// Get download URL for an asset (includes base URL for direct download) // Get download URL for an asset (includes base URL for direct download)
getAssetUrl: (schematicId: string, assetType: 'kernel' | 'initramfs' | 'iso'): string => { getAssetUrl: (schematicId: string, version: string, assetType: 'kernel' | 'initramfs' | 'iso'): string => {
return `${API_BASE_URL}/api/v1/assets/${schematicId}/pxe/${assetType}`; return `${API_BASE_URL}/api/v1/pxe/assets/${schematicId}/${version}/pxe/${assetType}`;
}, },
// Delete a schematic and all its assets // Delete an asset (schematic@version) and all its files
delete: async (schematicId: string): Promise<{ message: string }> => { delete: async (schematicId: string, version: string): Promise<{ message: string }> => {
const response = await apiClient.delete(`/api/v1/assets/${schematicId}`); const response = await apiClient.delete(`/api/v1/pxe/assets/${schematicId}/${version}`);
return response as { message: string }; return response as { message: string };
}, },
}; };

View File

@@ -9,19 +9,19 @@ export function useAssetList() {
}); });
} }
export function useAsset(schematicId: string | null | undefined) { export function useAsset(schematicId: string | null | undefined, version: string | null | undefined) {
return useQuery({ return useQuery({
queryKey: ['assets', schematicId], queryKey: ['assets', schematicId, version],
queryFn: () => assetsApi.get(schematicId!), queryFn: () => assetsApi.get(schematicId!, version!),
enabled: !!schematicId, enabled: !!schematicId && !!version,
}); });
} }
export function useAssetStatus(schematicId: string | null | undefined) { export function useAssetStatus(schematicId: string | null | undefined, version: string | null | undefined) {
return useQuery({ return useQuery({
queryKey: ['assets', schematicId, 'status'], queryKey: ['assets', schematicId, version, 'status'],
queryFn: () => assetsApi.status(schematicId!), queryFn: () => assetsApi.status(schematicId!, version!),
enabled: !!schematicId, enabled: !!schematicId && !!version,
refetchInterval: (query) => { refetchInterval: (query) => {
const data = query.state.data; const data = query.state.data;
// Poll every 2 seconds if downloading // Poll every 2 seconds if downloading
@@ -34,12 +34,12 @@ export function useDownloadAsset() {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation({ return useMutation({
mutationFn: ({ schematicId, request }: { schematicId: string; request: DownloadAssetRequest }) => mutationFn: ({ schematicId, version, request }: { schematicId: string; version: string; request: DownloadAssetRequest }) =>
assetsApi.download(schematicId, request), assetsApi.download(schematicId, version, request),
onSuccess: (_, variables) => { onSuccess: (_, variables) => {
queryClient.invalidateQueries({ queryKey: ['assets'] }); queryClient.invalidateQueries({ queryKey: ['assets'] });
queryClient.invalidateQueries({ queryKey: ['assets', variables.schematicId] }); queryClient.invalidateQueries({ queryKey: ['assets', variables.schematicId, variables.version] });
queryClient.invalidateQueries({ queryKey: ['assets', variables.schematicId, 'status'] }); queryClient.invalidateQueries({ queryKey: ['assets', variables.schematicId, variables.version, 'status'] });
}, },
}); });
} }
@@ -48,11 +48,12 @@ export function useDeleteAsset() {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation({ return useMutation({
mutationFn: (schematicId: string) => assetsApi.delete(schematicId), mutationFn: ({ schematicId, version }: { schematicId: string; version: string }) =>
onSuccess: (_, schematicId) => { assetsApi.delete(schematicId, version),
onSuccess: (_, { schematicId, version }) => {
queryClient.invalidateQueries({ queryKey: ['assets'] }); queryClient.invalidateQueries({ queryKey: ['assets'] });
queryClient.invalidateQueries({ queryKey: ['assets', schematicId] }); queryClient.invalidateQueries({ queryKey: ['assets', schematicId, version] });
queryClient.invalidateQueries({ queryKey: ['assets', schematicId, 'status'] }); queryClient.invalidateQueries({ queryKey: ['assets', schematicId, version, 'status'] });
}, },
}); });
} }

View File

@@ -10,8 +10,8 @@ export interface Asset {
downloaded: boolean; downloaded: boolean;
} }
// Schematic representation matching backend // PXEAsset represents a schematic@version combination (composite key)
export interface Schematic { export interface PXEAsset {
schematic_id: string; schematic_id: string;
version: string; version: string;
path: string; path: string;
@@ -19,13 +19,12 @@ export interface Schematic {
} }
export interface AssetListResponse { export interface AssetListResponse {
schematics: Schematic[]; assets: PXEAsset[];
} }
export interface DownloadAssetRequest { export interface DownloadAssetRequest {
version: string;
platform?: Platform; platform?: Platform;
assets?: AssetType[]; asset_types?: string[];
force?: boolean; force?: boolean;
} }