mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-06-13 08:23:32 -07:00
remove: app
This commit is contained in:
@@ -24,7 +24,7 @@ pub struct Route {
|
||||
pub struct Routes(pub Grouped<HashMap<String, Route>>);
|
||||
|
||||
const INPUTS_PATH: &str = "./in";
|
||||
const APP_TYPES_PATH: &str = "../app/src/types";
|
||||
const WEBSITE_TYPES_PATH: &str = "../website/types";
|
||||
|
||||
impl Routes {
|
||||
pub fn build() -> Self {
|
||||
@@ -111,7 +111,7 @@ impl Routes {
|
||||
let last_type = map_to_type("Last", &self.last);
|
||||
|
||||
fs::write(
|
||||
format!("{APP_TYPES_PATH}/paths.d.ts"),
|
||||
format!("{WEBSITE_TYPES_PATH}/paths.d.ts"),
|
||||
format!("{date_type}\n{height_type}\n{last_type}"),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -11,8 +11,13 @@ pub trait HeaderMapUtils {
|
||||
fn insert_cache_control(&mut self, max_age: u64, stale_while_revalidate: u64);
|
||||
|
||||
fn insert_content_type(&mut self, path: &Path);
|
||||
fn insert_content_type_image_icon(&mut self);
|
||||
fn insert_content_type_image_jpeg(&mut self);
|
||||
fn insert_content_type_image_png(&mut self);
|
||||
fn insert_content_type_application_javascript(&mut self);
|
||||
fn insert_content_type_application_json(&mut self);
|
||||
fn insert_content_type_application_manifest_json(&mut self);
|
||||
fn insert_content_type_text_css(&mut self);
|
||||
fn insert_content_type_text_html(&mut self);
|
||||
fn insert_content_type_text_plain(&mut self);
|
||||
fn insert_content_type_font_woff2(&mut self);
|
||||
@@ -40,8 +45,13 @@ impl HeaderMapUtils for HeaderMap {
|
||||
"js" => self.insert_content_type_application_javascript(),
|
||||
"json" => self.insert_content_type_application_json(),
|
||||
"html" => self.insert_content_type_text_html(),
|
||||
"css" => self.insert_content_type_text_css(),
|
||||
"txt" => self.insert_content_type_text_plain(),
|
||||
"woff2" => self.insert_content_type_font_woff2(),
|
||||
"ico" => self.insert_content_type_image_icon(),
|
||||
"jpg" | "jpeg" => self.insert_content_type_image_jpeg(),
|
||||
"png" => self.insert_content_type_image_png(),
|
||||
"webmanifest" => self.insert_content_type_application_manifest_json(),
|
||||
extension => {
|
||||
log(&format!("Extension unsupported: {extension}"));
|
||||
panic!()
|
||||
@@ -49,6 +59,27 @@ impl HeaderMapUtils for HeaderMap {
|
||||
}
|
||||
}
|
||||
|
||||
fn insert_content_type_image_icon(&mut self) {
|
||||
self.insert(
|
||||
header::CONTENT_TYPE,
|
||||
"image/x-icon".parse().unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
fn insert_content_type_image_jpeg(&mut self) {
|
||||
self.insert(
|
||||
header::CONTENT_TYPE,
|
||||
"image/jpeg".parse().unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
fn insert_content_type_image_png(&mut self) {
|
||||
self.insert(
|
||||
header::CONTENT_TYPE,
|
||||
"image/png".parse().unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
fn insert_content_type_application_javascript(&mut self) {
|
||||
self.insert(
|
||||
header::CONTENT_TYPE,
|
||||
@@ -60,6 +91,14 @@ impl HeaderMapUtils for HeaderMap {
|
||||
self.insert(header::CONTENT_TYPE, "application/json".parse().unwrap());
|
||||
}
|
||||
|
||||
fn insert_content_type_application_manifest_json(&mut self) {
|
||||
self.insert(header::CONTENT_TYPE, "application/manifest+json".parse().unwrap());
|
||||
}
|
||||
|
||||
fn insert_content_type_text_css(&mut self) {
|
||||
self.insert(header::CONTENT_TYPE, "text/css".parse().unwrap());
|
||||
}
|
||||
|
||||
fn insert_content_type_text_html(&mut self) {
|
||||
self.insert(header::CONTENT_TYPE, "text/html".parse().unwrap());
|
||||
}
|
||||
|
||||
@@ -3,8 +3,14 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use axum::{extract, http::HeaderMap, response::Response};
|
||||
use axum::{
|
||||
body::Body,
|
||||
extract,
|
||||
http::HeaderMap,
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use parser::log;
|
||||
use reqwest::StatusCode;
|
||||
|
||||
use crate::header_map::HeaderMapUtils;
|
||||
|
||||
@@ -15,8 +21,21 @@ const WEBSITE_PATH: &str = "../website";
|
||||
pub async fn file_handler(headers: HeaderMap, path: extract::Path<String>) -> Response {
|
||||
let path = path.0.replace("..", "").replace("\\", "");
|
||||
let mut path = str_to_path(&path);
|
||||
if path.extension().is_none() && !path.exists() {
|
||||
path = str_to_path("index.html");
|
||||
|
||||
if !path.exists() {
|
||||
if path.extension().is_some() {
|
||||
let mut response: Response<Body> = (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
"File doesn't exist".to_string(),
|
||||
)
|
||||
.into_response();
|
||||
|
||||
response.headers_mut().insert_cors();
|
||||
|
||||
return response;
|
||||
} else {
|
||||
path = str_to_path("index.html");
|
||||
}
|
||||
}
|
||||
|
||||
path_to_response(&path)
|
||||
|
||||
Reference in New Issue
Block a user