use http_req::{
request::{Method, Request},
uri::Uri,
};
pub async fn text_detection(image_base64: String) -> Result<String, String> {
let flows_user = unsafe { crate::_get_flows_user() };
let flow_id = unsafe { crate::_get_flow_id() };
let mut writer = Vec::new();
let uri = format!(
"{}/{}/{}/cloud-vision/text-detection",
crate::GOOGLE_CLOUD_SERVICE_API_PREFIX.as_str(),
flows_user,
flow_id,
);
let uri = Uri::try_from(uri.as_str()).unwrap();
let body = image_base64.as_bytes();
match Request::new(&uri)
.method(Method::POST)
.header("Content-Type", "text/plain")
.header("Content-Length", &body.len())
.body(body)
.send(&mut writer)
{
Ok(res) => match res.status_code().is_success() {
true => Ok(String::from_utf8_lossy(&writer).into_owned()),
false => Err(String::from_utf8_lossy(&writer).into_owned()),
},
Err(e) => {
return Err(e.to_string());
}
}
}