mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-03 15:23:41 -07:00
global: snapshot
This commit is contained in:
@@ -2,23 +2,23 @@ use std::{fs, io, path::Path};
|
||||
|
||||
use brk_query::{Index, Query};
|
||||
|
||||
use crate::Frontend;
|
||||
use crate::Website;
|
||||
|
||||
const SCRIPTS: &str = "scripts";
|
||||
const TPYES: &str = "types";
|
||||
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
pub trait DTS {
|
||||
fn generate_dts_file(&self, frontend: Frontend, websites_path: &Path) -> io::Result<()>;
|
||||
fn generate_dts_file(&self, website: Website, websites_path: &Path) -> io::Result<()>;
|
||||
}
|
||||
|
||||
impl DTS for Query<'static> {
|
||||
fn generate_dts_file(&self, frontend: Frontend, websites_path: &Path) -> io::Result<()> {
|
||||
if frontend.is_none() {
|
||||
fn generate_dts_file(&self, website: Website, websites_path: &Path) -> io::Result<()> {
|
||||
if website.is_none() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let path = websites_path.join(frontend.to_folder_name());
|
||||
let path = websites_path.join(website.to_folder_name());
|
||||
|
||||
if !fs::exists(&path)? {
|
||||
return Ok(());
|
||||
|
||||
@@ -46,7 +46,7 @@ fn any_handler(
|
||||
.websites_path
|
||||
.as_ref()
|
||||
.expect("Should never reach here is websites_path is None")
|
||||
.join(app_state.frontend.to_folder_name());
|
||||
.join(app_state.website.to_folder_name());
|
||||
|
||||
let instant = Instant::now();
|
||||
|
||||
|
||||
@@ -3,19 +3,19 @@ use axum::{Router, routing::get};
|
||||
use super::AppState;
|
||||
|
||||
mod file;
|
||||
mod frontend;
|
||||
mod minify;
|
||||
mod website;
|
||||
|
||||
use file::{file_handler, index_handler};
|
||||
pub use frontend::Frontend;
|
||||
pub use website::Website;
|
||||
|
||||
pub trait FilesRoutes {
|
||||
fn add_website_routes(self, frontend: Frontend) -> Self;
|
||||
fn add_website_routes(self, website: Website) -> Self;
|
||||
}
|
||||
|
||||
impl FilesRoutes for Router<AppState> {
|
||||
fn add_website_routes(self, frontend: Frontend) -> Self {
|
||||
if frontend.is_some() {
|
||||
fn add_website_routes(self, website: Website) -> Self {
|
||||
if website.is_some() {
|
||||
self.route("/{*path}", get(file_handler))
|
||||
.route("/", get(index_handler))
|
||||
} else {
|
||||
|
||||
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
||||
#[derive(
|
||||
Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize, ValueEnum,
|
||||
)]
|
||||
pub enum Frontend {
|
||||
pub enum Website {
|
||||
#[default]
|
||||
None,
|
||||
#[value(name = "kibo.money")]
|
||||
@@ -12,7 +12,7 @@ pub enum Frontend {
|
||||
Custom,
|
||||
}
|
||||
|
||||
impl Frontend {
|
||||
impl Website {
|
||||
pub fn is_none(&self) -> bool {
|
||||
self == &Self::None
|
||||
}
|
||||
@@ -32,14 +32,14 @@ mod api;
|
||||
mod files;
|
||||
mod traits;
|
||||
|
||||
pub use files::Frontend;
|
||||
pub use files::Website;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
// indexer: &'static Indexer,
|
||||
// computer: &'static Computer,
|
||||
query: &'static Query<'static>,
|
||||
frontend: Frontend,
|
||||
website: Website,
|
||||
websites_path: Option<PathBuf>,
|
||||
}
|
||||
|
||||
@@ -51,16 +51,12 @@ const WEBSITES: &str = "websites";
|
||||
pub struct Server(AppState);
|
||||
|
||||
impl Server {
|
||||
pub fn new(
|
||||
indexer: Indexer,
|
||||
computer: Computer,
|
||||
frontend: Frontend,
|
||||
) -> color_eyre::Result<Self> {
|
||||
pub fn new(indexer: Indexer, computer: Computer, website: Website) -> color_eyre::Result<Self> {
|
||||
let indexer = Box::leak(Box::new(indexer));
|
||||
let computer = Box::leak(Box::new(computer));
|
||||
let query = Box::leak(Box::new(Query::build(indexer, computer)));
|
||||
|
||||
let websites_path = if frontend.is_some() {
|
||||
let websites_path = if website.is_some() {
|
||||
let websites_dev_path = Path::new(DEV_PATH).join(WEBSITES);
|
||||
|
||||
let websites_path = if fs::exists(&websites_dev_path)? {
|
||||
@@ -90,7 +86,7 @@ impl Server {
|
||||
downloaded_websites_path
|
||||
};
|
||||
|
||||
query.generate_dts_file(frontend, websites_path.as_path())?;
|
||||
query.generate_dts_file(website, websites_path.as_path())?;
|
||||
|
||||
Some(websites_path)
|
||||
} else {
|
||||
@@ -99,7 +95,7 @@ impl Server {
|
||||
|
||||
Ok(Self(AppState {
|
||||
query,
|
||||
frontend,
|
||||
website,
|
||||
websites_path,
|
||||
}))
|
||||
}
|
||||
@@ -115,7 +111,7 @@ impl Server {
|
||||
|
||||
let router = Router::new()
|
||||
.add_api_routes()
|
||||
.add_website_routes(state.frontend)
|
||||
.add_website_routes(state.website)
|
||||
.route("/version", get(Json(env!("CARGO_PKG_VERSION"))))
|
||||
.with_state(state)
|
||||
.layer(compression_layer);
|
||||
|
||||
Reference in New Issue
Block a user