mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-08-24 04:13:59 +02:00
The body commands took a path from the client, so a token holder could read any file the process could. They now take a response id and resolve the location themselves, and the UI never sees a path at all: the desktop host asks the backend where the file is, and the bridge fetches /responses/:id/body. Ephemeral responses (GraphQL introspection) never reach the database, so resolution falls back to the path send writes them to.
24 lines
932 B
TypeScript
24 lines
932 B
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
import type { HttpResponse } from "@yaakapp-internal/models";
|
|
import { platform } from "@yaakapp-internal/platform";
|
|
|
|
/**
|
|
* A URL for a stored response body, for the viewers that hand one to an element
|
|
* instead of reading the bytes themselves.
|
|
*
|
|
* Resolved once here rather than inside each viewer: the host may have to ask
|
|
* the backend where the body is, and a viewer that computes its source during
|
|
* render (the PDF one, deliberately) needs it settled before it mounts.
|
|
*
|
|
* Null data means the response has no stored body.
|
|
*/
|
|
export function useResponseBodyUrl(response: HttpResponse | null) {
|
|
const responseId = response?.id ?? null;
|
|
|
|
return useQuery({
|
|
queryKey: ["response_body_url", responseId, response?.updatedAt ?? ""],
|
|
enabled: responseId != null,
|
|
queryFn: () => (responseId == null ? null : platform.files.responseBodyUrl(responseId)),
|
|
});
|
|
}
|