delete multiple files with selection
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user