diff --git a/backend/src/config_util.rs b/backend/src/config_util.rs index be96e69..9ca8c88 100644 --- a/backend/src/config_util.rs +++ b/backend/src/config_util.rs @@ -135,7 +135,7 @@ pub enum ConfigUpdate { } // Statics -static CONFIG_PATH: Lazy = +pub static CONFIG_PATH: Lazy = Lazy::new(|| get_app_root_dir().join("config").join("config.json")); static CONFIG: Lazy> = Lazy::new(|| ArcSwap::from_pointee(UFCRConfig::default())); diff --git a/backend/src/net_util.rs b/backend/src/net_util.rs index 533c200..bfedee1 100644 --- a/backend/src/net_util.rs +++ b/backend/src/net_util.rs @@ -5,7 +5,13 @@ use std::{net::SocketAddr, sync::Arc}; use anyhow::{anyhow, Context}; use arc_swap::ArcSwap; -use axum::{http::Method, Router}; +use axum::{ + body::Body, + http::{header, Method}, + response::IntoResponse, + routing::get, + Router, +}; use axum_embed::{FallbackBehavior::Redirect, ServeEmbed}; use once_cell::sync::Lazy; use reqwest::{header::HeaderMap, Client, Proxy, Response}; @@ -15,6 +21,8 @@ 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, @@ -93,6 +101,7 @@ pub async fn init_server() { // Axum router let app = Router::new() .nest_service("/", web_assets) + .route("/export_config", get(handle_config_dl_req)) .layer(create_ws_layer()) .layer(create_cors_layer()); @@ -157,6 +166,20 @@ pub fn update_proxied_client() -> anyhow::Result<()> { Ok(()) } +/// 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 headers = [ + (header::CONTENT_TYPE, "text/json; charset=utf-8"), + ( + header::CONTENT_DISPOSITION, + "attachment; filename=\"config.json\"", + ), + ]; + + (headers, body) +} + /// Fetches UFC Ripper's update information from the GitHub repo. pub async fn get_latest_app_meta() -> anyhow::Result { let req_url = format!("{}/raw/master/package.json", get_app_metadata().repo); diff --git a/frontend/src/components/ModConfig.vue b/frontend/src/components/ModConfig.vue index a8579b7..33e7e05 100644 --- a/frontend/src/components/ModConfig.vue +++ b/frontend/src/components/ModConfig.vue @@ -106,6 +106,10 @@ Import +
@@ -533,6 +537,11 @@ async function onConfigFileImport() { } } +// Config export +function onConfigFileExport() { + window.location.href = '/export_config'; +} + // Misc functions function save(config) { saveConfig(config || modConfig.data)