feat: upgrade to rust nostr 0.28

This commit is contained in:
2024-02-17 09:29:37 +07:00
parent f28a7ae82f
commit f47eba5af7
16 changed files with 352 additions and 210 deletions

View File

@@ -16,35 +16,39 @@ pub fn fetch_opg(url: String) -> Result<OpenGraphResponse, ()> {
options.max_redirections = 3;
options.timeout = Duration::from_secs(15);
let info = Webpage::from_url(&url, options).expect("Failed");
let html = info.html;
let info = Webpage::from_url(&url, options);
let result = OpenGraphResponse {
title: html
.opengraph
.properties
.get("title")
.cloned()
.unwrap_or_default(),
description: html
.opengraph
.properties
.get("description")
.cloned()
.unwrap_or_default(),
url: html
.opengraph
.properties
.get("url")
.cloned()
.unwrap_or_default(),
image: html
.opengraph
.images
.get(0)
.and_then(|i| Some(i.url.clone()))
.unwrap_or_default(),
};
if let Ok(data) = info {
let html = data.html;
let result = OpenGraphResponse {
title: html
.opengraph
.properties
.get("title")
.cloned()
.unwrap_or_default(),
description: html
.opengraph
.properties
.get("description")
.cloned()
.unwrap_or_default(),
url: html
.opengraph
.properties
.get("url")
.cloned()
.unwrap_or_default(),
image: html
.opengraph
.images
.get(0)
.and_then(|i| Some(i.url.clone()))
.unwrap_or_default(),
};
Ok(result.into())
Ok(result.into())
} else {
Err(())
}
}