mirror of
https://github.com/gtsteffaniak/filebrowser.git
synced 2026-11-24 15:43:41 -05:00
fix single download issue (#3420)
This commit is contained in:
1 parent
a1e41f667d
commit
cfe9ad992e
4 files changed
+58
-17
No files matched your search
@@ -7,10 +7,6 @@ import (
|
||||
"net"
|
||||
)
|
||||
|
||||
func peerCredentialFromConn(net.Conn) (UnixPeerCredential, bool) {
|
||||
return UnixPeerCredential{}, false
|
||||
}
|
||||
|
||||
func attachUnixPeerContext(ctx context.Context, _ net.Conn) context.Context {
|
||||
return ctx
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package settings
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
@@ -61,13 +60,23 @@ func TestListenUnixFilesystemSetsModeWithRestrictiveUmask(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("filesystem unix sockets are not used on Windows")
|
||||
}
|
||||
// Bind uses sockaddr_un.sun_path; macOS allows at most 104 bytes, so use a short
|
||||
// relative path in the test working directory (not the long t.TempDir() absolute path).
|
||||
dir := t.TempDir()
|
||||
socketPath := filepath.Join(dir, "fb.sock")
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if chdirErr := os.Chdir(dir); chdirErr != nil {
|
||||
t.Fatal(chdirErr)
|
||||
}
|
||||
socketPath := "fb.sock"
|
||||
orig := Config.Http
|
||||
Config.Http.SocketFileMode = ""
|
||||
t.Cleanup(func() {
|
||||
Config.Http = orig
|
||||
_ = os.Remove(socketPath)
|
||||
_ = os.Chdir(wd)
|
||||
Config.Http = orig
|
||||
})
|
||||
ln, err := ListenUnixFilesystem(socketPath)
|
||||
if err != nil {
|
||||
|
||||
@@ -285,12 +285,16 @@ export async function put(source, path, content = '') {
|
||||
return await resourceAction(source, path, 'PUT', content)
|
||||
}
|
||||
|
||||
function isDirectoryItem(item) {
|
||||
return item?.isDir === true || item?.type === "directory"
|
||||
}
|
||||
|
||||
export async function download(format, files, shareHash = "") {
|
||||
const downloadChunkSizeMb = state.user?.fileLoading?.downloadChunkSizeMb || 0
|
||||
const sizeThreshold = downloadChunkSizeMb * 1024 * 1024
|
||||
|
||||
const isMultiItemArchive =
|
||||
files.length > 1 || (files.length === 1 && files[0].isDir)
|
||||
files.length > 1 || (files.length === 1 && isDirectoryItem(files[0]))
|
||||
|
||||
const useChunkedArchive =
|
||||
downloadChunkSizeMb > 0 && isMultiItemArchive
|
||||
@@ -298,7 +302,7 @@ export async function download(format, files, shareHash = "") {
|
||||
const useChunkedDownload =
|
||||
downloadChunkSizeMb > 0 &&
|
||||
files.length === 1 &&
|
||||
!files[0].isDir &&
|
||||
!isDirectoryItem(files[0]) &&
|
||||
files[0].size &&
|
||||
files[0].size >= sizeThreshold
|
||||
|
||||
@@ -444,7 +448,7 @@ async function resolveDownloadContentLength(url) {
|
||||
function archiveDisplayFileName(format, files) {
|
||||
const ext = format === 'zip' ? '.zip' : '.tar.gz'
|
||||
const first = files[0]
|
||||
if (files.length === 1 && first.isDir) {
|
||||
if (files.length === 1 && isDirectoryItem(first)) {
|
||||
const base =
|
||||
first.name ||
|
||||
(first.path?.split('/').filter(Boolean).pop()) ||
|
||||
@@ -614,9 +618,14 @@ async function downloadChunkedArchive(url, format, files, filePaths, source, sha
|
||||
}
|
||||
const chunkSize = downloadChunkSizeMb * 1024 * 1024
|
||||
const fileName = archiveDisplayFileName(format, files)
|
||||
const { size: fileSize, token } = await resolveDownloadContentLength(url)
|
||||
const sizeProbeMessage = 'Could not determine archive size for chunked download'
|
||||
const { size: fileSize, token } = await resolveDownloadContentLength(url).catch((error) => {
|
||||
notifyDownloadError(fileName, error?.message || sizeProbeMessage)
|
||||
throw error
|
||||
})
|
||||
if (!fileSize || fileSize <= 0) {
|
||||
throw new Error('Could not determine archive size for chunked download')
|
||||
notifyDownloadError(fileName, sizeProbeMessage)
|
||||
throw new Error(sizeProbeMessage)
|
||||
}
|
||||
|
||||
const baseUrl = appendArchiveTokenToUrl(url, token)
|
||||
|
||||
@@ -2,6 +2,14 @@ import { resourcesApi } from "@/api/index.js";
|
||||
import { notify } from "@/notify/index.ts";
|
||||
import { getters, mutations, state } from "@/store/index.ts";
|
||||
|
||||
function isItemDirectory(item) {
|
||||
return item?.isDir === true || item?.type === "directory";
|
||||
}
|
||||
|
||||
function isSingleFileItem(items) {
|
||||
return items.length === 1 && !isItemDirectory(items[0]);
|
||||
}
|
||||
|
||||
export default function downloadFiles(items) {
|
||||
if (items.length === 0) {
|
||||
notify.showError("No files selected");
|
||||
@@ -19,12 +27,12 @@ export default function downloadFiles(items) {
|
||||
const willUseChunkedDownload =
|
||||
downloadChunkSizeMb > 0 &&
|
||||
items.length === 1 &&
|
||||
!items[0].isDir &&
|
||||
!isItemDirectory(items[0]) &&
|
||||
items[0].size &&
|
||||
items[0].size >= sizeThreshold
|
||||
|
||||
const isMultiItemArchive =
|
||||
items.length > 1 || (items.length === 1 && items[0].isDir)
|
||||
items.length > 1 || (items.length === 1 && isItemDirectory(items[0]))
|
||||
|
||||
const willUseChunkedArchive =
|
||||
downloadChunkSizeMb > 0 && isMultiItemArchive
|
||||
@@ -34,7 +42,7 @@ export default function downloadFiles(items) {
|
||||
|
||||
if (getters.isShare()) {
|
||||
// Perform download without opening a new window
|
||||
if (getters.isSingleFileSelected()) {
|
||||
if (isSingleFileItem(items)) {
|
||||
if (showChunkedProgressFirst) {
|
||||
mutations.showPrompt({ name: "download" });
|
||||
void startDownload(null, items, state.shareInfo.hash, {
|
||||
@@ -58,7 +66,7 @@ export default function downloadFiles(items) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getters.isSingleFileSelected()) {
|
||||
if (isSingleFileItem(items)) {
|
||||
if (showChunkedProgressFirst) {
|
||||
mutations.showPrompt({ name: "download" });
|
||||
void startDownload(null, items, "", { silentChunkedError: true });
|
||||
@@ -105,11 +113,30 @@ export function showShareDownloadPrompt(items) {
|
||||
}
|
||||
|
||||
const downloadChunkSizeMb = state.user?.fileLoading?.downloadChunkSizeMb || 0;
|
||||
const sizeThreshold = downloadChunkSizeMb * 1024 * 1024;
|
||||
const willUseChunkedDownload =
|
||||
downloadChunkSizeMb > 0 &&
|
||||
items.length === 1 &&
|
||||
!isItemDirectory(items[0]) &&
|
||||
items[0].size &&
|
||||
items[0].size >= sizeThreshold;
|
||||
const isMultiItemArchive =
|
||||
items.length > 1 || (items.length === 1 && items[0].isDir);
|
||||
items.length > 1 || (items.length === 1 && isItemDirectory(items[0]));
|
||||
const willUseChunkedArchive =
|
||||
downloadChunkSizeMb > 0 && isMultiItemArchive;
|
||||
|
||||
if (isSingleFileItem(items)) {
|
||||
if (willUseChunkedDownload) {
|
||||
mutations.showPrompt({ name: "download" });
|
||||
void startDownload(null, items, state.shareInfo?.hash || "", {
|
||||
silentChunkedError: true,
|
||||
});
|
||||
} else {
|
||||
void startDownload(null, items, state.shareInfo?.hash || "");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
mutations.showPrompt({
|
||||
name: "download",
|
||||
confirm: (format) => {
|
||||
|
||||
Reference in new issue
Block a user