mirror of
https://github.com/yuzu-emu/liftinstall.git
synced 2024-11-22 09:55:40 +01:00
Hook up installer framework to REST API
This commit is contained in:
parent
d51e0bdb54
commit
d3bc6333e9
@ -30,14 +30,16 @@ impl InstallerFramework {
|
||||
Err(_) => home_dir()?,
|
||||
};
|
||||
|
||||
println!("{:?}", base_dir);
|
||||
|
||||
let file = base_dir.join(app_name);
|
||||
println!("{:?}", file);
|
||||
|
||||
Some(file.to_str()?.to_owned())
|
||||
}
|
||||
|
||||
/// Sends a request for something to be installed.
|
||||
pub fn install(&self, items : Vec<String>) {
|
||||
println!("Framework: Installing {:?}", items);
|
||||
}
|
||||
|
||||
/// Creates a new instance of the Installer Framework with a specified Config.
|
||||
pub fn new(config: Config) -> Self {
|
||||
InstallerFramework { config }
|
||||
|
21
src/rest.rs
21
src/rest.rs
@ -13,7 +13,6 @@ use serde_json;
|
||||
use futures::Stream;
|
||||
use futures::Future;
|
||||
use futures::future;
|
||||
use futures::future::FutureResult;
|
||||
|
||||
use hyper::{self, Error as HyperError, Get, Post, StatusCode};
|
||||
use hyper::header::{ContentLength, ContentType};
|
||||
@ -150,11 +149,25 @@ impl Service for WebService {
|
||||
}
|
||||
(&Post, "/api/start-install") => {
|
||||
// We need to bit of pipelining to get this to work
|
||||
return Box::new(req.body().concat2().map(|b| {
|
||||
let cloned_element = self.framework.clone();
|
||||
|
||||
return Box::new(req.body().concat2().map(move |b| {
|
||||
let results = form_urlencoded::parse(b.as_ref())
|
||||
.into_owned().collect::<HashMap<String, String>>();
|
||||
|
||||
println!("{:?}", results);
|
||||
let mut to_install = Vec::new();
|
||||
|
||||
// Transform results into just an array of stuff to install
|
||||
for (key, value) in results.iter() {
|
||||
if value == "true" {
|
||||
to_install.push(key.to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
// Startup a thread to do this operation for us
|
||||
thread::spawn(move || {
|
||||
cloned_element.install(to_install);
|
||||
});
|
||||
|
||||
let file = serde_json::to_string(&{}).unwrap();
|
||||
|
||||
@ -174,8 +187,6 @@ impl Service for WebService {
|
||||
path += "index.html";
|
||||
}
|
||||
|
||||
println!("Trying {} => {}", req.path(), path);
|
||||
|
||||
match assets::file_from_string(&path) {
|
||||
Some((content_type, file)) => {
|
||||
let content_type = ContentType(content_type.parse().unwrap());
|
||||
|
Loading…
Reference in New Issue
Block a user