Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/client/api-client/@tanstack/react-query.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
deleteVolume,
devPanelExec,
downloadResticPassword,
dumpSnapshot,
getBackupSchedule,
getBackupScheduleForVolume,
getDevPanel,
Expand Down Expand Up @@ -100,6 +101,8 @@ import type {
DevPanelExecResponse,
DownloadResticPasswordData,
DownloadResticPasswordResponse,
DumpSnapshotData,
DumpSnapshotResponse,
GetBackupScheduleData,
GetBackupScheduleForVolumeData,
GetBackupScheduleForVolumeResponse,
Expand Down Expand Up @@ -851,6 +854,25 @@ export const listSnapshotFilesInfiniteOptions = (options: Options<ListSnapshotFi
},
);

export const dumpSnapshotQueryKey = (options: Options<DumpSnapshotData>) => createQueryKey("dumpSnapshot", options);

/**
* Download a snapshot path as a tar archive (folders) or raw file stream (single files)
*/
export const dumpSnapshotOptions = (options: Options<DumpSnapshotData>) =>
queryOptions<DumpSnapshotResponse, DefaultError, DumpSnapshotResponse, ReturnType<typeof dumpSnapshotQueryKey>>({
queryFn: async ({ queryKey, signal }) => {
const { data } = await dumpSnapshot({
...options,
...queryKey[0],
signal,
throwOnError: true,
});
return data;
},
queryKey: dumpSnapshotQueryKey(options),
});

