proxmox-rest-server: cleanup formatter, improve docs
Use trait for OutputFormatter. This is functionally equivalent, but more rust-like...
This commit is contained in:
@ -1332,7 +1332,7 @@ pub fn upload_backup_log(
|
||||
replace_file(&path, blob.raw_data(), CreateOptions::new())?;
|
||||
|
||||
// fixme: use correct formatter
|
||||
Ok(formatter::json_response(Ok(Value::Null)))
|
||||
Ok(formatter::JSON_FORMATTER.format_data(Value::Null, &*rpcenv))
|
||||
}.boxed()
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ pub struct BackupEnvironment {
|
||||
result_attributes: Value,
|
||||
auth_id: Authid,
|
||||
pub debug: bool,
|
||||
pub formatter: &'static OutputFormatter,
|
||||
pub formatter: &'static dyn OutputFormatter,
|
||||
pub worker: Arc<WorkerTask>,
|
||||
pub datastore: Arc<DataStore>,
|
||||
pub backup_dir: BackupDir,
|
||||
@ -146,7 +146,7 @@ impl BackupEnvironment {
|
||||
worker,
|
||||
datastore,
|
||||
debug: false,
|
||||
formatter: &JSON_FORMATTER,
|
||||
formatter: JSON_FORMATTER,
|
||||
backup_dir,
|
||||
last_backup: None,
|
||||
state: Arc::new(Mutex::new(state)),
|
||||
@ -556,10 +556,7 @@ impl BackupEnvironment {
|
||||
}
|
||||
|
||||
pub fn format_response(&self, result: Result<Value, Error>) -> Response<Body> {
|
||||
match result {
|
||||
Ok(data) => (self.formatter.format_data)(data, self),
|
||||
Err(err) => (self.formatter.format_error)(err),
|
||||
}
|
||||
self.formatter.format_result(result, self)
|
||||
}
|
||||
|
||||
/// Raise error if finished flag is not set
|
||||
|
@ -18,7 +18,7 @@ pub struct ReaderEnvironment {
|
||||
result_attributes: Value,
|
||||
auth_id: Authid,
|
||||
pub debug: bool,
|
||||
pub formatter: &'static OutputFormatter,
|
||||
pub formatter: &'static dyn OutputFormatter,
|
||||
pub worker: Arc<WorkerTask>,
|
||||
pub datastore: Arc<DataStore>,
|
||||
pub backup_dir: BackupDir,
|
||||
@ -42,7 +42,7 @@ impl ReaderEnvironment {
|
||||
worker,
|
||||
datastore,
|
||||
debug: false,
|
||||
formatter: &JSON_FORMATTER,
|
||||
formatter: JSON_FORMATTER,
|
||||
backup_dir,
|
||||
allowed_chunks: Arc::new(RwLock::new(HashSet::new())),
|
||||
}
|
||||
|
Reference in New Issue
Block a user