feat: commit file download
This commit is contained in:
1 parent
d13955e39b
commit
2ad5c7e282
3 files changed
+25
-3
No files matched your search
Generated
+3
@@ -1625,6 +1625,9 @@ checksum = "8afb4815a6d6a3bd1c23e6c647f7df18c9800c12e80526a98e18d7decd7cedcd"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bstr",
|
"bstr",
|
||||||
"cc",
|
"cc",
|
||||||
|
"futures-core",
|
||||||
|
"futures-task",
|
||||||
|
"futures-util",
|
||||||
"lua-src",
|
"lua-src",
|
||||||
"luajit-src",
|
"luajit-src",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
|
|||||||
+1
-1
@@ -60,7 +60,7 @@ dioxus-rsx-interpreter = { git = "https://github.com/dioxuslabs/dioxus/" }
|
|||||||
proc-macro2 = { version = "1.0", features = ["span-locations"] }
|
proc-macro2 = { version = "1.0", features = ["span-locations"] }
|
||||||
|
|
||||||
# plugin packages
|
# plugin packages
|
||||||
mlua = { version = "0.8.1", features = ["lua54", "vendored"] }
|
mlua = { version = "0.8.1", features = ["lua54", "vendored", "async"] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|||||||
@@ -1,8 +1,27 @@
|
|||||||
|
use std::{io::Cursor, path::PathBuf};
|
||||||
|
|
||||||
use mlua::UserData;
|
use mlua::UserData;
|
||||||
|
|
||||||
pub struct PluginDownloader;
|
pub struct PluginDownloader;
|
||||||
impl UserData for PluginDownloader {
|
impl UserData for PluginDownloader {
|
||||||
fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(_methods: &mut M) {
|
fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) {
|
||||||
// methods.add_function("name", function)
|
methods.add_async_function("download_file", |_, args: (String, String)| async move {
|
||||||
|
let url = args.0;
|
||||||
|
let path = args.1;
|
||||||
|
|
||||||
|
let resp = reqwest::get(url).await;
|
||||||
|
if let Ok(resp) = resp {
|
||||||
|
let mut content = Cursor::new(resp.bytes().await.unwrap());
|
||||||
|
let file = std::fs::File::create(PathBuf::from(path));
|
||||||
|
if file.is_err() {
|
||||||
|
return Ok(false);
|
||||||
|
}
|
||||||
|
let mut file = file.unwrap();
|
||||||
|
let res = std::io::copy(&mut content, &mut file);
|
||||||
|
return Ok(res.is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(false)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user