0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-12-22 12:28:21 -05:00

chore: rename from theme to public

This commit is contained in:
neon_arch 2023-05-25 11:50:37 +03:00
parent 211f170178
commit dc3308cb5f
5 changed files with 15 additions and 15 deletions

1
src/handler/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod public_path_handler;

View File

@ -5,7 +5,7 @@ use std::io::Error;
use std::path::Path;
// ------- Constants --------
static THEME_DIRECTORY_NAME: &str = "public";
static PUBLIC_DIRECTORY_NAME: &str = "public";
/// A function which returns an appropriate theme directory path checking if the theme
/// directory exists on that path.
@ -17,11 +17,11 @@ static THEME_DIRECTORY_NAME: &str = "public";
/// 1. `/opt/websurfx` if it not present here then it fallbacks to the next one (2)
/// 2. Under project folder ( or codebase in other words) if it is not present
/// here then it returns an error as mentioned above.
pub fn handle_different_theme_path() -> Result<String, Error> {
if Path::new(format!("/opt/websurfx/{}/", THEME_DIRECTORY_NAME).as_str()).exists() {
Ok(format!("/opt/websurfx/{}", THEME_DIRECTORY_NAME))
} else if Path::new(format!("./{}/", THEME_DIRECTORY_NAME).as_str()).exists() {
Ok(format!("./{}", THEME_DIRECTORY_NAME))
pub fn handle_different_public_path() -> Result<String, Error> {
if Path::new(format!("/opt/websurfx/{}/", PUBLIC_DIRECTORY_NAME).as_str()).exists() {
Ok(format!("/opt/websurfx/{}", PUBLIC_DIRECTORY_NAME))
} else if Path::new(format!("./{}/", PUBLIC_DIRECTORY_NAME).as_str()).exists() {
Ok(format!("./{}", PUBLIC_DIRECTORY_NAME))
} else {
Err(Error::new(
std::io::ErrorKind::NotFound,

View File

@ -4,9 +4,9 @@
pub mod cache;
pub mod config_parser;
pub mod engines;
pub mod handler;
pub mod search_results_handler;
pub mod server;
pub mod theme_handler;
use std::net::TcpListener;
@ -16,7 +16,7 @@ use actix_files as fs;
use actix_web::{dev::Server, middleware::Logger, web, App, HttpServer};
use config_parser::parser::Config;
use handlebars::Handlebars;
use theme_handler::theme_path_handler::handle_different_theme_path;
use handler::public_path_handler::handle_different_public_path;
/// Runs the web server on the provided TCP listener and returns a `Server` instance.
///
@ -41,10 +41,10 @@ use theme_handler::theme_path_handler::handle_different_theme_path;
pub fn run(listener: TcpListener, config: Config) -> std::io::Result<Server> {
let mut handlebars: Handlebars = Handlebars::new();
let theme_folder_path: String = handle_different_theme_path()?;
let public_folder_path: String = handle_different_public_path()?;
handlebars
.register_templates_directory(".html", format!("{}/templates", theme_folder_path))
.register_templates_directory(".html", format!("{}/templates", public_folder_path))
.unwrap();
let handlebars_ref: web::Data<Handlebars> = web::Data::new(handlebars);
@ -56,11 +56,11 @@ pub fn run(listener: TcpListener, config: Config) -> std::io::Result<Server> {
.wrap(Logger::default()) // added logging middleware for logging.
// Serve images and static files (css and js files).
.service(
fs::Files::new("/static", format!("{}/static", theme_folder_path))
fs::Files::new("/static", format!("{}/static", public_folder_path))
.show_files_listing(),
)
.service(
fs::Files::new("/images", format!("{}/images", theme_folder_path))
fs::Files::new("/images", format!("{}/images", public_folder_path))
.show_files_listing(),
)
.service(routes::robots_data) // robots.txt

View File

@ -7,8 +7,8 @@ use std::fs::read_to_string;
use crate::{
cache::cacher::RedisCache,
config_parser::parser::Config,
handler::public_path_handler::handle_different_public_path,
search_results_handler::{aggregation_models::SearchResults, aggregator::aggregate},
theme_handler::theme_path_handler::handle_different_theme_path,
};
use actix_web::{get, web, HttpRequest, HttpResponse};
use handlebars::Handlebars;
@ -148,7 +148,7 @@ pub async fn search(
#[get("/robots.txt")]
pub async fn robots_data(_req: HttpRequest) -> Result<HttpResponse, Box<dyn std::error::Error>> {
let page_content: String =
read_to_string(format!("{}/robots.txt", handle_different_theme_path()?))?;
read_to_string(format!("{}/robots.txt", handle_different_public_path()?))?;
Ok(HttpResponse::Ok()
.content_type("text/plain; charset=ascii")
.body(page_content))

View File

@ -1 +0,0 @@
pub mod theme_path_handler;