Skip to content

Commit

Permalink
Replace reqwest with ureq. blocking reqwest call doesn't work inside …
Browse files Browse the repository at this point in the history
…tokio runtime
  • Loading branch information
Exidex committed Jul 21, 2024
1 parent e74c128 commit 5190db5
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 87 deletions.
148 changes: 68 additions & 80 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion dev_plugin/src/detail-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ReactElement, useEffect, useState } from 'react';
import upperCase from "lodash/upperCase";
import { Action, ActionPanel, Detail, Icons } from "@project-gauntlet/api/components";
import { useNavigation } from "@project-gauntlet/api/hooks";
import { assetData, pluginPreferences, entrypointPreferences, Clipboard } from "@project-gauntlet/api/helpers";
import { Clipboard, entrypointPreferences, pluginPreferences } from "@project-gauntlet/api/helpers";

async function readFile(url: string): Promise<Blob> {
const res = await fetch(url);
Expand Down Expand Up @@ -112,6 +112,7 @@ export default function DetailView(): ReactElement {
<Detail.Content.H5>H5 Title</Detail.Content.H5>
<Detail.Content.H6>H6 Title</Detail.Content.H6>
<Detail.Content.Image source={{ asset: "logo.png" }}/>
<Detail.Content.Image source={{ url: "https://github.com/project-gauntlet/gauntlet/blob/main/docs/logo.png?raw=true" }}/>
<Detail.Content.CodeBlock>Code block Test</Detail.Content.CodeBlock>
<Detail.Content.HorizontalBreak/>
<Detail.Content.Paragraph>
Expand Down
2 changes: 1 addition & 1 deletion rust/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ resvg = { version = "0.41", default-features = false}
image = "0.25"
arboard = "3.4.0"
global-hotkey = "0.4.2"
reqwest = { version = "0.11.27", features = ["blocking"] }
ureq = "2.10.0"
bytes = "1.6.0"

scenario_runner = { path = "../scenario_runner", optional = true }
Expand Down
14 changes: 9 additions & 5 deletions rust/server/src/plugins/js/ui.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::cell::RefCell;
use std::collections::HashMap;
use std::io::Read;
use std::rc::Rc;
use anyhow::{anyhow, Context};
use deno_core::{op, OpState, serde_v8, v8};
Expand Down Expand Up @@ -281,8 +282,6 @@ fn convert(
convert_object(state.clone(), scope, name, value, &object_name, shared_types)
}
(Some(PropertyType::ImageSource), None) => {
println!("test: {}", debug_object_to_json(scope, value.clone()));

let source: ImageSource = serde_v8::from_v8(scope, value)?;
convert_image_source(state.clone(), name, source)
}
Expand Down Expand Up @@ -399,10 +398,15 @@ fn convert_image_source(state: Rc<RefCell<OpState>>, name: String, source: Image
Ok((name, UiPropertyValue::Bytes(bytes::Bytes::from(bytes))))
}
ImageSource::Url { url } => {
// FIXME implement error handling properly
// FIXME implement error handling so it doesn't error whole view
// TODO implement caching
let response = reqwest::blocking::get(url).expect("unable to get image");
let bytes = response.bytes().expect("unable to get image: unable to read bytes from response");

let bytes: bytes::Bytes = ureq::get(&url)
.call()?
.into_reader()
.bytes()
.collect::<std::io::Result<Vec<u8>>>()?
.into();

Ok((name, UiPropertyValue::Bytes(bytes)))
}
Expand Down

0 comments on commit 5190db5

Please sign in to comment.