diff --git a/Cargo.toml b/Cargo.toml index f0b9663..ffb6da1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pbbot-rq" -version = "0.1.6" +version = "0.1.7" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/error.rs b/src/error.rs index 92b0057..9183e1a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -17,6 +17,8 @@ pub enum RCError { Timeout, #[error("client_not_found error")] ClientNotFound, + #[error("protocol_not_supported error")] + ProtocolNotSupported, #[error("io error, {0}")] IO(#[from] io::Error), #[error("websocket error, {0}")] @@ -39,6 +41,7 @@ impl IntoResponse for RCError { fn into_response(self) -> Response { let code = match self { Self::ClientNotFound => StatusCode::BAD_REQUEST, + Self::ProtocolNotSupported => StatusCode::BAD_REQUEST, _ => StatusCode::INTERNAL_SERVER_ERROR, }; (code, self.to_string()).into_response() diff --git a/src/handler/qrcode.rs b/src/handler/qrcode.rs index 50ecf65..cdb80a9 100644 --- a/src/handler/qrcode.rs +++ b/src/handler/qrcode.rs @@ -72,7 +72,11 @@ pub struct CreateClientResp { pub async fn create(Json(req): Json) -> RCResult> { let rand_seed = req.device_seed.unwrap_or_else(rand::random); let device = Device::random_with_rng(&mut StdRng::seed_from_u64(rand_seed)); - let protocol = Protocol::from_u8(req.protocol); + let protocol = match Protocol::from_u8(req.protocol) { + Protocol::MacOS => Protocol::MacOS, + Protocol::AndroidWatch => Protocol::AndroidWatch, + _ => return Err(RCError::ProtocolNotSupported), + }; let (sender, receiver) = tokio::sync::broadcast::channel(10); let cli = Arc::new(Client::new(device, get_version(protocol), sender)); let stream = tokio::net::TcpStream::connect(cli.get_address())