mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-26 15:58:21 -05:00
Compare commits
2 Commits
3dc5f62e49
...
3f02f670bc
Author | SHA1 | Date | |
---|---|---|---|
|
3f02f670bc | ||
|
6aa99922a6 |
@ -48,7 +48,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
config.port,
|
config.port,
|
||||||
);
|
);
|
||||||
|
|
||||||
let listener = TcpListener::bind((config.binding_ip.clone(), config.port))?;
|
let listener = TcpListener::bind((config.binding_ip.as_str(), config.port))?;
|
||||||
|
|
||||||
run(listener, config, cache)?.await
|
run(listener, config, cache)?.await
|
||||||
}
|
}
|
||||||
|
1
src/cache/redis_cacher.rs
vendored
1
src/cache/redis_cacher.rs
vendored
@ -11,7 +11,6 @@ const REDIS_PIPELINE_SIZE: usize = 3;
|
|||||||
|
|
||||||
/// A named struct which stores the redis Connection url address to which the client will
|
/// A named struct which stores the redis Connection url address to which the client will
|
||||||
/// connect to.
|
/// connect to.
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct RedisCache {
|
pub struct RedisCache {
|
||||||
/// It stores a pool of connections ready to be used.
|
/// It stores a pool of connections ready to be used.
|
||||||
connection_pool: Vec<ConnectionManager>,
|
connection_pool: Vec<ConnectionManager>,
|
||||||
|
@ -9,7 +9,6 @@ use mlua::Lua;
|
|||||||
use std::{collections::HashMap, fs, thread::available_parallelism};
|
use std::{collections::HashMap, fs, thread::available_parallelism};
|
||||||
|
|
||||||
/// A named struct which stores the parsed config file options.
|
/// A named struct which stores the parsed config file options.
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
/// It stores the parsed port number option on which the server should launch.
|
/// It stores the parsed port number option on which the server should launch.
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
|
@ -69,8 +69,6 @@ pub fn run(
|
|||||||
) -> std::io::Result<Server> {
|
) -> std::io::Result<Server> {
|
||||||
let public_folder_path: &str = file_path(FileType::Theme)?;
|
let public_folder_path: &str = file_path(FileType::Theme)?;
|
||||||
|
|
||||||
let cloned_config_threads_opt: u8 = config.threads;
|
|
||||||
|
|
||||||
let cache = SHARED_CACHE.get_or_init(|| SharedCache::new(cache));
|
let cache = SHARED_CACHE.get_or_init(|| SharedCache::new(cache));
|
||||||
|
|
||||||
let server = HttpServer::new(move || {
|
let server = HttpServer::new(move || {
|
||||||
@ -114,7 +112,7 @@ pub fn run(
|
|||||||
.service(router::settings) // settings page
|
.service(router::settings) // settings page
|
||||||
.default_service(web::route().to(router::not_found)) // error page
|
.default_service(web::route().to(router::not_found)) // error page
|
||||||
})
|
})
|
||||||
.workers(cloned_config_threads_opt as usize)
|
.workers(config.threads as usize)
|
||||||
// Start server on 127.0.0.1 with the user provided port number. for example 127.0.0.1:8080.
|
// Start server on 127.0.0.1 with the user provided port number. for example 127.0.0.1:8080.
|
||||||
.listen(listener)?
|
.listen(listener)?
|
||||||
.run();
|
.run();
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
/// order to allow the deserializing the json back to struct in aggregate function in
|
/// order to allow the deserializing the json back to struct in aggregate function in
|
||||||
/// aggregator.rs and create a new struct out of it and then serialize it back to json and pass
|
/// aggregator.rs and create a new struct out of it and then serialize it back to json and pass
|
||||||
/// it to the template files.
|
/// it to the template files.
|
||||||
#[derive(Clone, Default)]
|
#[derive(Default)]
|
||||||
pub struct Style {
|
pub struct Style {
|
||||||
/// It stores the parsed theme option used to set a theme for the website.
|
/// It stores the parsed theme option used to set a theme for the website.
|
||||||
pub theme: String,
|
pub theme: String,
|
||||||
@ -40,7 +40,6 @@ impl Style {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Configuration options for the aggregator.
|
/// Configuration options for the aggregator.
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct AggregatorConfig {
|
pub struct AggregatorConfig {
|
||||||
/// It stores the option to whether enable or disable random delays between
|
/// It stores the option to whether enable or disable random delays between
|
||||||
/// requests.
|
/// requests.
|
||||||
@ -48,7 +47,6 @@ pub struct AggregatorConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Configuration options for the rate limiter middleware.
|
/// Configuration options for the rate limiter middleware.
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct RateLimiter {
|
pub struct RateLimiter {
|
||||||
/// The number of request that are allowed within a provided time limit.
|
/// The number of request that are allowed within a provided time limit.
|
||||||
pub number_of_requests: u8,
|
pub number_of_requests: u8,
|
||||||
|
@ -12,6 +12,7 @@ use error_stack::Report;
|
|||||||
use futures::stream::FuturesUnordered;
|
use futures::stream::FuturesUnordered;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use reqwest::{Client, ClientBuilder};
|
use reqwest::{Client, ClientBuilder};
|
||||||
|
use std::sync::Arc;
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
use std::{fs::File, io::BufRead};
|
use std::{fs::File, io::BufRead};
|
||||||
use std::{
|
use std::{
|
||||||
@ -98,13 +99,20 @@ pub async fn aggregate(
|
|||||||
// create tasks for upstream result fetching
|
// create tasks for upstream result fetching
|
||||||
let tasks: FutureVec = FutureVec::new();
|
let tasks: FutureVec = FutureVec::new();
|
||||||
|
|
||||||
|
let query: Arc<String> = Arc::new(query.to_string());
|
||||||
for engine_handler in upstream_search_engines {
|
for engine_handler in upstream_search_engines {
|
||||||
let (name, search_engine) = engine_handler.to_owned().into_name_engine();
|
let (name, search_engine) = engine_handler.clone().into_name_engine();
|
||||||
names.push(name);
|
names.push(name);
|
||||||
let query: String = query.to_owned();
|
let query_partially_cloned = query.clone();
|
||||||
tasks.push(tokio::spawn(async move {
|
tasks.push(tokio::spawn(async move {
|
||||||
search_engine
|
search_engine
|
||||||
.results(&query, page, user_agent, client, safe_search)
|
.results(
|
||||||
|
&query_partially_cloned,
|
||||||
|
page,
|
||||||
|
user_agent,
|
||||||
|
client,
|
||||||
|
safe_search,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ pub fn engines(engine_names: &HashMap<String, bool>) -> Markup {
|
|||||||
input type="checkbox" class="engine" checked;
|
input type="checkbox" class="engine" checked;
|
||||||
span class="slider round"{}
|
span class="slider round"{}
|
||||||
}
|
}
|
||||||
(format!("{}{}",engine_name[..1].to_uppercase().to_owned(), engine_name[1..].to_owned()))
|
(format!("{}{}",&engine_name[..1].to_uppercase(), &engine_name[1..]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@else {
|
@else {
|
||||||
@ -64,7 +64,7 @@ pub fn engines(engine_names: &HashMap<String, bool>) -> Markup {
|
|||||||
input type="checkbox" class="engine";
|
input type="checkbox" class="engine";
|
||||||
span class="slider round"{}
|
span class="slider round"{}
|
||||||
}
|
}
|
||||||
(format!("{}{}",engine_name[..1].to_uppercase().to_owned(), engine_name[1..].to_owned()))
|
(format!("{}{}",&engine_name[..1], &engine_name[1..]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ fn style_option_list(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if style_type == "animations" {
|
if style_type == "animations" {
|
||||||
style_option_names.push(("".to_owned(), "none".to_owned()))
|
style_option_names.push((String::default(), "none".to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(style_option_names)
|
Ok(style_option_names)
|
||||||
@ -83,9 +83,11 @@ pub fn user_interface(
|
|||||||
"Select the animation for your theme to be used in user interface"
|
"Select the animation for your theme to be used in user interface"
|
||||||
}
|
}
|
||||||
select name="animations"{
|
select name="animations"{
|
||||||
|
@let default_animation = &String::default();
|
||||||
|
@let animation = animation.as_ref().unwrap_or(default_animation);
|
||||||
// Sets the user selected animation name from the config file as the first option in the selection list.
|
// Sets the user selected animation name from the config file as the first option in the selection list.
|
||||||
option value=(animation.as_ref().unwrap_or(&"".to_owned())){(animation.as_ref().unwrap_or(&"".to_owned()).replace('-'," "))}
|
option value=(animation){(animation.replace('-'," "))}
|
||||||
@for (k,v) in style_option_list("animations", animation.as_ref().unwrap_or(&"".to_owned()))?{
|
@for (k,v) in style_option_list("animations", animation)?{
|
||||||
option value=(k){(v)}
|
option value=(k){(v)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ pub fn search(
|
|||||||
small{(result.url)}
|
small{(result.url)}
|
||||||
p{(PreEscaped(&result.description))}
|
p{(PreEscaped(&result.description))}
|
||||||
.upstream_engines{
|
.upstream_engines{
|
||||||
@for name in result.clone().engine{
|
@for name in &result.engine {
|
||||||
span{(name)}
|
span{(name)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user