mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-20 16:43:53 +01:00
Support binary responses!
This commit is contained in:
21
src-web/hooks/useResponseBodyText.ts
Normal file
21
src-web/hooks/useResponseBodyText.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
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) {
|
||||
return String.fromCharCode.apply(null, response.body);
|
||||
}
|
||||
|
||||
if (response.bodyPath) {
|
||||
return await readTextFile(response.bodyPath);
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
}).data;
|
||||
}
|
||||
Reference in New Issue
Block a user