mirror of
https://mirror.ghproxy.com/https://github.com/StarCitizenToolBox/app.git
synced 2024-12-23 01:53:41 +08:00
update Rust
This commit is contained in:
parent
5fa62351f2
commit
95b4b8b947
@ -300,9 +300,9 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
switch (raw[0]) {
|
||||
case 0:
|
||||
return const MyDownloaderStatus_NoStart();
|
||||
return MyDownloaderStatus_NoStart();
|
||||
case 1:
|
||||
return const MyDownloaderStatus_Running();
|
||||
return MyDownloaderStatus_Running();
|
||||
case 2:
|
||||
return MyDownloaderStatus_Pending(
|
||||
dco_decode_my_network_item_pending_type(raw[1]),
|
||||
@ -312,7 +312,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
dco_decode_String(raw[1]),
|
||||
);
|
||||
case 4:
|
||||
return const MyDownloaderStatus_Finished();
|
||||
return MyDownloaderStatus_Finished();
|
||||
default:
|
||||
throw Exception("unreachable");
|
||||
}
|
||||
@ -501,9 +501,9 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
var tag_ = sse_decode_i_32(deserializer);
|
||||
switch (tag_) {
|
||||
case 0:
|
||||
return const MyDownloaderStatus_NoStart();
|
||||
return MyDownloaderStatus_NoStart();
|
||||
case 1:
|
||||
return const MyDownloaderStatus_Running();
|
||||
return MyDownloaderStatus_Running();
|
||||
case 2:
|
||||
var var_field0 = sse_decode_my_network_item_pending_type(deserializer);
|
||||
return MyDownloaderStatus_Pending(var_field0);
|
||||
@ -511,7 +511,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
var var_field0 = sse_decode_String(deserializer);
|
||||
return MyDownloaderStatus_Error(var_field0);
|
||||
case 4:
|
||||
return const MyDownloaderStatus_Finished();
|
||||
return MyDownloaderStatus_Finished();
|
||||
default:
|
||||
throw UnimplementedError('');
|
||||
}
|
||||
|
@ -3,13 +3,17 @@ name = "rust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[profile.release]
|
||||
opt-level = "s"
|
||||
strip = "debuginfo"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "staticlib"]
|
||||
|
||||
[dependencies]
|
||||
flutter_rust_bridge = "=2.0.0-dev.23"
|
||||
http-downloader = { version = "0.3.2", features = ["status-tracker", "speed-tracker", "breakpoint-resume", "bson-file-archiver"] }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }
|
||||
url = "2.5.0"
|
||||
uuid = { version = "1.7.0", features = ["v4", "fast-rng", "macro-diagnostics"] }
|
||||
async-std = "1.12.0"
|
||||
@ -17,3 +21,4 @@ hyper = { version = "0.14.28"}
|
||||
once_cell = "1.19.0"
|
||||
reqwest = { version = "0.11", features = ["rustls-tls-native-roots", "cookies", "gzip", "brotli", "deflate", "multipart", "trust-dns", "json","stream"] }
|
||||
hickory-resolver = {version = "0.24.0", features = [ "dns-over-https-rustls","dns-over-rustls","native-certs"]}
|
||||
anyhow = "1.0"
|
||||
|
@ -2,8 +2,8 @@ use std::sync::Arc;
|
||||
use crate::downloader::{do_cancel_download, do_start_download, DownloadCallbackData};
|
||||
use crate::frb_generated::StreamSink;
|
||||
|
||||
pub fn start_download(url: String, save_path: String, file_name: String, connection_count: u8, sink: StreamSink<DownloadCallbackData>) {
|
||||
let _ = do_start_download(url, save_path, file_name, connection_count, Arc::new(sink));
|
||||
pub async fn start_download(url: String, save_path: String, file_name: String, connection_count: u8, sink: StreamSink<DownloadCallbackData>) {
|
||||
do_start_download(url, save_path, file_name, connection_count, Arc::new(sink)).await.unwrap();
|
||||
}
|
||||
|
||||
pub async fn cancel_download(id: String) {
|
||||
|
@ -1,5 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use std::error::Error;
|
||||
use std::num::{NonZeroU8, NonZeroUsize};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
@ -63,8 +62,7 @@ pub async fn do_cancel_download(id: &str) {
|
||||
d.unwrap().cancel().await
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn do_start_download(url: String, save_path: String, file_name: String, connection_count: u8, sink: Arc<StreamSink<DownloadCallbackData>>) -> Result<(), Box<dyn Error>> {
|
||||
pub async fn do_start_download(url: String, save_path: String, file_name: String, connection_count: u8, sink: Arc<StreamSink<DownloadCallbackData>>) -> anyhow::Result<()> {
|
||||
let save_dir = PathBuf::from(save_path);
|
||||
let test_url = Url::parse(&*url)?;
|
||||
|
||||
|
@ -82,44 +82,17 @@ fn wire_start_download_impl(
|
||||
rust_vec_len_: i32,
|
||||
data_len_: i32,
|
||||
) {
|
||||
FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::SseCodec, _, _>(
|
||||
flutter_rust_bridge::for_generated::TaskInfo {
|
||||
debug_name: "start_download",
|
||||
port: Some(port_),
|
||||
mode: flutter_rust_bridge::for_generated::FfiCallMode::Stream,
|
||||
},
|
||||
move || {
|
||||
let message = unsafe {
|
||||
flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire(
|
||||
ptr_,
|
||||
rust_vec_len_,
|
||||
data_len_,
|
||||
)
|
||||
};
|
||||
let mut deserializer =
|
||||
flutter_rust_bridge::for_generated::SseDeserializer::new(message);
|
||||
FLUTTER_RUST_BRIDGE_HANDLER.wrap_async::<flutter_rust_bridge::for_generated::SseCodec,_,_,_>(flutter_rust_bridge::for_generated::TaskInfo{ debug_name: "start_download", port: Some(port_), mode: flutter_rust_bridge::for_generated::FfiCallMode::Stream }, move || {
|
||||
let message = unsafe { flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire(ptr_, rust_vec_len_, data_len_) };
|
||||
let mut deserializer = flutter_rust_bridge::for_generated::SseDeserializer::new(message);
|
||||
let api_url = <String>::sse_decode(&mut deserializer);
|
||||
let api_save_path = <String>::sse_decode(&mut deserializer);
|
||||
let api_file_name = <String>::sse_decode(&mut deserializer);
|
||||
let api_connection_count = <u8>::sse_decode(&mut deserializer);
|
||||
deserializer.end();
|
||||
move |context| {
|
||||
transform_result_sse((move || {
|
||||
Result::<_, ()>::Ok(crate::api::downloader_api::start_download(
|
||||
api_url,
|
||||
api_save_path,
|
||||
api_file_name,
|
||||
api_connection_count,
|
||||
StreamSink::new(
|
||||
context
|
||||
.rust2dart_context()
|
||||
.stream_sink::<_, crate::downloader::DownloadCallbackData>(),
|
||||
),
|
||||
))
|
||||
})())
|
||||
}
|
||||
},
|
||||
)
|
||||
let api_save_path = <String>::sse_decode(&mut deserializer);
|
||||
let api_file_name = <String>::sse_decode(&mut deserializer);
|
||||
let api_connection_count = <u8>::sse_decode(&mut deserializer);deserializer.end(); move |context| async move {
|
||||
transform_result_sse((move || async move {
|
||||
Result::<_,()>::Ok(crate::api::downloader_api::start_download(api_url, api_save_path, api_file_name, api_connection_count, StreamSink::new(context.rust2dart_context().stream_sink::<_,crate::downloader::DownloadCallbackData>())).await)
|
||||
})().await)
|
||||
} })
|
||||
}
|
||||
fn wire_fetch_impl(
|
||||
port_: flutter_rust_bridge::for_generated::MessagePort,
|
||||
|
@ -43,12 +43,12 @@ impl Iterator for SocketAddrs {
|
||||
}
|
||||
}
|
||||
|
||||
fn new_resolver() -> io::Result<TokioAsyncResolver> {
|
||||
fn new_resolver() -> anyhow::Result<TokioAsyncResolver> {
|
||||
let ali_ips: &[IpAddr] = &[
|
||||
IpAddr::V4(Ipv4Addr::new(223, 5, 5, 5)),
|
||||
IpAddr::V4(Ipv4Addr::new(223, 6, 6, 6)),
|
||||
IpAddr::V6("2400:3200::1".parse::<Ipv6Addr>().unwrap()),
|
||||
IpAddr::V6("2400:3200:baba::1".parse::<Ipv6Addr>().unwrap()),
|
||||
IpAddr::V6("2400:3200::1".parse::<Ipv6Addr>()?),
|
||||
IpAddr::V6("2400:3200:baba::1".parse::<Ipv6Addr>()?),
|
||||
];
|
||||
|
||||
let group =
|
||||
|
@ -48,7 +48,7 @@ pub async fn fetch(
|
||||
url: String,
|
||||
headers: Option<HashMap<String, String>>,
|
||||
input_data: Option<Vec<u8>>,
|
||||
) -> reqwest::Result<RustHttpResponse> {
|
||||
) -> anyhow::Result<RustHttpResponse> {
|
||||
let mut req = _mix_header(HTTP_CLIENT.request(method, url), headers);
|
||||
if input_data.is_some() {
|
||||
req = req.body(input_data.unwrap());
|
||||
|
Loading…
Reference in New Issue
Block a user