delete multiple files with selection

This commit is contained in:
2025-09-04 16:26:23 +02:00
parent 49b4162448
commit 8b2ed0e700
17 changed files with 250 additions and 137 deletions

View File

@@ -3,7 +3,13 @@ import { useDropZone } from '@vueuse/core';
import { toast } from 'vue-sonner';
import DirectoryListContextMenu from '~/components/DirectoryListContextMenu.vue';
import RenameEntryDialog from '~/components/actions/RenameEntryDialog.vue';
import { fetchFile, getWarrenDirectory } from '~/lib/api/warrens';
import {
deleteWarrenDirectory,
deleteWarrenFile,
fetchFile,
getWarrenDirectory,
warrenRm,
} from '~/lib/api/warrens';
import type { DirectoryEntry } from '~/shared/types';
definePageMeta({
@@ -119,27 +125,39 @@ function onEntryDownload(entry: DirectoryEntry) {
let downloadName: string;
let downloadApiUrl: string;
const selectionSize = warrenStore.selection.size;
if (selectionSize === 0 || !warrenStore.isSelected(entry)) {
const targets = getTargetsFromSelection(entry, warrenStore.selection);
if (targets.length === 1) {
downloadName =
entry.fileType === 'directory' ? `${entry.name}.zip` : entry.name;
entry.fileType === 'directory'
? `${targets[0].name}.zip`
: targets[0].name;
downloadApiUrl = getApiUrl(
`warrens/files/cat?warrenId=${warrenStore.current.warrenId}&paths=${joinPaths(warrenStore.current.path, entry.name)}`
`warrens/files/cat?warrenId=${warrenStore.current.warrenId}&paths=${joinPaths(warrenStore.current.path, targets[0].name)}`
);
} else {
downloadName = 'download.zip';
const paths = Array.from(warrenStore.selection).map((entry) =>
joinPaths(warrenStore.current!.path, entry.name)
);
const paths = targets
.map((entry) => joinPaths(warrenStore.current!.path, entry.name))
.join(':');
downloadApiUrl = getApiUrl(
`warrens/files/cat?warrenId=${warrenStore.current.warrenId}&paths=${paths.join(':')}`
`warrens/files/cat?warrenId=${warrenStore.current.warrenId}&paths=${paths}`
);
}
downloadFile(downloadName, downloadApiUrl);
}
async function onEntryDelete(entry: DirectoryEntry, force: boolean) {
if (warrenStore.current == null) {
return;
}
const targets = getTargetsFromSelection(entry, warrenStore.selection).map(
(entry) => joinPaths(warrenStore.current!.path, entry.name)
);
await warrenRm(warrenStore.current.warrenId, targets, force);
}
function onBack() {
warrenStore.backCurrentPath();
@@ -162,6 +180,7 @@ function onBack() {
:parent="warrenStore.current.dir.parent"
@entry-click="onEntryClicked"
@entry-download="onEntryDownload"
@entry-delete="onEntryDelete"
@back="onBack"
/>
</DirectoryListContextMenu>