mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-24 15:08:22 -05:00
♻️ refactor: standardize the content-type
header by using an enum value over typing it manually (#474)
* ♻️ refactor: change content-type * 🐛 fix: change parameters that were passed to the settings function --------- Co-authored-by: neon_arch <mustafadhuleb53@gmail.com>
This commit is contained in:
parent
5b4864424a
commit
5020f36c90
@ -6,15 +6,13 @@ use crate::{
|
||||
config::parser::Config,
|
||||
handler::{file_path, FileType},
|
||||
};
|
||||
use actix_web::{get, web, HttpRequest, HttpResponse};
|
||||
use actix_web::{get, http::header::ContentType, web, HttpRequest, HttpResponse};
|
||||
use std::fs::read_to_string;
|
||||
|
||||
/// Handles the route of index page or main page of the `websurfx` meta search engine website.
|
||||
#[get("/")]
|
||||
pub async fn index(config: web::Data<Config>) -> Result<HttpResponse, Box<dyn std::error::Error>> {
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(
|
||||
Ok(HttpResponse::Ok().content_type(ContentType::html()).body(
|
||||
crate::templates::views::index::index(
|
||||
&config.style.colorscheme,
|
||||
&config.style.theme,
|
||||
@ -29,9 +27,7 @@ pub async fn index(config: web::Data<Config>) -> Result<HttpResponse, Box<dyn st
|
||||
pub async fn not_found(
|
||||
config: web::Data<Config>,
|
||||
) -> Result<HttpResponse, Box<dyn std::error::Error>> {
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(
|
||||
Ok(HttpResponse::Ok().content_type(ContentType::html()).body(
|
||||
crate::templates::views::not_found::not_found(
|
||||
&config.style.colorscheme,
|
||||
&config.style.theme,
|
||||
@ -47,16 +43,14 @@ pub async fn robots_data(_req: HttpRequest) -> Result<HttpResponse, Box<dyn std:
|
||||
let page_content: String =
|
||||
read_to_string(format!("{}/robots.txt", file_path(FileType::Theme)?))?;
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("text/plain; charset=ascii")
|
||||
.content_type(ContentType::plaintext())
|
||||
.body(page_content))
|
||||
}
|
||||
|
||||
/// Handles the route of about page of the `websurfx` meta search engine website.
|
||||
#[get("/about")]
|
||||
pub async fn about(config: web::Data<Config>) -> Result<HttpResponse, Box<dyn std::error::Error>> {
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(
|
||||
Ok(HttpResponse::Ok().content_type(ContentType::html()).body(
|
||||
crate::templates::views::about::about(
|
||||
&config.style.colorscheme,
|
||||
&config.style.theme,
|
||||
@ -71,9 +65,7 @@ pub async fn about(config: web::Data<Config>) -> Result<HttpResponse, Box<dyn st
|
||||
pub async fn settings(
|
||||
config: web::Data<Config>,
|
||||
) -> Result<HttpResponse, Box<dyn std::error::Error>> {
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(
|
||||
Ok(HttpResponse::Ok().content_type(ContentType::html()).body(
|
||||
crate::templates::views::settings::settings(
|
||||
config.safe_search,
|
||||
&config.style.colorscheme,
|
||||
|
@ -11,7 +11,7 @@ use crate::{
|
||||
},
|
||||
results::aggregator::aggregate,
|
||||
};
|
||||
use actix_web::{get, web, HttpRequest, HttpResponse};
|
||||
use actix_web::{get, http::header::ContentType, web, HttpRequest, HttpResponse};
|
||||
use regex::Regex;
|
||||
use std::{
|
||||
fs::File,
|
||||
@ -68,9 +68,7 @@ pub async fn search(
|
||||
get_results(page + 1)
|
||||
);
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(
|
||||
Ok(HttpResponse::Ok().content_type(ContentType::html()).body(
|
||||
crate::templates::views::search::search(
|
||||
&config.style.colorscheme,
|
||||
&config.style.theme,
|
||||
|
Loading…
Reference in New Issue
Block a user