AirLibrary/Client/AirClient/
DownloadUpdate.rs1use std::collections::HashMap;
8
9use tonic::Request;
10
11use crate::{
12 AirError,
13 Client::AirClient::{AirClient, FileInfo},
14 Vine::Generated::air::DownloadRequest,
15 dev_log,
16};
17
18impl AirClient {
19 pub async fn DownloadUpdate(
29 &self,
30
31 request_id:String,
32
33 url:String,
34
35 destination_path:String,
36
37 checksum:String,
38
39 headers:HashMap<String, String>,
40 ) -> Result<FileInfo::Struct, AirError> {
41 dev_log!("grpc", "[AirClient] Downloading update from: {}", url);
42
43 let RequestPayload = DownloadRequest { request_id, url, destination_path, checksum, headers };
44
45 let Client = self
46 .Client()
47 .ok_or_else(|| AirError::Network("Air client not initialized".to_string()))?;
48
49 let mut ClientGuard = Client.lock().await;
50
51 match ClientGuard.download_update(Request::new(RequestPayload)).await {
52 Ok(Response) => {
53 let Response = Response.into_inner();
54
55 if Response.success {
56 dev_log!("grpc", "[AirClient] Update downloaded successfully to: {}", Response.file_path);
57
58 Ok(FileInfo::Struct {
59 file_path:Response.file_path,
60 file_size:Response.file_size,
61 checksum:Response.checksum,
62 })
63 } else {
64 dev_log!("grpc", "error: [AirClient] Update download failed: {}", Response.error);
65
66 Err(AirError::Network(Response.error))
67 }
68 },
69
70 Err(Status) => {
71 dev_log!("grpc", "error: [AirClient] Download update RPC error: {}", Status);
72
73 Err(AirError::Network(format!("Download update RPC error: {}", Status)))
74 },
75 }
76 }
77}