server: multiple frontends + auto download from github when needed

This commit is contained in:
nym21
2025-03-05 12:22:11 +01:00
parent 0d0edd7917
commit b27297cdc6
29 changed files with 892 additions and 99 deletions

View File

@@ -6,17 +6,16 @@ use std::{
};
use brk_computer::Computer;
use brk_core::path_dot_brk;
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_parser::rpc::{self, Auth, Client, RpcApi};
use brk_server::tokio;
use brk_server::{Frontend, tokio};
use clap::{Parser, ValueEnum};
use color_eyre::eyre::eyre;
use log::info;
use serde::{Deserialize, Serialize};
use crate::path_dot_brk;
pub fn run(config: RunConfig) -> color_eyre::Result<()> {
let config = RunConfig::import(Some(config))?;
@@ -40,10 +39,11 @@ pub fn run(config: RunConfig) -> color_eyre::Result<()> {
.block_on(async {
let served_indexer = indexer.clone();
let served_computer = computer.clone();
let frontend = config.frontend();
let handle = if config.serve() {
let server = if config.serve() {
Some(tokio::spawn(async move {
brk_server::main(served_indexer, served_computer)
brk_server::main(served_indexer, served_computer, frontend)
.await
.unwrap();
}))
@@ -73,9 +73,10 @@ pub fn run(config: RunConfig) -> color_eyre::Result<()> {
}
}
if let Some(handle) = handle {
if let Some(handle) = server {
handle.await.unwrap();
}
Ok(())
})
}
@@ -94,6 +95,10 @@ pub struct RunConfig {
#[arg(short, long)]
mode: Option<Mode>,
/// Frontend served by the server (if active), default: kibo.money, saved
#[arg(short, long)]
frontend: Option<Frontend>,
/// Bitcoin RPC ip, default: localhost, saved
#[arg(long, value_name = "IP")]
rpcconnect: Option<String>,
@@ -142,6 +147,10 @@ impl RunConfig {
config_saved.mode = Some(mode);
}
if let Some(frontend) = config_args.frontend.take() {
config_saved.frontend = Some(frontend);
}
if let Some(rpcconnect) = config_args.rpcconnect.take() {
config_saved.rpcconnect = Some(rpcconnect);
}
@@ -182,6 +191,7 @@ impl RunConfig {
// info!(" bitcoindir: {:?}", config.bitcoindir);
// info!(" brkdir: {:?}", config.brkdir);
// info!(" mode: {:?}", config.mode);
// info!(" frontend: {:?}", config.frontend);
// info!(" rpcconnect: {:?}", config.rpcconnect);
// info!(" rpcport: {:?}", config.rpcport);
// info!(" rpccookiefile: {:?}", config.rpccookiefile);
@@ -334,6 +344,10 @@ impl RunConfig {
fix("~").unwrap_or_else(|| fix("$HOME").unwrap_or_else(|| PathBuf::from(&path)))
}
pub fn frontend(&self) -> Frontend {
self.frontend.unwrap_or_default()
}
}
#[derive(