move multiple files at once

This commit is contained in:
2025-09-05 01:22:40 +02:00
parent 13e91fdfbf
commit 49c59cbaea
14 changed files with 224 additions and 112 deletions

View File

@@ -382,9 +382,9 @@ export async function fetchFileStream(
};
}
export async function moveFile(
export async function moveFiles(
warrenId: string,
currentPath: string,
currentPaths: string[],
targetPath: string
): Promise<{ success: boolean }> {
const { status } = await useFetch(getApiUrl(`warrens/files/mv`), {
@@ -392,7 +392,7 @@ export async function moveFile(
headers: getApiHeaders(),
body: JSON.stringify({
warrenId,
path: currentPath,
paths: currentPaths,
targetPath: targetPath,
}),
});

View File

@@ -7,7 +7,6 @@ definePageMeta({
layout: 'share',
});
const selectionRect = useSelectionRect();
const warrenStore = useWarrenStore();
const route = useRoute();

View File

@@ -1,4 +1,4 @@
import { copyFile, moveFile } from '~/lib/api/warrens';
import { copyFile, moveFiles } from '~/lib/api/warrens';
import type { DirectoryEntry } from '~/shared/types';
export function joinPaths(path: string, ...other: string[]): string {
@@ -25,7 +25,11 @@ export function onDirectoryEntryDrop(
return async (e: DragEvent) => {
const warrenStore = useWarrenStore();
if (e.dataTransfer == null || warrenStore.current == null) {
if (
e.dataTransfer == null ||
warrenStore.current == null ||
warrenStore.current.dir == null
) {
return;
}
@@ -39,23 +43,29 @@ export function onDirectoryEntryDrop(
return;
}
const currentPath = joinPaths(warrenStore.current.path, fileName);
const draggedEntry = warrenStore.current.dir.entries.find(
(e) => e.name === fileName
);
if (draggedEntry == null) {
return;
}
const targetPaths = getTargetsFromSelection(
draggedEntry,
warrenStore.selection
).map((currentEntry) =>
joinPaths(warrenStore.current!.path, currentEntry.name)
);
let targetPath: string;
if (isParent) {
targetPath = joinPaths(
getParentPath(warrenStore.current.path),
fileName
);
targetPath = getParentPath(warrenStore.current.path);
} else {
targetPath = joinPaths(
warrenStore.current.path,
entry.name,
fileName
);
targetPath = joinPaths(warrenStore.current.path, entry.name);
}
await moveFile(warrenStore.current.warrenId, currentPath, targetPath);
await moveFiles(warrenStore.current.warrenId, targetPaths, targetPath);
};
}