From cc4b3bf888096f1e41563761a369998af48200bd Mon Sep 17 00:00:00 2001 From: mooleshacat <43627985+mooleshacat@users.noreply.github.com> Date: Mon, 21 Oct 2024 22:20:20 -0400 Subject: [PATCH] added config variable --- config/config.example.yml | 8 ++++++++ src/invidious/config.cr | 1 + src/invidious/helpers/uptime.cr | 19 ++++++++++++------- src/invidious/views/template.ecr | 6 ++++-- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/config/config.example.yml b/config/config.example.yml index 759b81e0..a9ef777a 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -238,6 +238,14 @@ http_proxy: # Features # ----------------------------- +## +## Enable/Disable showing the uptime on the main page. +## +## Accepted values: true, false +## Default: false +## +#uptime_enabled: true + ## ## Enable/Disable the "Popular" tab on the main page. ## diff --git a/src/invidious/config.cr b/src/invidious/config.cr index 45efc3ff..a5fc0aca 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -102,6 +102,7 @@ class Config # Subscribe to channels using PubSubHubbub (requires domain, hmac_key) property use_pubsub_feeds : Bool | Int32 = false property popular_enabled : Bool = true + property uptime_enabled : Bool = false property captcha_enabled : Bool = true property login_enabled : Bool = true property registration_enabled : Bool = true diff --git a/src/invidious/helpers/uptime.cr b/src/invidious/helpers/uptime.cr index c26d948e..f406cc48 100644 --- a/src/invidious/helpers/uptime.cr +++ b/src/invidious/helpers/uptime.cr @@ -1,15 +1,20 @@ class Invidious::Uptime def self.get_uptime - + str_uptime = "error" - # get the uptime - uptime_cmd = "/usr/bin/uptime" - uptime_args = "-p" - process = Process.new(uptime_cmd, [uptime_args], output: Process::Redirect::Pipe) - - str_uptime = process.output.gets_to_end + if CONFIG.uptime_enabled + + # get the uptime + uptime_cmd = "/usr/bin/uptime" + uptime_args = "-p" + process = Process.new(uptime_cmd, [uptime_args], output: Process::Redirect::Pipe) + str_uptime = process.output.gets_to_end + + else + str_uptime = "" + end return str_uptime diff --git a/src/invidious/views/template.ecr b/src/invidious/views/template.ecr index 23234f59..45f78a43 100644 --- a/src/invidious/views/template.ecr +++ b/src/invidious/views/template.ecr @@ -1,7 +1,7 @@ <% locale = env.get("preferences").as(Preferences).locale dark_mode = env.get("preferences").as(Preferences).dark_mode - str_uptime = Invidious::Uptime.get_uptime + uptime_enabled = CONFIG.uptime_enabled %> @@ -34,8 +34,10 @@ <% if navbar_search %>
😸Invidious🐈catspeed💨 + <% if uptime_enabled %>
-         server <%= str_uptime %> +         server <%= Invidious::Uptime.get_uptime %> + <% end %>