feat(images): frontend Images page, catalog hooks, download dialog
Phase 1 UI for VM image mirror feature: - use-image-catalog hook (catalog, lxc repo templates, target storages, download) - ImagesPage: server/node context, arch/search filters, cloud + LXC sections - DownloadImageDialog: storage picker, background download via DeployTask - CatalogImage/ImageMirror types, image_download/image_template task kinds - sidebar nav 'Images' + /images route Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
75
frontend/src/hooks/use-image-catalog.ts
Normal file
75
frontend/src/hooks/use-image-catalog.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { apiClient } from '@/lib/api-client';
|
||||
import type {
|
||||
ImageCatalogResponse,
|
||||
ImageTargetStorage,
|
||||
} from '@/types';
|
||||
import type { AvailableLXCTemplate } from '@/hooks/use-lxc-templates';
|
||||
|
||||
export const imageKeys = {
|
||||
catalog: ['image-catalog'] as const,
|
||||
lxcRepo: (serverId?: number, node?: string) => ['image-lxc-repo', serverId, node] as const,
|
||||
storages: (serverId?: number, node?: string, content?: string) =>
|
||||
['image-storages', serverId, node, content] as const,
|
||||
};
|
||||
|
||||
// Встроенный каталог + кастомные зеркала. Меняется редко — кэш 10 минут.
|
||||
export function useImageCatalog() {
|
||||
return useQuery({
|
||||
queryKey: imageKeys.catalog,
|
||||
queryFn: () => apiClient.get<ImageCatalogResponse>('/proxmox/api/images/catalog'),
|
||||
staleTime: 10 * 60 * 1000,
|
||||
});
|
||||
}
|
||||
|
||||
// Динамический список LXC-шаблонов из репозитория Proxmox (aplinfo).
|
||||
export function useImageLXCTemplates(serverId?: number, node?: string) {
|
||||
return useQuery({
|
||||
queryKey: imageKeys.lxcRepo(serverId, node),
|
||||
queryFn: () =>
|
||||
apiClient.get<AvailableLXCTemplate[]>(
|
||||
`/proxmox/api/${serverId}/images/lxc-templates?node=${encodeURIComponent(node!)}`,
|
||||
),
|
||||
enabled: !!serverId && !!node,
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
}
|
||||
|
||||
// Целевые хранилища ноды по типу контента (import|vztmpl|iso).
|
||||
export function useImageStorages(serverId?: number, node?: string, content?: string) {
|
||||
return useQuery({
|
||||
queryKey: imageKeys.storages(serverId, node, content),
|
||||
queryFn: () =>
|
||||
apiClient.get<ImageTargetStorage[]>(
|
||||
`/proxmox/api/${serverId}/images/storages?node=${encodeURIComponent(node!)}&content=${encodeURIComponent(content!)}`,
|
||||
),
|
||||
enabled: !!serverId && !!node && !!content,
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
}
|
||||
|
||||
export interface ImageDownloadRequest {
|
||||
node: string;
|
||||
storage: string;
|
||||
source_id?: string;
|
||||
kind?: 'qcow2' | 'vztmpl';
|
||||
url?: string;
|
||||
template?: string;
|
||||
filename?: string;
|
||||
checksum?: string;
|
||||
checksum_algorithm?: string;
|
||||
}
|
||||
|
||||
export function useDownloadImage(serverId: number) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: ImageDownloadRequest) =>
|
||||
apiClient.post<{ task_id: number; status: string; name: string }>(
|
||||
`/proxmox/api/${serverId}/images/download`,
|
||||
data,
|
||||
),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ['all-tasks'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user