0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-10-18 06:22:53 -04:00

Merge branch 'rolling' into feat-inform-user-when-no-engines-are-selected

This commit is contained in:
alamin655 2023-09-23 17:12:58 +05:30 committed by GitHub
commit 017036ed00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 201 additions and 114 deletions

View File

@ -4,6 +4,7 @@
<p align="center"> <p align="center">
<b align="center"><a href="README.md">Readme</a></b> | <b align="center"><a href="README.md">Readme</a></b> |
<b><a href="https://discord.gg/SWnda7Mw5u">Discord</a></b> | <b><a href="https://discord.gg/SWnda7Mw5u">Discord</a></b> |
<b><a href="https://discord.gg/VKCAememnr">User Showcase</a></b> |
<b><a href="https://github.com/neon-mmd/websurfx">GitHub</a></b> | <b><a href="https://github.com/neon-mmd/websurfx">GitHub</a></b> |
<b><a href="../../tree/HEAD/docs/">Documentation</a></b> <b><a href="../../tree/HEAD/docs/">Documentation</a></b>
<br /><br /> <br /><br />
@ -57,28 +58,19 @@
<p> <p>
- **Getting Started** - **Getting Started**
- [🔭 Preview](#preview-) - [🔭 Preview](#preview-)
- [🚀 Features](#features-) - [🚀 Features](#features-)
- [🛠️ Installation and Testing](#installation-and-testing-%EF%B8%8F) - [🛠️ Installation and Testing](#installation-and-testing-%EF%B8%8F)
- [🔧 Configuration](#configuration-) - [🔧 Configuration](#configuration-)
- **Feature Overview** - **Feature Overview**
- [🎨 Theming](#theming-) - [🎨 Theming](#theming-)
- [🌍 Multi-Language Support](#multi-language-support-) - [🌍 Multi-Language Support](#multi-language-support-)
- **Community** - **Community** - [📊 System Requirements](#system-requirements-) - [🗨️ FAQ (Frequently Asked Questions)](#faq-frequently-asked-questions-) - [📣 More Contributors Wanted](#more-contributors-wanted-) - [💖 Supporting Websurfx](#supporting-websurfx-) - [📘 Documentation](#documentation-) - [🛣️ Roadmap](#roadmap-) - [🙋 Contributing](#contributing-) - [📜 License](#license-) - [🤝 Credits](#credits-)
- [📊 System Requirements](#system-requirements-)
- [🗨️ FAQ (Frequently Asked Questions)](#faq-frequently-asked-questions-)
- [📣 More Contributors Wanted](#more-contributors-wanted-)
- [💖 Supporting Websurfx](#supporting-websurfx-)
- [📘 Documentation](#documentation-)
- [🛣️ Roadmap](#roadmap-)
- [🙋 Contributing](#contributing-)
- [📜 License](#license-)
- [🤝 Credits](#credits-)
</p> </p>
</details> </details>
# Preview 🔭 # Preview 🔭
## Home Page ## Home Page
@ -94,7 +86,7 @@
**[⬆️ Back to Top](#--)** **[⬆️ Back to Top](#--)**
# Features 🚀 # Features 🚀
- 🎨 Make Websurfx uniquely yours with twelve color schemes provided by default. It also supports creation of custom themes and color schemes in a quick and easy way, so unleash your creativity! - 🎨 Make Websurfx uniquely yours with twelve color schemes provided by default. It also supports creation of custom themes and color schemes in a quick and easy way, so unleash your creativity!
- 🔐 Fast, private, and secure - 🔐 Fast, private, and secure
@ -104,7 +96,7 @@
**[⬆️ Back to Top](#--)** **[⬆️ Back to Top](#--)**
# Installation and Testing 🛠️ # Installation and Testing 🛠️
> For full setup instructions, see: [**Installation**](./docs/installation.md) > For full setup instructions, see: [**Installation**](./docs/installation.md)
@ -112,7 +104,7 @@ Before you can start building `websurfx`, you will need to have `Cargo` installe
To get started with Websurfx, clone the repository, edit the config file, which is located in the `websurfx/` directory, and install the Redis server by following the instructions located [here](https://redis.io/docs/getting-started/) and then run the websurfx server and redis server using the following commands: To get started with Websurfx, clone the repository, edit the config file, which is located in the `websurfx/` directory, and install the Redis server by following the instructions located [here](https://redis.io/docs/getting-started/) and then run the websurfx server and redis server using the following commands:
``` shell ```shell
git clone https://github.com/neon-mmd/websurfx.git git clone https://github.com/neon-mmd/websurfx.git
cd websurfx cd websurfx
git checkout stable git checkout stable
@ -128,7 +120,7 @@ Once you have started the server, open your preferred web browser and navigate t
**[⬆️ Back to Top](#--)** **[⬆️ Back to Top](#--)**
# Configuration 🔧 # Configuration 🔧
> For full configuration instructions, see: [**Configuration**](./docs/configuration.md) > For full configuration instructions, see: [**Configuration**](./docs/configuration.md)
@ -136,7 +128,7 @@ Websurfx is configured through the config.lua file, located at `websurfx/config.
**[⬆️ Back to Top](#--)** **[⬆️ Back to Top](#--)**
# Theming 🎨 # Theming 🎨
> For full theming and customization instructions, see: [**Theming**](./docs/theming.md) > For full theming and customization instructions, see: [**Theming**](./docs/theming.md)
@ -173,7 +165,7 @@ Websurfx is based on Rust due to its memory safety features, which prevents vuln
**[⬆️ Back to Top](#--)** **[⬆️ Back to Top](#--)**
# More Contributors Wanted 📣 # More Contributors Wanted 📣
We are looking for more willing contributors to help grow this project. For more information on how you can contribute, check out the [project board](https://github.com/neon-mmd/websurfx/projects?query=is%3Aopen) and the [CONTRIBUTING.md](CONTRIBUTING.md) file for guidelines and rules for making contributions. We are looking for more willing contributors to help grow this project. For more information on how you can contribute, check out the [project board](https://github.com/neon-mmd/websurfx/projects?query=is%3Aopen) and the [CONTRIBUTING.md](CONTRIBUTING.md) file for guidelines and rules for making contributions.
@ -186,6 +178,7 @@ We are looking for more willing contributors to help grow this project. For more
If you use Websurfx and would like to contribute to its development, we're glad to have you on board! Contributions of any size or type are always welcome, and we will always acknowledge your efforts. If you use Websurfx and would like to contribute to its development, we're glad to have you on board! Contributions of any size or type are always welcome, and we will always acknowledge your efforts.
Several areas that we need a bit of help with at the moment are: Several areas that we need a bit of help with at the moment are:
- **Better and more color schemes**: Help fix color schemes and add other famous color schemes. - **Better and more color schemes**: Help fix color schemes and add other famous color schemes.
- **Improve evasion code for bot detection** - Help improve code related to evading IP blocking and emulating human behaviors located in everyone's engine file. - **Improve evasion code for bot detection** - Help improve code related to evading IP blocking and emulating human behaviors located in everyone's engine file.
- **Logo** - Help create a logo for the project and website. - **Logo** - Help create a logo for the project and website.
@ -198,7 +191,7 @@ Several areas that we need a bit of help with at the moment are:
# Documentation 📘 # Documentation 📘
> **Note** > **Note**
> We welcome any contributions to the [documentation](../../tree/HEAD/docs/) as this will benefit everyone who uses this project. > We welcome any contributions to the [documentation](../../tree/HEAD/docs/) as this will benefit everyone who uses this project.
**[⬆️ Back to Top](#--)** **[⬆️ Back to Top](#--)**
@ -208,7 +201,7 @@ Several areas that we need a bit of help with at the moment are:
**[⬆️ Back to Top](#--)** **[⬆️ Back to Top](#--)**
# Contributing 🙋 # Contributing 🙋
Contributions are welcome from anyone. It doesn't matter who you are; you can still contribute to the project in your own way. Contributions are welcome from anyone. It doesn't matter who you are; you can still contribute to the project in your own way.
@ -222,13 +215,13 @@ If you are a developer, have a look at the [CONTRIBUTING.org](CONTRIBUTING.md) d
**[⬆️ Back to Top](#--)** **[⬆️ Back to Top](#--)**
# License 📜 # License 📜
Websurfx is licensed under the [AGPLv3](LICENSE) license. Websurfx is licensed under the [AGPLv3](LICENSE) license.
**[⬆️ Back to Top](#--)** **[⬆️ Back to Top](#--)**
# Credits 🤝 # Credits 🤝
We would like to thank the following people for their contributions and support: We would like to thank the following people for their contributions and support:

View File

@ -16,8 +16,9 @@ document.addEventListener(
let cookie = decodeURIComponent(document.cookie) let cookie = decodeURIComponent(document.cookie)
// Set the value of the input field to the decoded cookie value if it is not empty // Set the value of the input field to the decoded cookie value if it is not empty
// Otherwise, display a message indicating that no cookies have been saved on the user's system // Otherwise, display a message indicating that no cookies have been saved on the user's system
document.querySelector('.cookies input').value = document.querySelector('.cookies input').value = cookie.length
cookie !== '' ? cookie : 'No cookies have been saved on your system' ? cookie
: 'No cookies have been saved on your system'
} catch (error) { } catch (error) {
// If there is an error decoding the cookie, log the error to the console // If there is an error decoding the cookie, log the error to the console
// and display an error message in the input field // and display an error message in the input field
@ -25,5 +26,5 @@ document.addEventListener(
document.querySelector('.cookies input').value = 'Error decoding cookie' document.querySelector('.cookies input').value = 'Error decoding cookie'
} }
}, },
false false,
) )

View File

@ -2,16 +2,25 @@
* Selects the input element for the search box * Selects the input element for the search box
* @type {HTMLInputElement} * @type {HTMLInputElement}
*/ */
const searchBox = document.querySelector('input'); const searchBox = document.querySelector('input')
/** /**
* Redirects the user to the search results page with the query parameter * Redirects the user to the search results page with the query parameter
*/ */
function searchWeb() { function searchWeb() {
const query = searchBox.value.trim(); const query = searchBox.value.trim()
if (query) { try {
window.location.href = `search?q=${encodeURIComponent(query)}`; let safeSearchLevel = document.querySelector('.search_options select').value
} if (query) {
window.location.href = `search?q=${encodeURIComponent(
query,
)}&safesearch=${encodeURIComponent(safeSearchLevel)}`
}
} catch (error) {
if (query) {
window.location.href = `search?q=${encodeURIComponent(query)}`
}
}
} }
/** /**
@ -19,7 +28,7 @@ function searchWeb() {
* @param {KeyboardEvent} e - The keyboard event object * @param {KeyboardEvent} e - The keyboard event object
*/ */
searchBox.addEventListener('keyup', (e) => { searchBox.addEventListener('keyup', (e) => {
if (e.key === 'Enter') { if (e.key === 'Enter') {
searchWeb(); searchWeb()
} }
}); })

View File

@ -3,8 +3,8 @@
* @returns {void} * @returns {void}
*/ */
function navigate_forward() { function navigate_forward() {
const url = new URL(window.location); let url = new URL(window.location);
const searchParams = url.searchParams; let searchParams = url.searchParams;
let q = searchParams.get('q'); let q = searchParams.get('q');
let page = parseInt(searchParams.get('page')); let page = parseInt(searchParams.get('page'));
@ -23,8 +23,8 @@ function navigate_forward() {
* @returns {void} * @returns {void}
*/ */
function navigate_backward() { function navigate_backward() {
const url = new URL(window.location); let url = new URL(window.location);
const searchParams = url.searchParams; let searchParams = url.searchParams;
let q = searchParams.get('q'); let q = searchParams.get('q');
let page = parseInt(searchParams.get('page')); let page = parseInt(searchParams.get('page'));

View File

@ -0,0 +1,18 @@
document.addEventListener(
'DOMContentLoaded',
() => {
let url = new URL(window.location)
let searchParams = url.searchParams
let safeSearchLevel = searchParams.get('safesearch')
if (
safeSearchLevel >= 0 &&
safeSearchLevel <= 2 &&
safeSearchLevel !== null
) {
document.querySelector('.search_options select').value = safeSearchLevel
}
},
false,
)

View File

@ -1,5 +1,5 @@
/** /**
* This function handles the toggling of selections of all upstream search engines * This function handles the toggling of selections of all upstream search engines
* options in the settings page under the tab engines. * options in the settings page under the tab engines.
*/ */
function toggleAllSelection() { function toggleAllSelection() {
@ -8,12 +8,12 @@ function toggleAllSelection() {
.forEach( .forEach(
(engine_checkbox) => (engine_checkbox) =>
(engine_checkbox.checked = (engine_checkbox.checked =
document.querySelector('.select_all').checked) document.querySelector('.select_all').checked),
) )
} }
/** /**
* This function adds the functionality to sidebar buttons to only show settings * This function adds the functionality to sidebar buttons to only show settings
* related to that tab. * related to that tab.
* @param {HTMLElement} current_tab - The current tab that was clicked. * @param {HTMLElement} current_tab - The current tab that was clicked.
*/ */
@ -43,20 +43,28 @@ function setClientSettings() {
// Loop through all select tags and add their values to the cookie dictionary // Loop through all select tags and add their values to the cookie dictionary
document.querySelectorAll('select').forEach((select_tag) => { document.querySelectorAll('select').forEach((select_tag) => {
if (select_tag.name === 'themes') { switch (select_tag.name) {
cookie_dictionary['theme'] = select_tag.value case 'themes':
} else if (select_tag.name === 'colorschemes') { cookie_dictionary['theme'] = select_tag.value
cookie_dictionary['colorscheme'] = select_tag.value break
case 'colorschemes':
cookie_dictionary['colorscheme'] = select_tag.value
break
case 'safe_search_levels':
cookie_dictionary['safe_search_level'] = Number(select_tag.value)
break
} }
}) })
// Loop through all engine checkboxes and add their values to the cookie dictionary // Loop through all engine checkboxes and add their values to the cookie dictionary
let engines = [] let engines = []
document.querySelectorAll('.engine').forEach((engine_checkbox) => { document.querySelectorAll('.engine').forEach((engine_checkbox) => {
if (engine_checkbox.checked === true) { if (engine_checkbox.checked) {
engines.push(engine_checkbox.parentNode.parentNode.innerText.trim()) engines.push(engine_checkbox.parentNode.parentNode.innerText.trim())
} }
}) })
cookie_dictionary['engines'] = engines cookie_dictionary['engines'] = engines
// Set the expiration date for the cookie to 1 year from the current date // Set the expiration date for the cookie to 1 year from the current date
@ -65,7 +73,7 @@ function setClientSettings() {
// Save the cookie to the user's machine // Save the cookie to the user's machine
document.cookie = `appCookie=${JSON.stringify( document.cookie = `appCookie=${JSON.stringify(
cookie_dictionary cookie_dictionary,
)}; expires=${expiration_date.toUTCString()}` )}; expires=${expiration_date.toUTCString()}`
// Display a success message to the user // Display a success message to the user
@ -79,9 +87,9 @@ function setClientSettings() {
} }
/** /**
* This functions gets the saved cookies if it is present on the user's machine If it * This functions gets the saved cookies if it is present on the user's machine If it
* is available then it is parsed and converted to an object which is then used to * is available then it is parsed and converted to an object which is then used to
* retrieve the preferences that the user had selected previously and is then loaded in the * retrieve the preferences that the user had selected previously and is then loaded in the
* website otherwise the function does nothing and the default server side settings are loaded. * website otherwise the function does nothing and the default server side settings are loaded.
*/ */
function getClientSettings() { function getClientSettings() {
@ -89,21 +97,19 @@ function getClientSettings() {
let cookie = decodeURIComponent(document.cookie) let cookie = decodeURIComponent(document.cookie)
// If the cookie is not empty, parse it and use it to set the user's preferences // If the cookie is not empty, parse it and use it to set the user's preferences
if (cookie !== '') { if (cookie.length) {
let cookie_value = decodeURIComponent(document.cookie) let cookie_value = cookie
.split(';') .split(';')
.map((item) => item.split('=')) .map((item) => item.split('='))
.reduce((acc, [_, v]) => (acc = JSON.parse(v)) && acc, {}) .reduce((acc, [_, v]) => (acc = JSON.parse(v)) && acc, {})
// Loop through all link tags and update their href values to match the user's preferences // Loop through all link tags and update their href values to match the user's preferences
let links = Array.from(document.querySelectorAll('link')).forEach( Array.from(document.querySelectorAll('link')).forEach((item) => {
(item) => { if (item.href.includes('static/themes')) {
if (item.href.includes('static/themes')) { item.href = `static/themes/${cookie_value['theme']}.css`
item.href = `static/themes/${cookie_value['theme']}.css` } else if (item.href.includes('static/colorschemes')) {
} else if (item.href.includes('static/colorschemes')) { item.href = `static/colorschemes/${cookie_value['colorscheme']}.css`
item.href = `static/colorschemes/${cookie_value['colorscheme']}.css`
}
} }
) })
} }
} }

View File

@ -70,6 +70,28 @@ body {
filter: brightness(1.2); filter: brightness(1.2);
} }
.search_area .search_options {
display: flex;
justify-content: space-between;
align-items: center;
}
.search_area .search_options select {
margin: 0.7rem 0;
width: 20rem;
background-color: var(--color-one);
color: var(--foreground-color);
padding: 1rem 2rem;
border-radius: 0.5rem;
outline: none;
border: none;
text-transform: capitalize;
}
.search_area .search_options option:hover {
background-color: var(--color-one);
}
.result_not_found { .result_not_found {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -503,7 +525,8 @@ footer {
color: var(--foreground-color); color: var(--foreground-color);
} }
.settings_container .user_interface select { .settings_container .user_interface select,
.settings_container .general select {
margin: 0.7rem 0; margin: 0.7rem 0;
width: 20rem; width: 20rem;
background-color: var(--background-color); background-color: var(--background-color);
@ -515,7 +538,8 @@ footer {
text-transform: capitalize; text-transform: capitalize;
} }
.settings_container .user_interface option:hover { .settings_container .user_interface option:hover,
.settings_container .general option:hover {
background-color: var(--color-one); background-color: var(--color-one);
} }

View File

@ -1,4 +1,5 @@
<div class="engines tab"> <div class="engines tab">
<h1>Engines</h1>
<h3>select search engines</h3> <h3>select search engines</h3>
<p class="description"> <p class="description">
Select the search engines from the list of engines that you want results Select the search engines from the list of engines that you want results

View File

@ -1,4 +1,13 @@
<div class="general tab active"> <div class="general tab active">
<h1>General</h1> <h1>General</h1>
<p class="description">Coming soon!!</p> <h3>Select a safe search level</h3>
<p class="description">
Select a safe search level from the menu below to filter content based on
the level.
</p>
<select name="safe_search_levels">
<option value=0>None</option>
<option value=1>Low</option>
<option value=2>Moderate</option>
</select>
</div> </div>

View File

@ -80,6 +80,7 @@
</div> </div>
</main> </main>
<script src="static/index.js"></script> <script src="static/index.js"></script>
<script src="static/search_area_options.js"></script>
<script src="static/pagination.js"></script> <script src="static/pagination.js"></script>
<script src="static/error_box.js"></script> <script src="static/error_box.js"></script>
{{>footer}} {{>footer}}

View File

@ -1,27 +1,36 @@
{{>bar this}} <div class="search_area">
<div class="error_box"> {{>bar this}}
{{#if engineErrorsInfo}} <div class="error_box">
<button onclick="toggleErrorBox()" class="error_box_toggle_button"> {{#if engineErrorsInfo}}
<img src="./images/warning.svg" alt="Info icon for error box" /> <button onclick="toggleErrorBox()" class="error_box_toggle_button">
</button> <img src="./images/warning.svg" alt="Info icon for error box" />
<div class="dropdown_error_box"> </button>
{{#each engineErrorsInfo}} <div class="dropdown_error_box">
<div class="error_item"> {{#each engineErrorsInfo}}
<span class="engine_name">{{{this.engine}}}</span> <div class="error_item">
<span class="engine_name">{{{this.error}}}</span> <span class="engine_name">{{{this.engine}}}</span>
<span class="severity_color" style="background: {{{this.severity_color}}};"></span> <span class="engine_name">{{{this.error}}}</span>
<span class="severity_color" style="background: {{{this.severity_color}}};"></span>
</div>
{{/each}}
</div> </div>
{{/each}} {{else}}
</div> <button onclick="toggleErrorBox()" class="error_box_toggle_button">
{{else}} <img src="./images/info.svg" alt="Warning icon for error box" />
<button onclick="toggleErrorBox()" class="error_box_toggle_button"> </button>
<img src="./images/info.svg" alt="Warning icon for error box" /> <div class="dropdown_error_box">
</button> <div class="no_errors">
<div class="dropdown_error_box"> Everything looks good 🙂!!
<div class="no_errors"> </div>
Everything looks good 🙂!!
</div> </div>
{{/if}}
</div> </div>
{{/if}} </div>
<div class="search_options">
<select name="safe_search_levels" {{#if (gte safeSearchLevel 3)}} disabled {{/if}}>
<option value=0 {{#if (eq safeSearchLevel 0)}} selected {{/if}}>SafeSearch: None</option>
<option value=1 {{#if (eq safeSearchLevel 1)}} selected {{/if}}>SafeSearch: Low</option>
<option value=2 {{#if (eq safeSearchLevel 2)}} selected {{/if}}>SafeSearch: Moderate</option>
</select>
</div> </div>
</div> </div>

View File

@ -1,4 +1,5 @@
<div class="user_interface tab"> <div class="user_interface tab">
<h1>User Interface</h1>
<h3>select theme</h3> <h3>select theme</h3>
<p class="description"> <p class="description">
Select the theme from the available themes to be used in user interface Select the theme from the available themes to be used in user interface

View File

@ -26,4 +26,6 @@ pub struct Cookie<'a> {
pub colorscheme: &'a str, pub colorscheme: &'a str,
/// It stores the user selected upstream search engines selected from the UI. /// It stores the user selected upstream search engines selected from the UI.
pub engines: Vec<&'a str>, pub engines: Vec<&'a str>,
/// It stores the user selected safe search level from the UI.
pub safe_search_level: u8,
} }

View File

@ -67,61 +67,48 @@ pub async fn search(
None => 1, None => 1,
}; };
let safe_search: u8 = match config.safe_search {
3..=4 => config.safe_search,
_ => match &params.safesearch {
Some(safesearch) => match safesearch {
0..=2 => *safesearch,
_ => 1,
},
None => config.safe_search,
},
};
let (_, results, _) = join!( let (_, results, _) = join!(
results( results(
format!( format!(
"http://{}:{}/search?q={}&page={}&safesearch={}", "http://{}:{}/search?q={}&page={}&safesearch=",
config.binding_ip, config.binding_ip,
config.port, config.port,
query, query,
page - 1, page - 1,
safe_search
), ),
&config, &config,
&cache, &cache,
query, query,
page - 1, page - 1,
req.clone(), req.clone(),
safe_search &params.safesearch
), ),
results( results(
format!( format!(
"http://{}:{}/search?q={}&page={}&safesearch={}", "http://{}:{}/search?q={}&page={}&safesearch=",
config.binding_ip, config.port, query, page, safe_search config.binding_ip, config.port, query, page
), ),
&config, &config,
&cache, &cache,
query, query,
page, page,
req.clone(), req.clone(),
safe_search &params.safesearch
), ),
results( results(
format!( format!(
"http://{}:{}/search?q={}&page={}&safesearch={}", "http://{}:{}/search?q={}&page={}&safesearch=",
config.binding_ip, config.binding_ip,
config.port, config.port,
query, query,
page + 1, page + 1,
safe_search
), ),
&config, &config,
&cache, &cache,
query, query,
page + 1, page + 1,
req.clone(), req.clone(),
safe_search &params.safesearch
) )
); );
@ -156,7 +143,7 @@ async fn results(
query: &str, query: &str,
page: u32, page: u32,
req: HttpRequest, req: HttpRequest,
safe_search: u8, safe_search: &Option<u8>,
) -> Result<SearchResults, Box<dyn std::error::Error>> { ) -> Result<SearchResults, Box<dyn std::error::Error>> {
// fetch the cached results json. // fetch the cached results json.
let cached_results = cache.cached_json(&url).await; let cached_results = cache.cached_json(&url).await;
@ -165,7 +152,18 @@ async fn results(
match cached_results { match cached_results {
Ok(results) => Ok(results), Ok(results) => Ok(results),
Err(_) => { Err(_) => {
if safe_search == 4 { let mut safe_search_level: u8 = match config.safe_search {
3..=4 => config.safe_search,
_ => match safe_search {
Some(safesearch) => match safesearch {
0..=2 => *safesearch,
_ => config.safe_search,
},
None => config.safe_search,
},
};
if safe_search_level == 4 {
let mut results: SearchResults = SearchResults::default(); let mut results: SearchResults = SearchResults::default();
let mut _flag: bool = let mut _flag: bool =
is_match_from_filter_list(file_path(FileType::BlockList)?, query)?; is_match_from_filter_list(file_path(FileType::BlockList)?, query)?;
@ -176,6 +174,7 @@ async fn results(
results.add_style(&config.style); results.add_style(&config.style);
results.set_page_query(query); results.set_page_query(query);
cache.cache_results(&results, &url).await?; cache.cache_results(&results, &url).await?;
results.set_safe_search_level(safe_search_level);
return Ok(results); return Ok(results);
} }
} }
@ -195,6 +194,17 @@ async fn results(
.filter_map(|name| EngineHandler::new(name)) .filter_map(|name| EngineHandler::new(name))
.collect(); .collect();
safe_search_level = match config.safe_search {
3..=4 => config.safe_search,
_ => match safe_search {
Some(safesearch) => match safesearch {
0..=2 => *safesearch,
_ => config.safe_search,
},
None => cookie_value.safe_search_level,
},
};
match engines.is_empty() { match engines.is_empty() {
false => { false => {
aggregate( aggregate(
@ -224,7 +234,7 @@ async fn results(
config.debug, config.debug,
&config.upstream_search_engines, &config.upstream_search_engines,
config.request_timeout, config.request_timeout,
safe_search, safe_search_level,
) )
.await? .await?
} }
@ -236,7 +246,10 @@ async fn results(
results.set_filtered(); results.set_filtered();
} }
results.add_style(&config.style); results.add_style(&config.style);
cache.cache_results(&results, &url).await?; cache
.cache_results(&results, &(format!("{url}{safe_search_level}")))
.await?;
results.set_safe_search_level(safe_search_level);
Ok(results) Ok(results)
} }
} }