From 1fbd6033744b9a85f9280f6fb7f731a9914cb802 Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 29 Oct 2022 15:49:47 +0700 Subject: [PATCH] frontend implementation for snapshot integration --- tubearchivist/home/config.json | 3 ++- tubearchivist/home/src/es/snapshot.py | 1 + tubearchivist/home/src/frontend/forms.py | 9 +++++++++ tubearchivist/home/templates/home/settings.html | 17 +++++++++++++++++ tubearchivist/home/views.py | 5 +++++ 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/tubearchivist/home/config.json b/tubearchivist/home/config.json index 95c12118..a953a497 100644 --- a/tubearchivist/home/config.json +++ b/tubearchivist/home/config.json @@ -37,7 +37,8 @@ "cache_dir": "/cache", "videos": "/youtube", "colors": "dark", - "enable_cast": false + "enable_cast": false, + "enable_snapshot": false }, "scheduler": { "update_subscribed": false, diff --git a/tubearchivist/home/src/es/snapshot.py b/tubearchivist/home/src/es/snapshot.py index c2152198..239fa1ec 100644 --- a/tubearchivist/home/src/es/snapshot.py +++ b/tubearchivist/home/src/es/snapshot.py @@ -34,6 +34,7 @@ class ElasticSnapshot: def setup(self): """setup the snapshot in ES, create or update if needed""" + print("snapshot: run setup") repo_exists = self._check_repo_exists() if not repo_exists: self.create_repo() diff --git a/tubearchivist/home/src/frontend/forms.py b/tubearchivist/home/src/frontend/forms.py index 4459f9b5..90927c4b 100644 --- a/tubearchivist/home/src/frontend/forms.py +++ b/tubearchivist/home/src/frontend/forms.py @@ -74,6 +74,12 @@ class ApplicationSettingsForm(forms.Form): ("1", "enable Cast"), ] + SNAPSHOT_CHOICES = [ + ("", "-- change snapshot settings --"), + ("0", "disable system snapshots"), + ("1", "enable system snapshots"), + ] + SUBTITLE_SOURCE_CHOICES = [ ("", "-- change subtitle source settings"), ("user", "only download user created"), @@ -124,6 +130,9 @@ class ApplicationSettingsForm(forms.Form): application_enable_cast = forms.ChoiceField( widget=forms.Select, choices=CAST_CHOICES, required=False ) + application_enable_snapshot = forms.ChoiceField( + widget=forms.Select, choices=SNAPSHOT_CHOICES, required=False + ) class SchedulerSettingsForm(forms.Form): diff --git a/tubearchivist/home/templates/home/settings.html b/tubearchivist/home/templates/home/settings.html index 6477013d..30b656b9 100644 --- a/tubearchivist/home/templates/home/settings.html +++ b/tubearchivist/home/templates/home/settings.html @@ -153,6 +153,23 @@ {{ app_form.application_enable_cast }} +
+

Snapshots

+
+

Current system snapshot: {{ config.application.enable_snapshot }}

+ Automatically create daily deduplicated snapshots of the index, stored in Elasticsearch. Read first before activating: Wiki.
+ {{ app_form.application_enable_snapshot }} +
+
+ {% if snapshots %} +

Create next snapshot: {{ snapshots.next_exec_str }}, snapshots expire after {{ snapshots.expire_after }}

+
+ {% for snapshot in snapshots.snapshots %} +

Snapshot created on: {{ snapshot.start_date }}, took {{ snapshot.duration_s }}s to create

+ {% endfor %} + {% endif %} +
+
diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index ba5af2f1..f5788d09 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -18,6 +18,7 @@ from django.views import View from home.src.download.yt_dlp_base import CookieHandler from home.src.es.connect import ElasticWrap from home.src.es.index_setup import get_available_backups +from home.src.es.snapshot import ElasticSnapshot from home.src.frontend.api_calls import PostData from home.src.frontend.forms import ( AddToQueueForm, @@ -942,6 +943,7 @@ class SettingsView(View): user_form = UserSettingsForm() app_form = ApplicationSettingsForm() scheduler_form = SchedulerSettingsForm() + snapshots = ElasticSnapshot().get_snapshot_stats() token = self.get_token(request) context = { @@ -953,6 +955,7 @@ class SettingsView(View): "user_form": user_form, "app_form": app_form, "scheduler_form": scheduler_form, + "snapshots": snapshots, "version": settings.TA_VERSION, } @@ -1000,6 +1003,8 @@ class SettingsView(View): for config_value, updated_value in updated: if config_value == "cookie_import": self.process_cookie(config, updated_value) + if config_value == "enable_snapshot": + ElasticSnapshot().setup() def process_cookie(self, config, updated_value): """import and validate cookie"""