add fetch_b64 for downloading binary files in base64 format
This commit is contained in:
19
src/main.rs
19
src/main.rs
@@ -205,6 +205,20 @@ async fn file_handler(request: Request) -> impl IntoResponse {
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
|
||||
let fetch_b64 = lua
|
||||
.create_function(|lua, uri: String| {
|
||||
let resp = reqwest::blocking::get(&uri)
|
||||
.and_then(|resp| resp.error_for_status())
|
||||
.into_lua_err()?;
|
||||
let bytes = resp.bytes().into_lua_err()?;
|
||||
let b64 = BASE64_STANDARD.encode(bytes);
|
||||
lua.to_value(&b64)
|
||||
})
|
||||
.map_err(|e| {
|
||||
eprintln!("Lua Error: {:?}", e);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
|
||||
let dbg = lua
|
||||
.create_function(|_, value: LuaValue| {
|
||||
dbg!(value);
|
||||
@@ -220,6 +234,11 @@ async fn file_handler(request: Request) -> impl IntoResponse {
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
|
||||
globals.set("fetch_b64", fetch_b64).map_err(|e| {
|
||||
eprintln!("Lua Error: {:?}", e);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
|
||||
globals.set("dbg", dbg).map_err(|e| {
|
||||
eprintln!("Lua Error: {:?}", e);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
|
Reference in New Issue
Block a user