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