From 877ecd1feea34cb8f67ab0c95664db69ae9a2f27 Mon Sep 17 00:00:00 2001
From: Myzel394 <50424412+Myzel394@users.noreply.github.com>
Date: Thu, 22 Feb 2024 16:48:35 +0100
Subject: [PATCH] fix: Improvements;
---
Cargo.lock | 18 +++
Cargo.toml | 3 +
src/engines/bing.rs | 2 +-
src/engines/engine_base.rs | 20 ++-
src/html/beginning.html | 20 ---
src/main.rs | 87 +++++++++---
src/public/css/finished.css | 10 ++
src/public/css/style.css | 180 +++++++++++++++++++++++++
src/public/html/beginning.html | 239 +++++++++++++++++++++++++++++++++
src/{ => public}/html/end.html | 1 +
src/static_files.rs | 29 ++++
src/utils.rs | 11 ++
12 files changed, 575 insertions(+), 45 deletions(-)
delete mode 100644 src/html/beginning.html
create mode 100644 src/public/css/finished.css
create mode 100644 src/public/css/style.css
create mode 100644 src/public/html/beginning.html
rename src/{ => public}/html/end.html (98%)
diff --git a/Cargo.lock b/Cargo.lock
index 73d4b2a..87076ca 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -557,6 +557,15 @@ dependencies = [
"windows-sys 0.52.0",
]
+[[package]]
+name = "html-escape"
+version = "0.2.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6d1ad449764d627e22bfd7cd5e8868264fc9236e07c752972b4080cd351cb476"
+dependencies = [
+ "utf8-width",
+]
+
[[package]]
name = "http"
version = "0.2.11"
@@ -1631,12 +1640,15 @@ dependencies = [
"async-trait",
"bytes",
"futures",
+ "html-escape",
"lazy-regex",
"lazy_static",
+ "log",
"mio",
"regex",
"reqwest",
"rocket",
+ "rustc-hash",
"rustls",
"rustls-pemfile",
"tokio",
@@ -1952,6 +1964,12 @@ version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
+[[package]]
+name = "utf8-width"
+version = "0.1.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "86bd8d4e895da8537e5315b8254664e6b769c4ff3db18321b297a1e7004392e3"
+
[[package]]
name = "valuable"
version = "0.1.0"
diff --git a/Cargo.toml b/Cargo.toml
index a6f4370..44825fd 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,12 +9,15 @@ edition = "2021"
async-trait = "0.1.77"
bytes = "1.5.0"
futures = "0.3.30"
+html-escape = "0.2.13"
lazy-regex = "3.1.0"
lazy_static = "1.4.0"
+log = "0.4.20"
mio = { version = "0.8.10", features = ["net", "os-poll", ] }
regex = "1.10.3"
reqwest = { version = "0.11.23", features = ["stream"] }
rocket = "0.5.0"
+rustc-hash = "1.1.0"
rustls = { path = "../rustls/rustls", features = ["logging"] }
rustls-pemfile = "2"
tokio = {version = "1.35.1", features = ["full"]}
diff --git a/src/engines/bing.rs b/src/engines/bing.rs
index 7f73f23..ade3009 100644
--- a/src/engines/bing.rs
+++ b/src/engines/bing.rs
@@ -14,7 +14,7 @@ pub mod bing {
lazy_static! {
static ref RESULTS_START: Regex = Regex::new(r#"id="b_results""#).unwrap();
- static ref SINGLE_RESULT: Regex = Regex::new(r#"
(?P.+?).*?(((?P.*?).*?"#).unwrap();
+ static ref SINGLE_RESULT: Regex = Regex::new(r#"(?P.+?).*?(((?P.*?).*?"#).unwrap();
}
#[derive(Clone, Debug)]
diff --git a/src/engines/engine_base.rs b/src/engines/engine_base.rs
index 133729f..7412646 100644
--- a/src/engines/engine_base.rs
+++ b/src/engines/engine_base.rs
@@ -1,14 +1,16 @@
pub mod engine_base {
- use std::{fmt::Display, sync::Arc};
+ use core::fmt;
+ use std::{fmt::Debug, fmt::Display, sync::Arc};
use futures::{lock::Mutex, Future, StreamExt};
use lazy_static::lazy_static;
use regex::Regex;
use reqwest::{Error, Response};
+ use rustc_hash::FxHashMap;
use tokio::sync::mpsc::Sender;
use urlencoding::decode;
- use crate::utils::utils::decode_html_text;
+ use crate::utils::utils::{decode_html_text, hash_string};
lazy_static! {
static ref STRIP: Regex = Regex::new(r"[\s\n]+").unwrap();
@@ -41,6 +43,16 @@ pub mod engine_base {
pub engine: SearchEngine,
}
+ impl SearchResult {
+ pub fn get_html_id(&self) -> String {
+ format!(
+ "html-id-{}-{}",
+ hash_string(&self.url),
+ self.url[self.url.len() - 5..].to_string(),
+ )
+ }
+ }
+
pub trait EngineBase {
fn parse_next<'a>(&mut self) -> Option;
@@ -61,7 +73,9 @@ pub mod engine_base {
request: impl Future