mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-09-11 22:48:38 +00:00
fix(frontend): encode uploaded filenames in delete requests (#4312)
This commit is contained in:
parent
cd34a1a504
commit
16377b1206
@ -116,8 +116,9 @@ export async function deleteUploadedFile(
|
|||||||
threadId: string,
|
threadId: string,
|
||||||
filename: string,
|
filename: string,
|
||||||
): Promise<{ success: boolean; message: string }> {
|
): Promise<{ success: boolean; message: string }> {
|
||||||
|
const encodedFilename = encodeURIComponent(filename);
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${getBackendBaseURL()}/api/threads/${threadId}/uploads/${filename}`,
|
`${getBackendBaseURL()}/api/threads/${threadId}/uploads/${encodedFilename}`,
|
||||||
{
|
{
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
},
|
},
|
||||||
|
|||||||
49
frontend/tests/unit/core/uploads/api.test.ts
Normal file
49
frontend/tests/unit/core/uploads/api.test.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import { beforeEach, describe, expect, rs, test } from "@rstest/core";
|
||||||
|
|
||||||
|
rs.mock("@/core/api/fetcher", () => ({
|
||||||
|
fetch: rs.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
rs.mock("@/core/config", () => ({
|
||||||
|
getBackendBaseURL: () => "/backend",
|
||||||
|
}));
|
||||||
|
|
||||||
|
import { fetch as fetcher } from "@/core/api/fetcher";
|
||||||
|
import { deleteUploadedFile } from "@/core/uploads/api";
|
||||||
|
|
||||||
|
const mockedFetch = rs.mocked(fetcher);
|
||||||
|
|
||||||
|
function jsonResponse(status: number, body: unknown): Response {
|
||||||
|
return new Response(JSON.stringify(body), {
|
||||||
|
status,
|
||||||
|
statusText: status >= 400 ? "Error" : "OK",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mockedFetch.mockReset();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("uploads api", () => {
|
||||||
|
test("encodes uploaded filenames in delete request paths", async () => {
|
||||||
|
mockedFetch.mockResolvedValueOnce(
|
||||||
|
jsonResponse(200, {
|
||||||
|
success: true,
|
||||||
|
message: "Deleted report#1?.txt",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
deleteUploadedFile("thread-1", "report#1?.txt"),
|
||||||
|
).resolves.toEqual({
|
||||||
|
success: true,
|
||||||
|
message: "Deleted report#1?.txt",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(mockedFetch).toHaveBeenCalledWith(
|
||||||
|
"/backend/api/threads/thread-1/uploads/report%231%3F.txt",
|
||||||
|
{ method: "DELETE" },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user