Hook up installer framework to REST API

This commit is contained in:
James 2018-01-29 22:08:28 +11:00
parent d51e0bdb54
commit d3bc6333e9
2 changed files with 21 additions and 8 deletions

View File

@ -30,14 +30,16 @@ impl InstallerFramework {
Err(_) => home_dir()?, Err(_) => home_dir()?,
}; };
println!("{:?}", base_dir);
let file = base_dir.join(app_name); let file = base_dir.join(app_name);
println!("{:?}", file);
Some(file.to_str()?.to_owned()) 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. /// Creates a new instance of the Installer Framework with a specified Config.
pub fn new(config: Config) -> Self { pub fn new(config: Config) -> Self {
InstallerFramework { config } InstallerFramework { config }

View File

@ -13,7 +13,6 @@ use serde_json;
use futures::Stream; use futures::Stream;
use futures::Future; use futures::Future;
use futures::future; use futures::future;
use futures::future::FutureResult;
use hyper::{self, Error as HyperError, Get, Post, StatusCode}; use hyper::{self, Error as HyperError, Get, Post, StatusCode};
use hyper::header::{ContentLength, ContentType}; use hyper::header::{ContentLength, ContentType};
@ -150,11 +149,25 @@ impl Service for WebService {
} }
(&Post, "/api/start-install") => { (&Post, "/api/start-install") => {
// We need to bit of pipelining to get this to work // 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()) let results = form_urlencoded::parse(b.as_ref())
.into_owned().collect::<HashMap<String, String>>(); .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(); let file = serde_json::to_string(&{}).unwrap();
@ -174,8 +187,6 @@ impl Service for WebService {
path += "index.html"; path += "index.html";
} }
println!("Trying {} => {}", req.path(), path);
match assets::file_from_string(&path) { match assets::file_from_string(&path) {
Some((content_type, file)) => { Some((content_type, file)) => {
let content_type = ContentType(content_type.parse().unwrap()); let content_type = ContentType(content_type.parse().unwrap());