Remove download to folder, just download zip or single file. The folder download is still accessible by Alt+Click on the download button (in the few browsers that support it).
This commit is contained in:
@@ -7,7 +7,6 @@ import { useMainStore } from '@/stores/main'
|
|||||||
import { apiFetch } from '@/repositories/Client'
|
import { apiFetch } from '@/repositories/Client'
|
||||||
import type { SelectedItems } from '@/repositories/Document'
|
import type { SelectedItems } from '@/repositories/Document'
|
||||||
import { zipName } from '@/utils/fileutil'
|
import { zipName } from '@/utils/fileutil'
|
||||||
import { reactive } from 'vue';
|
|
||||||
|
|
||||||
const store = useMainStore()
|
const store = useMainStore()
|
||||||
|
|
||||||
@@ -131,39 +130,7 @@ const filesystemdl = async (sel: SelectedItems, handle: FileSystemDirectoryHandl
|
|||||||
statReset()
|
statReset()
|
||||||
}
|
}
|
||||||
|
|
||||||
const download = async () => {
|
const zipdl = (sel: SelectedItems) => {
|
||||||
const sel = store.selectedFiles
|
|
||||||
console.log('Download', sel)
|
|
||||||
if (sel.keys.length === 0) {
|
|
||||||
console.warn('Attempted download but no files found. Missing selected keys:', sel.missing)
|
|
||||||
store.showToast('No existing files selected')
|
|
||||||
store.selected.clear()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// Plain old a href download if only one file (ignoring any folders)
|
|
||||||
const files = sel.recursive.filter(([rel, full, doc]) => !doc.dir)
|
|
||||||
if (files.length === 1) {
|
|
||||||
store.selected.clear()
|
|
||||||
store.showToast(`Downloading ${files[0]![0].split('/').pop()}`)
|
|
||||||
return linkdl(`/files/${files[0]![1]}`)
|
|
||||||
}
|
|
||||||
// Use FileSystem API if multiple files and the browser supports it
|
|
||||||
if ('showDirectoryPicker' in window) {
|
|
||||||
try {
|
|
||||||
// @ts-ignore
|
|
||||||
const handle = await window.showDirectoryPicker({
|
|
||||||
startIn: 'downloads',
|
|
||||||
mode: 'readwrite'
|
|
||||||
})
|
|
||||||
await filesystemdl(sel, handle)
|
|
||||||
store.selected.clear()
|
|
||||||
return
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Download to folder aborted', e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Otherwise, zip and download
|
|
||||||
console.log("Falling back to zip download")
|
|
||||||
const items = sel.keys.map(k => sel.docs[k]!)
|
const items = sel.keys.map(k => sel.docs[k]!)
|
||||||
const name = zipName(items)
|
const name = zipName(items)
|
||||||
linkdl(`/zip/${Array.from(sel.keys).join('+')}/${name}.zip`)
|
linkdl(`/zip/${Array.from(sel.keys).join('+')}/${name}.zip`)
|
||||||
@@ -171,6 +138,37 @@ const download = async () => {
|
|||||||
store.selected.clear()
|
store.selected.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const download = async (e: MouseEvent) => {
|
||||||
|
const sel = store.selectedFiles
|
||||||
|
if (sel.keys.length === 0) {
|
||||||
|
store.showToast('No existing files selected')
|
||||||
|
store.selected.clear()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Single file: direct download
|
||||||
|
const files = sel.recursive.filter(([rel, full, doc]) => !doc.dir)
|
||||||
|
if (files.length === 1) {
|
||||||
|
store.selected.clear()
|
||||||
|
store.showToast(`Downloading ${files[0]![0].split('/').pop()}`)
|
||||||
|
return linkdl(`/files/${files[0]![1]}`)
|
||||||
|
}
|
||||||
|
// Alt+click: download to folder (hidden feature)
|
||||||
|
if (e.altKey && 'showDirectoryPicker' in window) {
|
||||||
|
try {
|
||||||
|
// @ts-ignore
|
||||||
|
const handle = await window.showDirectoryPicker({ startIn: 'downloads', mode: 'readwrite' })
|
||||||
|
await filesystemdl(sel, handle)
|
||||||
|
store.selected.clear()
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Download to folder failed', e)
|
||||||
|
store.showToast('Download to folder failed')
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Default: ZIP download
|
||||||
|
zipdl(sel)
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
Reference in New Issue
Block a user