Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions desktop/src-tauri/Cargo.lock

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

1 change: 1 addition & 0 deletions desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ nostr = { version = "0.44", features = ["nip44", "nip49"] }
# transitive dependency; pinned here for direct use).
getrandom = "0.2"
zeroize = "1"
percent-encoding = "2"
reqwest = { version = "0.13", features = ["json", "query", "stream", "blocking"] }
rustls = { version = "0.23", default-features = false, features = ["aws_lc_rs", "std"] }
url = "2"
Expand Down
9 changes: 7 additions & 2 deletions desktop/src-tauri/src/commands/link_preview.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::{io::Cursor, net::IpAddr, time::Duration};

use base64::{engine::general_purpose::STANDARD as BASE64_STANDARD, Engine as _};
use image::ImageDecoder;

use futures_util::StreamExt;
use image::ImageDecoder;
use reqwest::{
header::{ACCEPT, CONTENT_TYPE, LOCATION, USER_AGENT},
redirect::Policy,
Expand All @@ -13,6 +12,8 @@ use url::Url;

#[path = "link_preview_rate_limit.rs"]
mod rate_limit;
#[path = "link_preview_youtube.rs"]
mod youtube;

use rate_limit::{image_host_cooldown_remaining, retry_after_duration, set_image_host_cooldown};

Expand Down Expand Up @@ -67,6 +68,10 @@ async fn fetch_link_preview_metadata_inner(
let mut url = Url::parse(href.trim()).map_err(|error| format!("invalid URL: {error}"))?;
validate_public_https_url(&url).await?;

if youtube::is_video_url(&url) {
return youtube::fetch_oembed_metadata(&url).await;
}

for redirect_count in 0..=MAX_REDIRECTS {
let response = send_pinned_request(&url, "text/html,application/xhtml+xml;q=0.9").await?;

Expand Down
Loading
Loading