/**
* Restore a snapshot to a target path on the filesystem
*/
Expand Down
4 changes: 4 additions & 0 deletions app/client/api-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export {
deleteVolume,
devPanelExec,
downloadResticPassword,
dumpSnapshot,
getBackupSchedule,
getBackupScheduleForVolume,
getDevPanel,
Expand Down Expand Up @@ -109,6 +110,9 @@ export type {
DownloadResticPasswordData,
DownloadResticPasswordResponse,
DownloadResticPasswordResponses,
DumpSnapshotData,
DumpSnapshotResponse,
DumpSnapshotResponses,
GetBackupScheduleData,
GetBackupScheduleForVolumeData,
GetBackupScheduleForVolumeResponse,
Expand Down
11 changes: 11 additions & 0 deletions app/client/api-client/sdk.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import type {
DevPanelExecResponses,
DownloadResticPasswordData,
DownloadResticPasswordResponses,
DumpSnapshotData,
DumpSnapshotResponses,
GetBackupScheduleData,
GetBackupScheduleForVolumeData,
GetBackupScheduleForVolumeResponses,
Expand Down Expand Up @@ -431,6 +433,15 @@ export const listSnapshotFiles = <ThrowOnError extends boolean = false>(
...options,
});

/**
* Download a snapshot path as a tar archive (folders) or raw file stream (single files)
*/
export const dumpSnapshot = <ThrowOnError extends boolean = false>(options: Options<DumpSnapshotData, ThrowOnError>) =>
(options.client ?? client).get<DumpSnapshotResponses, unknown, ThrowOnError>({
url: "/api/v1/repositories/{shortId}/snapshots/{snapshotId}/dump",
...options,
});

/**
* Restore a snapshot to a target path on the filesystem
*/
Expand Down
22 changes: 22 additions & 0 deletions app/client/api-client/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,28 @@ export type ListSnapshotFilesResponses = {

export type ListSnapshotFilesResponse = ListSnapshotFilesResponses[keyof ListSnapshotFilesResponses];

export type DumpSnapshotData = {
body?: never;
path: {
shortId: string;
snapshotId: string;
};
query?: {
kind?: "dir" | "file";
path?: string;
};
url: "/api/v1/repositories/{shortId}/snapshots/{snapshotId}/dump";
};

export type DumpSnapshotResponses = {
/**
* Snapshot content stream
*/
200: Blob | File;
};

export type DumpSnapshotResponse = DumpSnapshotResponses[keyof DumpSnapshotResponses];

export type RestoreSnapshotData = {
body?: {
snapshotId: string;
Expand Down
8 changes: 1 addition & 7 deletions app/client/components/file-browsers/local-file-browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ import { browseFilesystemOptions } from "~/client/api-client/@tanstack/react-que
import { FileBrowser, type FileBrowserUiProps } from "~/client/components/file-browsers/file-browser";
import { useFileBrowser } from "~/client/hooks/use-file-browser";
import { parseError } from "~/client/lib/errors";

const normalizeAbsolutePath = (path?: string): string => {
if (!path) return "/";
const withLeadingSlash = path.startsWith("/") ? path : `/${path}`;
const trimmed = withLeadingSlash.replace(/\/+$/, "");
return trimmed || "/";
};
import { normalizeAbsolutePath } from "~/utils/path";

type LocalFileBrowserProps = FileBrowserUiProps & {
initialPath?: string;
Expand Down
60 changes: 38 additions & 22 deletions app/client/components/file-browsers/snapshot-tree-browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@ import { listSnapshotFilesOptions } from "~/client/api-client/@tanstack/react-qu
import { FileBrowser, type FileBrowserUiProps } from "~/client/components/file-browsers/file-browser";
import { useFileBrowser } from "~/client/hooks/use-file-browser";
import { parseError } from "~/client/lib/errors";

const normalizeAbsolutePath = (path?: string): string => {
if (!path) return "/";
const withLeadingSlash = path.startsWith("/") ? path : `/${path}`;
const trimmed = withLeadingSlash.replace(/\/+$/, "");
return trimmed || "/";
};
import { normalizeAbsolutePath } from "~/utils/path";

type SnapshotTreeBrowserProps = FileBrowserUiProps & {
repositoryId: string;
snapshotId: string;
basePath?: string;
pageSize?: number;
enabled?: boolean;
onSingleSelectionKindChange?: (kind: "file" | "dir" | null) => void;
};

export const SnapshotTreeBrowser = ({
Expand All @@ -28,7 +23,7 @@ export const SnapshotTreeBrowser = ({
enabled = true,
...uiProps
}: SnapshotTreeBrowserProps) => {
const { selectedPaths, onSelectionChange, ...fileBrowserUiProps } = uiProps;
const { selectedPaths, onSelectionChange, onSingleSelectionKindChange, ...fileBrowserUiProps } = uiProps;
const queryClient = useQueryClient();
const normalizedBasePath = normalizeAbsolutePath(basePath);

Expand Down Expand Up @@ -72,20 +67,6 @@ export const SnapshotTreeBrowser = ({
return displayPaths;
}, [selectedPaths, stripBasePath]);

const handleSelectionChange = useCallback(
(nextDisplayPaths: Set<string>) => {
if (!onSelectionChange) return;

const nextFullPaths = new Set<string>();
for (const displayPath of nextDisplayPaths) {
nextFullPaths.add(addBasePath(displayPath));
}

onSelectionChange(nextFullPaths);
},
[onSelectionChange, addBasePath],
);

const fileBrowser = useFileBrowser({
initialData: data,
isLoading,
Expand Down Expand Up @@ -119,6 +100,41 @@ export const SnapshotTreeBrowser = ({
},
});

const displayPathKinds = useMemo(() => {
const kinds = new Map<string, "file" | "dir">();
for (const entry of fileBrowser.fileArray) {
kinds.set(entry.path, entry.type === "file" ? "file" : "dir");
}
return kinds;
}, [fileBrowser.fileArray]);

const handleSelectionChange = useCallback(
(nextDisplayPaths: Set<string>) => {
if (!onSelectionChange) return;

const nextFullPaths = new Set<string>();
for (const displayPath of nextDisplayPaths) {
nextFullPaths.add(addBasePath(displayPath));
}

if (onSingleSelectionKindChange) {
if (nextDisplayPaths.size === 1) {
const [selectedDisplayPath] = nextDisplayPaths;
if (selectedDisplayPath) {
onSingleSelectionKindChange(displayPathKinds.get(selectedDisplayPath) ?? null);
} else {
onSingleSelectionKindChange(null);
}
} else {
onSingleSelectionKindChange(null);
}
}

onSelectionChange(nextFullPaths);
},
[onSelectionChange, addBasePath, onSingleSelectionKindChange, displayPathKinds],
);

const errorDetails = parseError(error)?.message;
const errorMessage = errorDetails
? `Failed to load files: ${errorDetails}`
Expand Down
Loading