mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-09 18:53:38 +02:00
Support binary responses!
This commit is contained in:
20
src-web/hooks/useResponseBodyBlob.ts
Normal file
20
src-web/hooks/useResponseBodyBlob.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { readBinaryFile } from '@tauri-apps/api/fs';
|
||||
import type { HttpResponse } from '../lib/models';
|
||||
|
||||
export function useResponseBodyBlob(response: HttpResponse | null) {
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user