mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-17 23:14:03 +01:00
21 lines
609 B
TypeScript
21 lines
609 B
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { readBinaryFile } from '@tauri-apps/api/fs';
|
|
import type { HttpResponse } from '../lib/models';
|
|
|
|
export function useResponseBodyBlob(response: HttpResponse) {
|
|
return useQuery<Uint8Array | null>({
|
|
enabled: response != null,
|
|
queryKey: ['response-body-binary', response?.updatedAt],
|
|
initialData: null,
|
|
queryFn: async () => {
|
|
if (response.body) {
|
|
return Uint8Array.of(...response.body);
|
|
}
|
|
if (response.bodyPath) {
|
|
return readBinaryFile(response.bodyPath);
|
|
}
|
|
return null;
|
|
},
|
|
}).data;
|
|
}
|