cleanup, sync

This commit is contained in:
2023-09-27 19:01:50 +02:00
parent 43e5d473b7
commit 6822b5eab5
11 changed files with 74 additions and 198 deletions
-23
View File
@@ -1,23 +0,0 @@
use std::fs;
pub fn read_file(file_path: &str) -> String {
let data: String = fs::read_to_string(file_path)
.expect(format!("Unable to read file {}", file_path).as_str());
return data;
}
pub fn add_component(component_tag: String, html_data: String) -> String {
let css_tag: String = component_tag.to_uppercase() + &String::from("_CSS");
let html_tag: String = component_tag.to_uppercase() + &String::from("_HTML");
let css_path = String::from("./templates/components/")
+ &component_tag.to_lowercase()
+ &String::from(".css");
let css_loaded = read_file(&css_path);
let html_path = String::from("./templates/components/")
+ &component_tag.to_lowercase()
+ &String::from(".html");
let html_loaded = read_file(&html_path);
let html_data = html_data.replace(html_tag.as_str(), &html_loaded);
let html_data = html_data.replace(css_tag.as_str(),&css_loaded);
return html_data
}
-17
View File
@@ -1,17 +0,0 @@
use super::content_loader::read_file;
use actix_web::HttpResponse;
pub async fn login() -> HttpResponse {
let mut html_data = read_file(&String::from("./templates/login.html"));
let javascript_data = read_file(&String::from("./javascript/login.js"));
let css_data = read_file(&String::from("./css/main.css"));
let base_css_data = read_file(&String::from("./css/base.css"));
html_data = html_data.replace("{{JAVASCRIPT}}", &javascript_data);
html_data = html_data.replace("{{CSS}}", &css_data);
html_data = html_data.replace("{{BASE_CSS}}", &base_css_data);
HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(html_data)
}
-15
View File
@@ -1,15 +0,0 @@
use actix_web::HttpResponse;
pub async fn logout() -> HttpResponse {
HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(
"<html>\
<script>\
localStorage.removeItem('user-token'); \
window.location.replace(document.location.origin);\
</script>\
</html>
",
)
}
-35
View File
@@ -1,35 +0,0 @@
use actix_web::web;
mod content_loader;
mod login;
mod logout;
mod reader;
use super::path::Path;
/// This function adds the app views to the web server serving HTML.
///
/// # Arguments
/// * (&mut web::ServiceConfig): reference to the app for configuration
///
/// # Returns
/// None
pub fn app_factory(app: &mut web::ServiceConfig) {
// define the path struct
let base_path: Path = Path {
prefix: String::from("/"),
backend: false,
};
// define the routes for the app
app.route(
&base_path.define(String::from("")),
web::get().to(reader::reader),
);
app.route(
&base_path.define(String::from("login")),
web::get().to(login::login),
);
app.route(
&base_path.define(String::from("logout")),
web::get().to(logout::logout),
);
}
-18
View File
@@ -1,18 +0,0 @@
use super::content_loader::read_file;
use actix_web::HttpResponse;
pub async fn reader() -> HttpResponse {
let mut html_data = read_file("./templates/reader.html");
let javascript = read_file("./javascript/main.js");
let css = read_file("./css/main.css");
let base_css = read_file("./css/base.css");
html_data = html_data.replace("JAVASCRIPT", &javascript);
html_data = html_data.replace("CSS", &css);
html_data = html_data.replace("BASE_CSS", &base_css);
// html_data = add_component(String::from("header"), html_data);
HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(html_data)
}
-2
View File
@@ -1,14 +1,12 @@
use actix_web::web;
use crate::reader;
mod app;
mod auth;
pub(crate) mod path;
mod users;
pub fn views_factory(app: &mut web::ServiceConfig) {
auth::auth_factory(app);
app::app_factory(app);
users::user_factory(app);
reader::feed_factory(app);
}