mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-17 22:46:48 +01:00
23 lines
641 B
TypeScript
23 lines
641 B
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { readTextFile } from '@tauri-apps/api/fs';
|
|
import type { HttpResponse } from '../lib/models';
|
|
|
|
export function useResponseBodyText(response: HttpResponse) {
|
|
return useQuery<string | null>({
|
|
queryKey: ['response-body-text', response?.updatedAt],
|
|
initialData: null,
|
|
queryFn: async () => {
|
|
if (response.body) {
|
|
const uint8Array = Uint8Array.of(...response.body);
|
|
return new TextDecoder().decode(uint8Array);
|
|
}
|
|
|
|
if (response.bodyPath) {
|
|
return await readTextFile(response.bodyPath);
|
|
}
|
|
|
|
return null;
|
|
},
|
|
}).data;
|
|
}
|