mirror of
https://github.com/yuzu-emu/liftinstall.git
synced 2024-11-26 02:25:38 +01:00
Add REST API for getting installation status
This commit is contained in:
parent
dae36a15b9
commit
93ebca5f3c
@ -52,14 +52,22 @@ pub struct InstallerFramework {
|
|||||||
preexisting_install: bool
|
preexisting_install: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Contains basic properties on the status of the session. Subset of InstallationFramework.
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct InstallationStatus {
|
||||||
|
database: Vec<LocalInstallation>,
|
||||||
|
install_path: Option<String>,
|
||||||
|
preexisting_install: bool
|
||||||
|
}
|
||||||
|
|
||||||
/// Used to track the amount of data that has been downloaded during a HTTP request.
|
/// Used to track the amount of data that has been downloaded during a HTTP request.
|
||||||
struct DownloadProgress {
|
struct DownloadProgress {
|
||||||
downloaded: usize,
|
downloaded: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tracks the state of a local installation
|
/// Tracks the state of a local installation
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
struct LocalInstallation {
|
pub struct LocalInstallation {
|
||||||
name: String,
|
name: String,
|
||||||
version: Version,
|
version: Version,
|
||||||
files: Vec<String>,
|
files: Vec<String>,
|
||||||
@ -398,6 +406,15 @@ impl InstallerFramework {
|
|||||||
self.install_path = Some(dir.to_owned());
|
self.install_path = Some(dir.to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns metadata on the current status of the installation.
|
||||||
|
pub fn get_installation_status(&self) -> InstallationStatus {
|
||||||
|
InstallationStatus {
|
||||||
|
database: self.database.clone(),
|
||||||
|
install_path: self.install_path.clone(),
|
||||||
|
preexisting_install: self.preexisting_install
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// 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 {
|
InstallerFramework {
|
||||||
|
18
src/rest.rs
18
src/rest.rs
@ -24,6 +24,7 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
|||||||
use std::thread::{self, JoinHandle};
|
use std::thread::{self, JoinHandle};
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::sync::RwLock;
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
@ -31,13 +32,14 @@ use assets;
|
|||||||
|
|
||||||
use installer::InstallerFramework;
|
use installer::InstallerFramework;
|
||||||
use installer::InstallMessage;
|
use installer::InstallMessage;
|
||||||
use std::sync::RwLock;
|
use installer::LocalInstallation;
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct FileSelection {
|
struct FileSelection {
|
||||||
path: Option<String>,
|
path: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Acts as a communication mechanism between the Hyper WebService and the rest of the
|
/// Acts as a communication mechanism between the Hyper WebService and the rest of the
|
||||||
/// application.
|
/// application.
|
||||||
pub struct WebServer {
|
pub struct WebServer {
|
||||||
@ -152,6 +154,20 @@ impl Service for WebService {
|
|||||||
(&Get, "/api/exit") => {
|
(&Get, "/api/exit") => {
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
// Gets properties such as if the application is in maintenance mode
|
||||||
|
(&Get, "/api/installation-status") => {
|
||||||
|
let framework = self.framework.read().unwrap();
|
||||||
|
|
||||||
|
let response = framework.get_installation_status();
|
||||||
|
|
||||||
|
let file = serde_json::to_string(&response).unwrap();
|
||||||
|
|
||||||
|
Response::<hyper::Body>::new()
|
||||||
|
.with_header(ContentLength(file.len() as u64))
|
||||||
|
.with_header(ContentType::json())
|
||||||
|
.with_body(file)
|
||||||
|
}
|
||||||
|
// Streams the installation of a particular set of packages
|
||||||
(&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
|
||||||
let framework = self.framework.clone();
|
let framework = self.framework.clone();
|
||||||
|
Loading…
Reference in New Issue
Block a user