proxmox-rest-server: make get_index async
This commit is contained in:
@ -1,3 +1,6 @@
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
|
||||
use anyhow::{bail, Error};
|
||||
use futures::*;
|
||||
use http::request::Parts;
|
||||
@ -24,20 +27,22 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_index(
|
||||
fn get_index<'a>(
|
||||
_auth_id: Option<String>,
|
||||
_language: Option<String>,
|
||||
_api: &ApiConfig,
|
||||
_api: &'a ApiConfig,
|
||||
_parts: Parts,
|
||||
) -> Response<Body> {
|
||||
) -> Pin<Box<dyn Future<Output = Response<Body>> + Send + 'a>> {
|
||||
Box::pin(async move {
|
||||
|
||||
let index = "<center><h1>Proxmox Backup API Server</h1></center>";
|
||||
let index = "<center><h1>Proxmox Backup API Server</h1></center>";
|
||||
|
||||
Response::builder()
|
||||
.status(StatusCode::OK)
|
||||
.header(header::CONTENT_TYPE, "text/html")
|
||||
.body(index.into())
|
||||
.unwrap()
|
||||
Response::builder()
|
||||
.status(StatusCode::OK)
|
||||
.header(header::CONTENT_TYPE, "text/html")
|
||||
.body(index.into())
|
||||
.unwrap()
|
||||
})
|
||||
}
|
||||
|
||||
async fn run() -> Result<(), Error> {
|
||||
@ -76,7 +81,7 @@ async fn run() -> Result<(), Error> {
|
||||
&proxmox_backup::api2::ROUTER,
|
||||
RpcEnvironmentType::PRIVILEGED,
|
||||
default_api_auth(),
|
||||
get_index,
|
||||
&get_index,
|
||||
)?;
|
||||
|
||||
let backup_user = pbs_config::backup_user()?;
|
||||
|
@ -1,6 +1,8 @@
|
||||
use std::sync::{Mutex, Arc};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
|
||||
use anyhow::{bail, format_err, Error};
|
||||
use futures::*;
|
||||
@ -76,13 +78,24 @@ fn main() -> Result<(), Error> {
|
||||
pbs_runtime::main(run())
|
||||
}
|
||||
|
||||
fn get_index(
|
||||
fn get_index<'a>(
|
||||
auth_id: Option<String>,
|
||||
language: Option<String>,
|
||||
api: &'a ApiConfig,
|
||||
parts: Parts,
|
||||
) -> Pin<Box<dyn Future<Output = Response<Body>> + Send + 'a>> {
|
||||
Box::pin(get_index_future(auth_id, language, api, parts))
|
||||
}
|
||||
|
||||
async fn get_index_future(
|
||||
auth_id: Option<String>,
|
||||
language: Option<String>,
|
||||
api: &ApiConfig,
|
||||
parts: Parts,
|
||||
) -> Response<Body> {
|
||||
|
||||
// fixme: make all IO async
|
||||
|
||||
let (userid, csrf_token) = match auth_id {
|
||||
Some(auth_id) => {
|
||||
let auth_id = auth_id.parse::<Authid>();
|
||||
@ -169,7 +182,7 @@ async fn run() -> Result<(), Error> {
|
||||
&proxmox_backup::api2::ROUTER,
|
||||
RpcEnvironmentType::PUBLIC,
|
||||
default_api_auth(),
|
||||
get_index,
|
||||
&get_index,
|
||||
)?;
|
||||
|
||||
config.add_alias("novnc", "/usr/share/novnc-pve");
|
||||
|
Reference in New Issue
Block a user