feat: adds language support for Wikipedia results and implements 'docker logs -f librex'

This commit is contained in:
Junior L. Botelho (JLB) 2023-02-18 14:16:25 -03:00
parent 1efc101e30
commit 0208b8f738
No known key found for this signature in database
GPG Key ID: 6A25840754F2A524
6 changed files with 21 additions and 3 deletions

View File

@ -8,6 +8,9 @@
"google_language_site" => "",
"google_language_results" => "",
// You can set a language for results in wikipedia
"wikipedia_language": "en",
// You can use any Invidious instance here
"invidious_instance_for_video_results" => "https://invidious.namazso.eu",

View File

@ -19,13 +19,17 @@ export OPEN_SEARCH_HOST=${OPEN_SEARCH_HOST:-"127.0.0.1"}
# Replace the 'config.php' script, which contains the most common search engine configurations, with these environment setups
# These environment setups can be found in 'config.php', and the default configurations can be useful for most use cases
export CONFIG_GOOGLE_DOMAIN=${CONFIG_GOOGLE_DOMAIN:-".com"}
export CONFIG_GOOGLE_DOMAIN=${CONFIG_GOOGLE_DOMAIN:-"com"}
export CONFIG_GOOGLE_LANGUAGE=${CONFIG_GOOGLE_LANGUAGE:-"en"}
export CONFIG_INVIDIOUS_INSTANCE=${CONFIG_INVIDIOUS_INSTANCE:-"invidious.namazso.eu"}
export CONFIG_HIDDEN_SERVICE_SEARCH=${CONFIG_HIDDEN_SERVICE_SEARCH:-false}
export CONFIG_DISABLE_BITTORRENT_SEARCH=${CONFIG_DISABLE_BITTORRENT_SEARCH:-false}
export CONFIG_BITTORRENT_TRACKERS=${CONFIG_BITTORRENT_TRACKERS:-"&tr=http://nyaa.tracker.wf:7777/announce&tr=udp://open.stealth.si:80/announce&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://exodus.desync.com:6969/announce&tr=udp://tracker.torrent.eu.org:451/announce"}
# The settings that will be used to handle Wikipedia results displayed on the libreX search page
# the settings below can be edited via environment variables.
export CONFIG_WIKIPEDIA_LANGUAGE=${CONFIG_WIKIPEDIA_LANGUAGE:-"en"}
# Supported apps integration configuration. These empty spaces can be set up using free hosts as pointers
# A particular example is using the "https://yewtu.be" or a self-hosted host to integrate the invidious app to librex
export APP_INVIDIOUS=${APP_INVIDIOUS:-""}

View File

@ -4,6 +4,8 @@
"google_language" => "${CONFIG_GOOGLE_LANGUAGE}",
"invidious_instance_for_video_results" => "${CONFIG_INVIDIOUS_INSTANCE}",
"wikipedia_language" => "${CONFIG_WIKIPEDIA_LANGUAGE}",
"disable_bittorent_search" => ${CONFIG_DISABLE_BITTORRENT_SEARCH},
"bittorent_trackers" => "${CONFIG_BITTORRENT_TRACKERS}",
"disable_hidden_service_search" => ${CONFIG_HIDDEN_SERVICE_SEARCH},

View File

@ -1,5 +1,9 @@
# Install Nginx with FastCGI enabled, optimizing its performance for serving content
RUN apk add nginx
# forward request and error logs to docker log collector
RUN ln -sf "/dev/stdout" "/var/log/nginx/access.log" &&\
ln -sf "/dev/stderr" "/var/log/nginx/error.log"
# After executing the 'docker run' command, run the 'prepare.sh' script
CMD [ "/bin/sh", "-c", "docker/server/prepare.sh" ]

View File

@ -55,7 +55,8 @@
$url = "https://check.torproject.org/torbulkexitlist";
break;
case 7:
$url = "https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts%7Cpageimages&exintro&explaintext&redirects=1&pithumbsize=500&titles=$query_encoded";
$wikipedia_language = $config->wikipedia_language;
$url = "https://$wikipedia_language.wikipedia.org/w/api.php?format=json&action=query&prop=extracts%7Cpageimages&exintro&explaintext&redirects=1&pithumbsize=500&titles=$query_encoded";
break;
}

View File

@ -1,6 +1,8 @@
<?php
function wikipedia_results($query, $response)
{
global $config;
$query_encoded = urlencode($query);
$json_response = json_decode($response, true);
@ -10,8 +12,10 @@
if (!array_key_exists("missing", $first_page))
{
$description = substr($first_page["extract"], 0, 250) . "...";
$wikipedia_language = $config->wikipedia_language;
$source = check_for_privacy_frontend("https://en.wikipedia.org/wiki/$query");
$source = check_for_privacy_frontend("https://$wikipedia_language.wikipedia.org/wiki/$query");
$response = array(
"special_response" => array(
"response" => htmlspecialchars($description),