rush_sync_server/server/handlers/web/
assets.rs

1// src/server/handlers/web/assets.rs
2use super::ServerDataWithConfig;
3use actix_web::{web, HttpResponse, Result as ActixResult};
4
5pub async fn serve_rss_js(data: web::Data<ServerDataWithConfig>) -> ActixResult<HttpResponse> {
6    let js_content = include_str!("../templates/rss/rss.js")
7        .replace("{{SERVER_NAME}}", &data.server.name)
8        .replace("{{PORT}}", &data.server.port.to_string())
9        .replace("{{PROXY_PORT}}", &data.proxy_http_port.to_string())
10        .replace("{{PROXY_HTTPS_PORT}}", &data.proxy_https_port.to_string());
11
12    Ok(HttpResponse::Ok()
13        .content_type("application/javascript; charset=utf-8")
14        .insert_header(("Cache-Control", "no-cache"))
15        .body(js_content))
16}
17
18// App Controller Module
19pub async fn serve_rush_app_js(data: web::Data<ServerDataWithConfig>) -> ActixResult<HttpResponse> {
20    let js_content = include_str!("../templates/rss/js/rush-app.js")
21        .replace("{{SERVER_NAME}}", &data.server.name)
22        .replace("{{PORT}}", &data.server.port.to_string())
23        .replace("{{PROXY_PORT}}", &data.proxy_http_port.to_string())
24        .replace("{{PROXY_HTTPS_PORT}}", &data.proxy_https_port.to_string());
25    Ok(HttpResponse::Ok()
26        .content_type("application/javascript; charset=utf-8")
27        .insert_header(("Cache-Control", "no-cache"))
28        .body(js_content))
29}
30
31pub async fn serve_rush_api_js(data: web::Data<ServerDataWithConfig>) -> ActixResult<HttpResponse> {
32    let js_content = include_str!("../templates/rss/js/rush-api.js")
33        .replace("{{SERVER_NAME}}", &data.server.name)
34        .replace("{{PORT}}", &data.server.port.to_string())
35        .replace("{{PROXY_PORT}}", &data.proxy_http_port.to_string())
36        .replace("{{PROXY_HTTPS_PORT}}", &data.proxy_https_port.to_string());
37
38    Ok(HttpResponse::Ok()
39        .content_type("application/javascript; charset=utf-8")
40        .insert_header(("Cache-Control", "no-cache"))
41        .body(js_content))
42}
43
44pub async fn serve_rush_ui_js(data: web::Data<ServerDataWithConfig>) -> ActixResult<HttpResponse> {
45    let js_content = include_str!("../templates/rss/js/rush-ui.js")
46        .replace("{{SERVER_NAME}}", &data.server.name)
47        .replace("{{PORT}}", &data.server.port.to_string())
48        .replace("{{PROXY_PORT}}", &data.proxy_http_port.to_string())
49        .replace("{{PROXY_HTTPS_PORT}}", &data.proxy_https_port.to_string());
50
51    Ok(HttpResponse::Ok()
52        .content_type("application/javascript; charset=utf-8")
53        .insert_header(("Cache-Control", "no-cache"))
54        .insert_header(("X-Content-Type-Options", "nosniff"))
55        .body(js_content))
56}
57
58pub async fn serve_system_css() -> ActixResult<HttpResponse> {
59    let css_content = include_str!("../templates/rss/style.css");
60
61    Ok(HttpResponse::Ok()
62        .content_type("text/css; charset=utf-8")
63        .insert_header(("Cache-Control", "no-cache"))
64        .body(css_content))
65}
66
67pub async fn serve_system_favicon() -> ActixResult<HttpResponse> {
68    let favicon_content = include_str!("../templates/rss/favicon.svg");
69
70    Ok(HttpResponse::Ok()
71        .content_type("image/svg+xml")
72        .body(favicon_content))
73}
74
75pub async fn serve_quicksand_font(req: actix_web::HttpRequest) -> ActixResult<HttpResponse> {
76    let path = req
77        .match_info()
78        .get("font")
79        .unwrap_or("Kenyan_Coffee_Bd.otf");
80
81    let valid_fonts = [
82        "Kenyan_Coffee_Bd_It.otf",
83        "Kenyan_Coffee_Bd.otf",
84        "Kenyan_Coffee_Rg_It.otf",
85        "Kenyan_Coffee_Rg.otf",
86    ];
87
88    if !valid_fonts.contains(&path) {
89        return Ok(HttpResponse::NotFound().body("Font not found"));
90    }
91
92    let font_data: &[u8] = match path {
93        "Kenyan_Coffee_Bd_It.otf" => {
94            include_bytes!("../templates/rss/fonts/Kenyan_Coffee_Bd_It.otf").as_slice()
95        }
96        "Kenyan_Coffee_Bd.otf" => {
97            include_bytes!("../templates/rss/fonts/Kenyan_Coffee_Bd.otf").as_slice()
98        }
99        "Kenyan_Coffee_Rg_It.otf" => {
100            include_bytes!("../templates/rss/fonts/Kenyan_Coffee_Rg_It.otf").as_slice()
101        }
102        "Kenyan_Coffee_Rg.otf" => {
103            include_bytes!("../templates/rss/fonts/Kenyan_Coffee_Rg.otf").as_slice()
104        }
105        _ => return Ok(HttpResponse::NotFound().body("Font not found")),
106    };
107
108    Ok(HttpResponse::Ok()
109        .content_type("font/otf")
110        .insert_header(("Cache-Control", "public, max-age=31536000, immutable"))
111        .insert_header(("Access-Control-Allow-Origin", "*"))
112        .body(font_data))
113}
114
115pub async fn serve_global_reset_css() -> ActixResult<HttpResponse> {
116    let reset_css = include_str!("../templates/rss/_reset.css");
117
118    Ok(HttpResponse::Ok()
119        .content_type("text/css; charset=utf-8")
120        .insert_header(("Cache-Control", "public, max-age=3600"))
121        .body(reset_css))
122}