feat: add api function
This commit is contained in:
1 parent
0fe8e4bcbd
commit
39e38917d6
4 files changed
+12
-29
No files matched your search
+1
-1
@@ -46,7 +46,7 @@ walkdir = "2"
|
|||||||
|
|
||||||
# tools download
|
# tools download
|
||||||
dirs = "4.0.0"
|
dirs = "4.0.0"
|
||||||
reqwest = { version = "0.11", features = ["rustls-tls", "stream", "trust-dns"] }
|
reqwest = { version = "0.11", features = ["rustls-tls", "stream", "trust-dns", "blocking"] }
|
||||||
flate2 = "1.0.22"
|
flate2 = "1.0.22"
|
||||||
tar = "0.4.38"
|
tar = "0.4.38"
|
||||||
zip = "0.6.2"
|
zip = "0.6.2"
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ use mlua::UserData;
|
|||||||
pub struct PluginNetwork;
|
pub struct PluginNetwork;
|
||||||
impl UserData for PluginNetwork {
|
impl UserData for PluginNetwork {
|
||||||
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_async_function("download_file", |_, args: (String, String)| async move {
|
methods.add_function("download_file", |_, args: (String, String)| {
|
||||||
let url = args.0;
|
let url = args.0;
|
||||||
let path = args.1;
|
let path = args.1;
|
||||||
|
|
||||||
let resp = reqwest::get(url).await;
|
let resp = reqwest::blocking::get(url);
|
||||||
if let Ok(resp) = resp {
|
if let Ok(resp) = resp {
|
||||||
let mut content = Cursor::new(resp.bytes().await.unwrap());
|
let mut content = Cursor::new(resp.bytes().unwrap());
|
||||||
let file = std::fs::File::create(PathBuf::from(path));
|
let file = std::fs::File::create(PathBuf::from(path));
|
||||||
if file.is_err() {
|
if file.is_err() {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use mlua::UserData;
|
use mlua::{UserData, Variadic};
|
||||||
|
|
||||||
pub struct PluginPath;
|
pub struct PluginPath;
|
||||||
impl UserData for PluginPath {
|
impl UserData for PluginPath {
|
||||||
fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) {
|
fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) {
|
||||||
// join function
|
// join function
|
||||||
methods.add_function("join", |_, args: (String, String)| {
|
methods.add_function("join", |_, args: Variadic<String>| {
|
||||||
let current_path = PathBuf::from(args.0);
|
let mut path = PathBuf::new();
|
||||||
let new_path = current_path.join(args.1);
|
for i in args {
|
||||||
Ok(new_path.to_str().unwrap().to_string())
|
path = path.join(i);
|
||||||
});
|
}
|
||||||
|
Ok(path.to_str().unwrap().to_string())
|
||||||
|
});
|
||||||
|
|
||||||
// parent function
|
// parent function
|
||||||
methods.add_function("parent", |_, path: String| {
|
methods.add_function("parent", |_, path: String| {
|
||||||
|
|||||||
@@ -298,25 +298,6 @@ impl PluginManager {
|
|||||||
plugin_path
|
plugin_path
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn plugin_list_from_dir() -> Vec<String> {
|
|
||||||
let mut res = vec![];
|
|
||||||
|
|
||||||
let app_path = app_path();
|
|
||||||
let plugin_path = app_path.join("plugins");
|
|
||||||
|
|
||||||
let child_dirs = std::fs::read_dir(plugin_path).unwrap();
|
|
||||||
for p in child_dirs {
|
|
||||||
if let Ok(p) = p {
|
|
||||||
if p.path().is_dir() && p.file_name() != "library" {
|
|
||||||
if p.path().join("init.lua").is_file() {
|
|
||||||
res.push(p.file_name().to_str().unwrap().to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
res
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn plugin_list() -> Vec<String> {
|
pub fn plugin_list() -> Vec<String> {
|
||||||
let mut res = vec![];
|
let mut res = vec![];
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user