no password required for file transfer action in remote control menu (#9731)

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages
2024-10-24 17:20:48 +08:00
committed by GitHub
parent 7a3e1fe648
commit 445e9ac285
16 changed files with 222 additions and 52 deletions

View File

@@ -11,6 +11,7 @@ use crossbeam_queue::ArrayQueue;
use magnum_opus::{Channels::*, Decoder as AudioDecoder};
#[cfg(not(any(target_os = "android", target_os = "linux")))]
use ringbuf::{ring_buffer::RbBase, Rb};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use std::{
collections::HashMap,
@@ -1274,7 +1275,7 @@ impl VideoHandler {
}
// The source of sent password
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
enum PasswordSource {
PersonalAb(Vec<u8>),
SharedAb(String),
@@ -1320,6 +1321,13 @@ impl PasswordSource {
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
struct ConnToken {
password: Vec<u8>,
password_source: PasswordSource,
session_id: u64,
}
/// Login config handler for [`Client`].
#[derive(Default)]
pub struct LoginConfigHandler {
@@ -1376,6 +1384,7 @@ impl LoginConfigHandler {
mut force_relay: bool,
adapter_luid: Option<i64>,
shared_password: Option<String>,
conn_token: Option<String>,
) {
let mut id = id;
if id.contains("@") {
@@ -1419,10 +1428,22 @@ impl LoginConfigHandler {
let config = self.load_config();
self.remember = !config.password.is_empty();
self.config = config;
let mut sid = rand::random();
let conn_token = conn_token
.map(|x| serde_json::from_str::<ConnToken>(&x).ok())
.flatten();
let mut sid = 0;
if let Some(token) = conn_token {
sid = token.session_id;
self.password = token.password; // use as last password
self.password_source = token.password_source;
}
if sid == 0 {
// you won the lottery
sid = 1;
sid = rand::random();
if sid == 0 {
// you won the lottery
sid = 1;
}
}
self.session_id = sid;
self.supported_encoding = Default::default();
@@ -2223,6 +2244,18 @@ impl LoginConfigHandler {
msg_out.set_misc(misc);
msg_out
}
pub fn get_conn_token(&self) -> Option<String> {
if self.password.is_empty() {
return None;
}
serde_json::to_string(&ConnToken {
password: self.password.clone(),
password_source: self.password_source.clone(),
session_id: self.session_id,
})
.ok()
}
}
/// Media data.