feature(sender): change the behavour to only show the transfer name if relay and local room0ids are send to realy server
This commit is contained in:
parent
19f6b24e0f
commit
f321b6bc6c
2 changed files with 52 additions and 34 deletions
|
|
@ -155,24 +155,35 @@ fn on_create_room(
|
|||
debug!("Got Result: {:?}", res);
|
||||
// Print a newline to the console to separate the output from the command
|
||||
// line.
|
||||
println!();
|
||||
match res {
|
||||
Ok(transfer_response) => {
|
||||
if !transfer_response.local_room_id.is_empty()
|
||||
&& !transfer_response.relay_room_id.is_empty()
|
||||
{
|
||||
println!();
|
||||
|
||||
// Try to generate a QR code from the URL. If the function fails for some
|
||||
// reason, print an error message to the console.
|
||||
// if let Err(error) = qr2term::print_qr(&url) {
|
||||
// error!("Failed to generate QR code: {}", error);
|
||||
// }
|
||||
// Try to generate a QR code from the URL. If the function fails for some
|
||||
// reason, print an error message to the console.
|
||||
// if let Err(error) = qr2term::print_qr(&url) {
|
||||
// error!("Failed to generate QR code: {}", error);
|
||||
// }
|
||||
|
||||
if let Err(error) = qr2term::print_qr(&transfer_name) {
|
||||
error!("Failed to generate QR code: {}", error);
|
||||
if let Err(error) = qr2term::print_qr(&transfer_name) {
|
||||
error!("Failed to generate QR code: {}", error);
|
||||
}
|
||||
// Print a newline to the console to separate the output from the command
|
||||
// line.
|
||||
println!();
|
||||
|
||||
// Print a message to the console with the URL.
|
||||
println!("Created room: {}", url);
|
||||
println!("Transfername is: {}", transfer_name);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Error sending info: {e}");
|
||||
}
|
||||
}
|
||||
// Print a newline to the console to separate the output from the command
|
||||
// line.
|
||||
println!();
|
||||
|
||||
// Print a message to the console with the URL.
|
||||
println!("Created room: {}", url);
|
||||
println!("Transfername is: {}", transfer_name);
|
||||
|
||||
// Continue the event loop.
|
||||
Status::Continue()
|
||||
|
|
|
|||
|
|
@ -5,9 +5,16 @@ use local_ip_address::{local_ip, local_ipv6};
|
|||
use reqwest::blocking::Client;
|
||||
use tokio::task;
|
||||
|
||||
use crate::relay::transfer::{TransferRequest, TransferResponse};
|
||||
|
||||
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
||||
|
||||
pub async fn send_info(relay: &str, name: &str, room_id: &str, is_local: bool) -> Result<String> {
|
||||
pub async fn send_info(
|
||||
relay: &str,
|
||||
name: &str,
|
||||
room_id: &str,
|
||||
is_local: bool,
|
||||
) -> Result<TransferResponse> {
|
||||
let url = relay.to_string();
|
||||
let sender_ip = match local_ipv6() {
|
||||
Ok(ip) => ip,
|
||||
|
|
@ -20,31 +27,31 @@ pub async fn send_info(relay: &str, name: &str, room_id: &str, is_local: bool) -
|
|||
},
|
||||
};
|
||||
let ip_str = sender_ip.to_owned().to_string();
|
||||
let map = {
|
||||
let mut map = HashMap::new();
|
||||
map.insert("name", String::from(name));
|
||||
map.insert("ip", ip_str);
|
||||
if is_local {
|
||||
map.insert("local_room_id", String::from(room_id));
|
||||
map.insert("relay_room_id", String::from(""));
|
||||
|
||||
let transfer_request = TransferRequest {
|
||||
name: String::from(name),
|
||||
ip: ip_str,
|
||||
local_room_id: if is_local {
|
||||
String::from(room_id)
|
||||
} else {
|
||||
map.insert("relay_room_id", String::from(room_id));
|
||||
map.insert("local_room_id", String::from(""));
|
||||
}
|
||||
map
|
||||
String::from("")
|
||||
},
|
||||
relay_room_id: if !is_local {
|
||||
String::from(room_id)
|
||||
} else {
|
||||
String::from("")
|
||||
},
|
||||
};
|
||||
let room_id = room_id.to_string();
|
||||
|
||||
debug!("Trying to send Request.");
|
||||
let result: Result<String> = task::spawn_blocking(move || {
|
||||
let result: Result<TransferResponse> = task::spawn_blocking(move || {
|
||||
let client = Client::new();
|
||||
client
|
||||
let response = client
|
||||
.put(format!("{}/upload", url))
|
||||
.json(&map)
|
||||
.json(&transfer_request)
|
||||
.send()?
|
||||
.text()?
|
||||
.to_string();
|
||||
Ok(room_id)
|
||||
.json()?;
|
||||
Ok(response)
|
||||
})
|
||||
.await?;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue