Compare commits
2
Commits
a7c1663491
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b86149851d | ||
|
|
b3ecbb854c |
+7
-9
@@ -1,9 +1,10 @@
|
||||
use anyhow::Context;
|
||||
use axum::{extract::State, response::Html};
|
||||
use http::StatusCode;
|
||||
use serde::Deserialize;
|
||||
use tokio::process::Command;
|
||||
|
||||
use crate::SharedState;
|
||||
use crate::{SharedState, util::e};
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
struct FlatpakApp {
|
||||
@@ -28,10 +29,8 @@ pub async fn index(State(state): State<SharedState>) -> Result<Html<String>, Sta
|
||||
.arg(format!("file://{}", repo.display()))
|
||||
.output()
|
||||
.await
|
||||
.map_err(|e| {
|
||||
tracing::error!("Failed to execute `flatpak remote-ls`: {e:?}");
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?
|
||||
.context("Failed to execute `flatpak remote-ls`")
|
||||
.map_err(e(StatusCode::INTERNAL_SERVER_ERROR))?
|
||||
};
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
@@ -42,10 +41,9 @@ pub async fn index(State(state): State<SharedState>) -> Result<Html<String>, Sta
|
||||
tracing::error!("stderr:\n{stderr}\n");
|
||||
}
|
||||
|
||||
let list: Vec<FlatpakApp> = serde_json::from_str(&stdout).map_err(|e| {
|
||||
tracing::error!("Failed to deserialize `flatpak remote-ls --json`'s output: {e:?}");
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
let list: Vec<FlatpakApp> = serde_json::from_str(&stdout)
|
||||
.context("Failed to deserialize `flatpak remote-ls --json`'s output")
|
||||
.map_err(e(StatusCode::INTERNAL_SERVER_ERROR))?;
|
||||
|
||||
Ok(to_html(&list))
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ pub async fn flatpak_bundle(
|
||||
}
|
||||
|
||||
// Create a tmpfile
|
||||
// TODO: ensure tmp_file is cleaned up on early return
|
||||
let (tmp_path, mut tmp_file) = block_in_place(|| {
|
||||
let mut file = NamedTempFile::new()?;
|
||||
file.disable_cleanup(true);
|
||||
|
||||
@@ -2,6 +2,9 @@ use std::fmt::Display;
|
||||
|
||||
use http::StatusCode;
|
||||
|
||||
/// Helper funciton for use with [`Result::map_err`].
|
||||
///
|
||||
/// Logs the error and replaces it with the provided status code.
|
||||
#[track_caller]
|
||||
pub fn e<E: Display>(code: StatusCode) -> impl FnOnce(E) -> StatusCode {
|
||||
move |e| {
|
||||
|
||||
Reference in New Issue
Block a user