diff --git a/backend/config/management/commands/ta_config_backup.py b/backend/config/management/commands/ta_config_backup.py new file mode 100644 index 00000000..40802ddd --- /dev/null +++ b/backend/config/management/commands/ta_config_backup.py @@ -0,0 +1,76 @@ +"""backup config for sqlite reset and restore""" + +import json +from pathlib import Path + +from django.contrib.auth import get_user_model +from django.core.management.base import BaseCommand +from home.models import CustomPeriodicTask +from home.src.ta.settings import EnvironmentSettings +from rest_framework.authtoken.models import Token + +User = get_user_model() + + +class Command(BaseCommand): + """export""" + + help = "Exports all users and their auth tokens to a JSON file" + FILE = Path(EnvironmentSettings.CACHE_DIR) / "backup" / "migration.json" + + def handle(self, *args, **kwargs): + """entry point""" + + data = { + "user_data": self.get_users(), + "schedule_data": self.get_schedules(), + } + + with open(self.FILE, "w", encoding="utf-8") as json_file: + json_file.write(json.dumps(data)) + + def get_users(self): + """get users""" + + users = User.objects.all() + + user_data = [] + + for user in users: + user_info = { + "username": user.name, + "is_staff": user.is_staff, + "is_superuser": user.is_superuser, + "password": user.password, + "tokens": [], + } + + try: + token = Token.objects.get(user=user) + user_info["tokens"] = [token.key] + except Token.DoesNotExist: + user_info["tokens"] = [] + + user_data.append(user_info) + + return user_data + + def get_schedules(self): + """get schedules""" + + all_schedules = CustomPeriodicTask.objects.all() + schedule_data = [] + + for schedule in all_schedules: + schedule_info = { + "name": schedule.name, + "crontab": { + "minute": schedule.crontab.minute, + "hour": schedule.crontab.hour, + "day_of_week": schedule.crontab.day_of_week, + }, + } + + schedule_data.append(schedule_info) + + return schedule_data diff --git a/backend/config/settings.py b/backend/config/settings.py index ab57efb7..4313b68d 100644 --- a/backend/config/settings.py +++ b/backend/config/settings.py @@ -296,4 +296,4 @@ CORS_ALLOW_HEADERS = list(default_headers) + [ # TA application settings TA_UPSTREAM = "https://github.com/tubearchivist/tubearchivist" -TA_VERSION = "v0.4.12" +TA_VERSION = "v0.4.13-unstable" diff --git a/backend/requirements.txt b/backend/requirements.txt index ffe9340e..4dc7fbb8 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,9 +1,9 @@ -apprise==1.9.1 +apprise==1.9.2 celery==5.4.0 django-auth-ldap==5.1.0 django-celery-beat==2.7.0 django-cors-headers==4.6.0 -Django==5.1.4 +Django==5.1.5 djangorestframework==3.15.2 Pillow==11.1.0 redis==5.2.1 @@ -11,4 +11,4 @@ requests==2.32.3 ryd-client==0.0.6 uvicorn==0.34.0 whitenoise==6.8.2 -yt-dlp[default]==2024.12.23 +yt-dlp[default]==2025.1.12