From 37b91af118976f9fbb2f1fcd1ac1cee51231e507 Mon Sep 17 00:00:00 2001 From: Iewnfod Date: Thu, 25 May 2023 10:49:19 +0800 Subject: [PATCH] File system auto refresh & Status bar --- Cargo.lock | 233 +++++++++++++++++++++++++++++++++++++++++++--- Cargo.toml | 1 + src/main.rs | 80 +++++++++++++++- src/ui.rs | 45 +++++++-- src/ui/network.rs | 37 ++++++-- 5 files changed, 360 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 348bd46..b4988ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -44,6 +44,12 @@ version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + [[package]] name = "cfg-if" version = "1.0.0" @@ -81,7 +87,7 @@ version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "crossbeam-utils", ] @@ -91,7 +97,7 @@ version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -100,7 +106,7 @@ version = "0.8.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -133,6 +139,18 @@ dependencies = [ "instant", ] +[[package]] +name = "filetime" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cbc844cecaee9d4443931972e1289c8ff485cb4cc2767cb03ca139ed6885153" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall 0.2.16", + "windows-sys 0.48.0", +] + [[package]] name = "fltk" version = "1.4.3" @@ -185,6 +203,41 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fsevent" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6" +dependencies = [ + "bitflags 1.3.2", + "fsevent-sys", +] + +[[package]] +name = "fsevent-sys" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f41b048a94555da0f42f1d632e2e19510084fb8e303b0daa2816e733fb3644a0" +dependencies = [ + "libc", +] + +[[package]] +name = "fuchsia-zircon" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +dependencies = [ + "bitflags 1.3.2", + "fuchsia-zircon-sys", +] + +[[package]] +name = "fuchsia-zircon-sys" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" + [[package]] name = "futures-channel" version = "0.3.28" @@ -229,6 +282,7 @@ name = "get_paper_rs" version = "0.1.0" dependencies = [ "fltk", + "hotwatch", "open", "reqwest", "serde", @@ -278,6 +332,16 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +[[package]] +name = "hotwatch" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39301670a6f5798b75f36a1b149a379a50df5aa7c71be50f4b41ec6eab445cb8" +dependencies = [ + "log", + "notify", +] + [[package]] name = "http" version = "0.2.9" @@ -369,13 +433,33 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "inotify" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4816c66d2c8ae673df83366c18341538f234a26d65a9ecea5c348b453ac1d02f" +dependencies = [ + "bitflags 1.3.2", + "inotify-sys", + "libc", +] + +[[package]] +name = "inotify-sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" +dependencies = [ + "libc", +] + [[package]] name = "instant" version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -389,6 +473,15 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "iovec" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" +dependencies = [ + "libc", +] + [[package]] name = "ipnet" version = "2.7.2" @@ -429,12 +522,28 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "libc" version = "0.2.144" @@ -463,7 +572,7 @@ version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -472,6 +581,25 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "mio" +version = "0.6.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" +dependencies = [ + "cfg-if 0.1.10", + "fuchsia-zircon", + "fuchsia-zircon-sys", + "iovec", + "kernel32-sys", + "libc", + "log", + "miow", + "net2", + "slab", + "winapi 0.2.8", +] + [[package]] name = "mio" version = "0.8.6" @@ -484,6 +612,30 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "mio-extras" +version = "2.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" +dependencies = [ + "lazycell", + "log", + "mio 0.6.23", + "slab", +] + +[[package]] +name = "miow" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" +dependencies = [ + "kernel32-sys", + "net2", + "winapi 0.2.8", + "ws2_32-sys", +] + [[package]] name = "native-tls" version = "0.2.11" @@ -502,6 +654,35 @@ dependencies = [ "tempfile", ] +[[package]] +name = "net2" +version = "0.2.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d0df99cfcd2530b2e694f6e17e7f37b8e26bb23983ac530c0c97408837c631" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "notify" +version = "4.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae03c8c853dba7bfd23e571ff0cff7bc9dceb40a4cd684cd1681824183f45257" +dependencies = [ + "bitflags 1.3.2", + "filetime", + "fsevent", + "fsevent-sys", + "inotify", + "libc", + "mio 0.6.23", + "mio-extras", + "walkdir", + "winapi 0.3.9", +] + [[package]] name = "num_cpus" version = "1.15.0" @@ -535,7 +716,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01b8574602df80f7b85fdfc5392fa884a4e3b3f4f35402c070ab34c3d3f78d56" dependencies = [ "bitflags 1.3.2", - "cfg-if", + "cfg-if 1.0.0", "foreign-types", "libc", "once_cell", @@ -588,7 +769,7 @@ version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "redox_syscall 0.2.16", "smallvec", @@ -842,7 +1023,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" dependencies = [ "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -862,7 +1043,7 @@ version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "fastrand", "redox_syscall 0.3.5", "rustix", @@ -893,7 +1074,7 @@ dependencies = [ "autocfg", "bytes", "libc", - "mio", + "mio 0.8.6", "num_cpus", "parking_lot", "pin-project-lite", @@ -950,7 +1131,7 @@ version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "pin-project-lite", "tracing-core", ] @@ -1046,7 +1227,7 @@ version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5bba0e8cb82ba49ff4e229459ff22a191bbe9a1cb3a341610c9c33efc27ddf73" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "wasm-bindgen-macro", ] @@ -1071,7 +1252,7 @@ version = "0.4.36" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d1985d03709c53167ce907ff394f5316aa22cb4e12761295c5dc57dacb6297e" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "js-sys", "wasm-bindgen", "web-sys", @@ -1116,6 +1297,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + [[package]] name = "winapi" version = "0.3.9" @@ -1126,6 +1313,12 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -1138,7 +1331,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1300,5 +1493,15 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ - "winapi", + "winapi 0.3.9", +] + +[[package]] +name = "ws2_32-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" +dependencies = [ + "winapi 0.2.8", + "winapi-build", ] diff --git a/Cargo.toml b/Cargo.toml index 25db808..18543ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,4 @@ serde_derive = "*" serde_json = "*" walkdir = "2.3.3" open = "*" +hotwatch = "0.4.6" diff --git a/src/main.rs b/src/main.rs index 34bc0c4..d36b6b2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,37 @@ use fltk::prelude::*; use ui::Message; mod ui; +fn get_result_path(changed_path: std::path::PathBuf) -> String { + let path_str = changed_path.to_str().unwrap(); + let split_path: Vec<&str> = path_str.split('/').collect(); + let mut result_path = std::string::String::from(ui::data::SAVE_DIR); + let mut save_dir_level = split_path.len(); + for path_level in 0..split_path.len() { + // 如果到了那一级,那就标记为这个位置 + if split_path[path_level] == ui::data::SAVE_DIR { + save_dir_level = path_level; + } + // 如果在后面就表示要加进去了 + if path_level > save_dir_level { + result_path.push_str(format!("/{}", split_path[path_level]).as_str()); + } + } + // println!("Result Path: {}", result_path); + result_path +} + +#[derive(Clone, Copy)] +enum FileSystemOperation { + Create, + Remove, + None +} + +static mut FILE_SYSTEM_REFRESH_PATH: String = std::string::String::new(); +static mut FILE_SYSTEM_OPERATION: FileSystemOperation = FileSystemOperation::None; + + +// main #[tokio::main] async fn main() { // 初始化一些东西 @@ -13,24 +44,63 @@ async fn main() { let mut app = fltk::app::App::default(); app.set_scheme(fltk::app::Scheme::Gtk); let (sender, receiver) = fltk::app::channel::(); - let mut root = fltk::window::Window::new(100, 100, 850, 900, "Main Window"); + let mut root = fltk::window::Window::new(100, 100, 850, 930, "Main Window"); root.resizable(&root); - let mut buffer = ui::add_widgets(&mut root, sender); + let mut buffer: ui::Buffer = ui::add_widgets(&mut root, sender); + + let mut watcher = hotwatch::Hotwatch::new().expect("Failed to initialize hotwatch!"); + watcher.watch(ui::data::SAVE_DIR, + |e: hotwatch::Event| { + println!("{:?}", e); + if let hotwatch::Event::Create(changed_path) = e { + // 如果是写入文件 + unsafe { FILE_SYSTEM_REFRESH_PATH = get_result_path(changed_path) }; + unsafe { FILE_SYSTEM_OPERATION = FileSystemOperation::Create }; + } else if let hotwatch::Event::Remove(changed_path) = e { + unsafe { FILE_SYSTEM_REFRESH_PATH = get_result_path(changed_path) }; + unsafe { FILE_SYSTEM_OPERATION = FileSystemOperation::Remove }; + } else if let hotwatch::Event::Rename(original_path, target_path) = e { + unsafe { FILE_SYSTEM_REFRESH_PATH = get_result_path(original_path) }; + unsafe { FILE_SYSTEM_OPERATION = FileSystemOperation::Remove }; + unsafe { FILE_SYSTEM_REFRESH_PATH = get_result_path(target_path) }; + unsafe { FILE_SYSTEM_OPERATION = FileSystemOperation::Create }; + } + } + ).unwrap(); root.show(); // app.run().unwrap(); while app.wait() { - app.redraw(); + // 刷新状态栏 + buffer.status_bar.set_value(unsafe { &ui::STATUS_BAR_CONTENT }); + // 文件系统刷新机制 + if unsafe { !FILE_SYSTEM_REFRESH_PATH.is_empty() } { + println!("Refresh Path: {}", unsafe { FILE_SYSTEM_REFRESH_PATH.as_str() }); + let file_system_refresh_path = unsafe { FILE_SYSTEM_REFRESH_PATH.as_str() }; + match unsafe { FILE_SYSTEM_OPERATION } { + FileSystemOperation::Create => { + buffer.refresh_file_system(file_system_refresh_path); + }, + FileSystemOperation::Remove => { + buffer.remove_file_system_node(file_system_refresh_path); + }, + FileSystemOperation::None => {} + } + unsafe { FILE_SYSTEM_REFRESH_PATH.clear() }; + unsafe { FILE_SYSTEM_OPERATION = FileSystemOperation::None }; + } + if let Some(msg) = receiver.recv() { match msg { Message::Start => { let buffer_clone = buffer.clone(); println!("Start"); - ui::network::start(buffer_clone).await; - buffer.refresh_file_system(); // 刷新左侧文件系统 + tokio::spawn(async move { + ui::network::start(buffer_clone).await; + }); } } } diff --git a/src/ui.rs b/src/ui.rs index b4d2970..fb6073d 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -3,6 +3,12 @@ use fltk::{prelude::*, *, enums::Color}; pub mod data; pub mod network; +pub static mut STATUS_BAR_CONTENT: String = std::string::String::new(); + +pub fn change_status_bar_content(s: &String) { + unsafe { STATUS_BAR_CONTENT = s.to_string() }; +} + #[derive(Copy, Clone)] pub enum Message { Start @@ -13,6 +19,7 @@ pub struct Buffer { pub check_bts: Vec<(button::CheckButton, String, String)>, // [bt, code, label] pub min_year_input: input::IntInput, pub max_year_input: input::IntInput, + pub status_bar: output::Output, file_system: tree::Tree, sender: app::Sender } @@ -24,13 +31,14 @@ impl Buffer { min_year_input: input::IntInput::default(), max_year_input: input::IntInput::default(), file_system: tree::Tree::default(), + status_bar: output::Output::default(), sender: sender } } - pub fn refresh_file_system(&mut self) { - self.file_system.clear(); - for f_result in walkdir::WalkDir::new(data::SAVE_DIR) { + pub fn refresh_file_system(&mut self, root_path: &str) { + // self.file_system.clear(); + for f_result in walkdir::WalkDir::new(root_path) { let f = f_result.unwrap(); if f.file_name() == ".DS_Store" { continue; @@ -38,6 +46,25 @@ impl Buffer { self.file_system.add(f.path().to_str().unwrap()); } } + + pub fn remove_file_system_node(&mut self, node_path: &str) { + let items = self.file_system.get_items().unwrap(); + for item in items { + if self.file_system.item_pathname(&item).unwrap() == node_path { + self.file_system.remove(&item).unwrap(); + } + } + } + + pub fn close_all_nodes(&mut self) { + let nodes = self.file_system.get_items().unwrap(); + for mut node in nodes { + if node.is_root() || node.label().unwrap() == data::SAVE_DIR { + continue; + } + node.close(); + } + } } pub fn add_widgets(root: &mut window::Window, sender: app::Sender) -> Buffer { @@ -48,7 +75,7 @@ pub fn add_widgets(root: &mut window::Window, sender: app::Sender) -> B // 组件初始化 let flex = group::Flex::default() .with_pos(5, 5) - .with_size(root.width() - 10, root.height() - 10) + .with_size(root.width() - 10, root.height() - 35) .row(); let left_flex = group::Flex::default() @@ -94,8 +121,7 @@ pub fn add_widgets(root: &mut window::Window, sender: app::Sender) -> B let mut mid_label = output::Output::default(); mid_label.set_value("to"); - mid_label.set_frame(enums::FrameType::NoBox); - mid_label.set_readonly(true); + mid_label.set_frame(enums::FrameType::FlatBox); buffer.max_year_input = input::IntInput::default(); buffer.max_year_input.set_value("2022"); @@ -112,9 +138,14 @@ pub fn add_widgets(root: &mut window::Window, sender: app::Sender) -> B flex.end(); + buffer.status_bar = output::Output::default() + .with_size(root.width() - 10, 20) + .with_pos(5, flex.height() + 10); + root.end(); - buffer.refresh_file_system(); + buffer.refresh_file_system(data::SAVE_DIR); + buffer.close_all_nodes(); buffer } diff --git a/src/ui/network.rs b/src/ui/network.rs index 5f35ff1..3330e7e 100644 --- a/src/ui/network.rs +++ b/src/ui/network.rs @@ -1,11 +1,14 @@ use fltk::{prelude::*}; use std::collections::HashMap; +use crate::ui::change_status_bar_content; + use super::{Buffer, data}; pub async fn start(buffer: Buffer) -> () { let min_year: isize = buffer.min_year_input.value().parse().unwrap(); let max_year: isize = buffer.max_year_input.value().parse().unwrap(); + println!("From {} to {}", min_year, max_year); let check_bts = buffer.check_bts.clone(); for (bt, code, name) in check_bts { if bt.value() { @@ -14,6 +17,7 @@ pub async fn start(buffer: Buffer) -> () { println!("{}", year); for season in data::SEASONS { println!("{}", season); + change_status_bar_content(&format!("Searching: {} | {} | {}", &name, year, &season)); let available_files = search_file(&code, year.to_string().as_str(), season).await; @@ -22,14 +26,19 @@ pub async fn start(buffer: Buffer) -> () { if available_files["status"] == 0 { let files_value = &available_files["data"]; if let Some(files) = files_value.as_array() { - for i in files.iter(){ + for i in files.iter() { let file_name = i[0].to_string(); let file_name = file_name[1..file_name.len()-1].to_string(); println!("{}", file_name); let mut url = data::FETCH_URL.to_string(); url.push_str(&file_name.as_str()); let save_path = format!("{}/{}/{}/{}", data::SAVE_DIR, &name, year, file_name); - download(&url, &save_path).await; + change_status_bar_content(&format!("Downloading: {}", &save_path)); + let mut status = download(&url, &save_path).await; + while !status { + println!("Retry: {}", save_path); + status = download(&url, &save_path).await; + } } } } @@ -60,23 +69,33 @@ async fn search_file(subject: &str, year: &str, season: &str) -> serde_json::Val return result; } -async fn download(url: &String, save_path: &String) { +async fn download(url: &String, save_path: &String) -> bool { // 创建文件以及其存在的目录 let path = std::path::Path::new(save_path); if path.exists() { - return ; + return true; } let prefix = path.parent().unwrap(); std::fs::create_dir_all(prefix).unwrap(); // 发送请求,获取文件 - let result = reqwest::get(url) + let response = reqwest::get(url) .await - .unwrap() - .bytes() + .unwrap(); + + println!("{} : {}", save_path, response.status()); + + // 判断是否成功 + if response.status().is_success() { + let result = response.bytes() .await .unwrap(); - // 写入文件 - std::fs::write(path, result).unwrap(); + // 写入文件 + std::fs::write(path, result).unwrap(); + return true; + + } else { + return false; + } }