mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 00:58:32 +02:00
Always store response on filesystem
This commit is contained in:
@@ -224,25 +224,27 @@ async fn actually_send_ephemeral_request(
|
|||||||
response.url = v.url().to_string();
|
response.url = v.url().to_string();
|
||||||
let body_bytes = v.bytes().await.expect("Failed to get body").to_vec();
|
let body_bytes = v.bytes().await.expect("Failed to get body").to_vec();
|
||||||
response.content_length = Some(body_bytes.len() as i64);
|
response.content_length = Some(body_bytes.len() as i64);
|
||||||
if body_bytes.len() > 1000 {
|
let dir = app_handle.path_resolver().app_data_dir().unwrap();
|
||||||
let dir = app_handle.path_resolver().app_data_dir().unwrap();
|
let body_path = dir.join(response.id.clone());
|
||||||
let body_path = dir.join(response.id.clone());
|
let mut f = File::options()
|
||||||
let mut f = File::options()
|
.create(true)
|
||||||
.create(true)
|
.write(true)
|
||||||
.write(true)
|
.open(&body_path)
|
||||||
.open(&body_path)
|
.expect("Failed to open file");
|
||||||
.expect("Failed to open file");
|
f.write_all(body_bytes.as_slice())
|
||||||
f.write_all(body_bytes.as_slice())
|
.expect("Failed to write to file");
|
||||||
.expect("Failed to write to file");
|
|
||||||
response.body_path = Some(
|
// Also story body directly on the model, if small enough
|
||||||
body_path
|
if body_bytes.len() < 100_000 {
|
||||||
.to_str()
|
|
||||||
.expect("Failed to get body path")
|
|
||||||
.to_string(),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
response.body = Some(body_bytes);
|
response.body = Some(body_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response.body_path = Some(
|
||||||
|
body_path
|
||||||
|
.to_str()
|
||||||
|
.expect("Failed to get body path")
|
||||||
|
.to_string(),
|
||||||
|
);
|
||||||
response.elapsed = start.elapsed().as_millis() as i64;
|
response.elapsed = start.elapsed().as_millis() as i64;
|
||||||
response = models::update_response_if_id(&response, pool)
|
response = models::update_response_if_id(&response, pool)
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -2,16 +2,16 @@ import { useQuery } from '@tanstack/react-query';
|
|||||||
import { readBinaryFile } from '@tauri-apps/api/fs';
|
import { readBinaryFile } from '@tauri-apps/api/fs';
|
||||||
import type { HttpResponse } from '../lib/models';
|
import type { HttpResponse } from '../lib/models';
|
||||||
|
|
||||||
export function useResponseBodyBlob(response: HttpResponse | null) {
|
export function useResponseBodyBlob(response: HttpResponse) {
|
||||||
return useQuery<Uint8Array | null>({
|
return useQuery<Uint8Array | null>({
|
||||||
enabled: response != null,
|
enabled: response != null,
|
||||||
queryKey: ['response-body-binary', response?.updatedAt],
|
queryKey: ['response-body-binary', response?.updatedAt],
|
||||||
initialData: null,
|
initialData: null,
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
if (response?.body) {
|
if (response.body) {
|
||||||
return Uint8Array.of(...response.body);
|
return Uint8Array.of(...response.body);
|
||||||
}
|
}
|
||||||
if (response?.bodyPath) {
|
if (response.bodyPath) {
|
||||||
return readBinaryFile(response.bodyPath);
|
return readBinaryFile(response.bodyPath);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user