Add support for search suggestions.

This commit is contained in:
FireMasterK 2021-04-30 11:56:27 +05:30
parent d81633205f
commit dacbdab7d6
No known key found for this signature in database
GPG key ID: 8DFF5DD33E93DB58
3 changed files with 41 additions and 14 deletions

View file

@ -58,13 +58,7 @@ pub mod piped {
.append_pair("url", nexturl.as_str())
.append_pair("id", nextbody.as_str());
let resp = &self
.httpclient
.get(url.as_str())
.send()
.await?
.text()
.await?;
let resp = &self.httpclient.get(url).send().await?.text().await?;
let streams: StreamsPage = serde_json::from_str(resp.as_str())?;
@ -100,13 +94,7 @@ pub mod piped {
.append_pair("url", nexturl.as_str())
.append_pair("id", nextbody.as_str());
let resp = &self
.httpclient
.get(url.as_str())
.send()
.await?
.text()
.await?;
let resp = &self.httpclient.get(url).send().await?.text().await?;
let streams: StreamsPage = serde_json::from_str(resp.as_str())?;
@ -129,6 +117,20 @@ pub mod piped {
Ok(video)
}
pub async fn get_search_suggestions(
&self,
q: String,
) -> Result<Vec<String>, Box<dyn std::error::Error>> {
let mut url = Url::parse(format!("{}/suggestions", &self.instance).as_str())?;
url.query_pairs_mut().append_pair("query", q.as_str());
let resp = &self.httpclient.get(url).send().await?.text().await?;
let suggestions: Vec<String> = serde_json::from_str(resp.as_str())?;
Ok(suggestions)
}
}
#[derive(Deserialize, Debug)]