frontend implementation for snapshot integration

This commit is contained in:
simon 2022-10-29 15:49:47 +07:00
parent 749f61aba6
commit 1fbd603374
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
5 changed files with 34 additions and 1 deletions

View File

@ -37,7 +37,8 @@
"cache_dir": "/cache",
"videos": "/youtube",
"colors": "dark",
"enable_cast": false
"enable_cast": false,
"enable_snapshot": false
},
"scheduler": {
"update_subscribed": false,

View File

@ -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()

View File

@ -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):

View File

@ -153,6 +153,23 @@
{{ app_form.application_enable_cast }}
</div>
</div>
<div class="settings-group">
<h2 id="snapshots">Snapshots</h2>
<div class="settings-item">
<p>Current system snapshot: <span class="settings-current">{{ config.application.enable_snapshot }}</span></p>
<i>Automatically create daily deduplicated snapshots of the index, stored in Elasticsearch. Read first before activating: Wiki.</i><br>
{{ app_form.application_enable_snapshot }}
</div>
<div>
{% if snapshots %}
<p>Create next snapshot: <span class="settings-current">{{ snapshots.next_exec_str }}</span>, snapshots expire after <span class="settings-current">{{ snapshots.expire_after }}</span></p>
<br>
{% for snapshot in snapshots.snapshots %}
<p><button data-id="{{ snapshot.id }}">Restore</button> Snapshot created on: <span class="settings-current">{{ snapshot.start_date }}</span>, took <span class="settings-current">{{ snapshot.duration_s }}s</span> to create</p>
{% endfor %}
{% endif %}
</div>
</div>
<button type="submit" name="application-settings">Update Application Configurations</button>
</form>
<div class="title-bar">

View File

@ -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"""