fix linux issue
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { remotePathBasename } from "./file-transfer-state";
|
||||
|
||||
describe("remotePathBasename", () => {
|
||||
test("extracts names from Windows paths on any server platform", () => {
|
||||
expect(remotePathBasename("C:\\Temp\\overlord-e2e-download.bin"))
|
||||
.toBe("overlord-e2e-download.bin");
|
||||
});
|
||||
|
||||
test("extracts names from POSIX and mixed-separator paths", () => {
|
||||
expect(remotePathBasename("/tmp/archive.tar.gz")).toBe("archive.tar.gz");
|
||||
expect(remotePathBasename("C:\\Temp/mixed.bin")).toBe("mixed.bin");
|
||||
});
|
||||
});
|
||||
@@ -91,6 +91,11 @@ export function isSafeRemotePath(value: string): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
export function remotePathBasename(value: string): string {
|
||||
const segments = value.split(/[\\/]+/).filter(Boolean);
|
||||
return segments.at(-1) || "";
|
||||
}
|
||||
|
||||
export function notifyPullWaiters(state: StreamingPullState) {
|
||||
const list = state.waiters.splice(0);
|
||||
for (const w of list) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
UUID_TOKEN_RE,
|
||||
getFileTransferLimits,
|
||||
isSafeRemotePath,
|
||||
remotePathBasename,
|
||||
makeIncrementalPullStream,
|
||||
notifyPullWaiters,
|
||||
streamFileRangeWithCleanup,
|
||||
@@ -125,7 +126,7 @@ async function serveDownloadById(
|
||||
|
||||
const commandId = uuidv4();
|
||||
|
||||
let fileName = path.basename(downloadPath) || "download.bin";
|
||||
let fileName = remotePathBasename(downloadPath) || "download.bin";
|
||||
try {
|
||||
fileName = deps.sanitizeOutputName(fileName);
|
||||
} catch {
|
||||
@@ -604,7 +605,7 @@ export async function handleFileDownloadRoutes(
|
||||
ip: server.requestIP(req)?.address || "unknown",
|
||||
});
|
||||
|
||||
const fileName = deps.sanitizeOutputName(path.basename(pull.fileName) || "upload.bin");
|
||||
const fileName = deps.sanitizeOutputName(remotePathBasename(pull.fileName) || "upload.bin");
|
||||
const baseHeaders = {
|
||||
...deps.secureHeaders("application/octet-stream"),
|
||||
"Content-Disposition": `attachment; filename="${fileName}"`,
|
||||
|
||||
Reference in New Issue
Block a user