Skip to content

Commit

Permalink
[net_util] Remove unnecessary storage access when exporting the config
Browse files Browse the repository at this point in the history
  • Loading branch information
m4heshd committed Jul 6, 2024
1 parent 0e6f87f commit b670ca3
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions backend/src/net_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use anyhow::{anyhow, Context};
use arc_swap::ArcSwap;
use axum::{
body::Body,
http::{header, Method},
http::{header, Method, StatusCode},
response::IntoResponse,
routing::get,
Router,
Expand All @@ -21,8 +21,6 @@ use tower_http::cors::{Any, CorsLayer};

use ufcr_libs::{log_err, log_success};

use crate::config_util::CONFIG_PATH;
use crate::fs_util::read_config_file_to_string;
use crate::{
app_util::{get_app_metadata, get_os_id, is_container},
bin_util::BINS,
Expand Down Expand Up @@ -168,7 +166,16 @@ pub fn update_proxied_client() -> anyhow::Result<()> {

/// Sends the config file as a download.
async fn handle_config_dl_req() -> impl IntoResponse {
let body = Body::from(read_config_file_to_string(&CONFIG_PATH).await);
let config_json = match serde_json::to_string_pretty(get_config().as_ref()) {
Ok(config) => config,
Err(err) => {
return Err((
StatusCode::INTERNAL_SERVER_ERROR,
format!("Failed to prepare JSON: {err}"),
))
}
};
let body = Body::from(config_json);
let headers = [
(header::CONTENT_TYPE, "text/json; charset=utf-8"),
(
Expand All @@ -177,7 +184,7 @@ async fn handle_config_dl_req() -> impl IntoResponse {
),
];

(headers, body)
Ok((headers, body))
}

/// Fetches UFC Ripper's update information from the GitHub repo.
Expand Down

0 comments on commit b670ca3

Please sign in to comment.