diff --git a/tubearchivist/home/src/frontend/api_calls.py b/tubearchivist/home/src/frontend/api_calls.py index e3d658a0..f2d6231c 100644 --- a/tubearchivist/home/src/frontend/api_calls.py +++ b/tubearchivist/home/src/frontend/api_calls.py @@ -9,19 +9,9 @@ from home.src.download.subscriptions import ( PlaylistSubscription, ) from home.src.index.playlist import YoutubePlaylist -from home.src.ta.ta_redis import RedisArchivist, RedisQueue +from home.src.ta.ta_redis import RedisArchivist from home.src.ta.urlparser import Parser -from home.tasks import ( - download_pending, - kill_dl, - re_sync_thumbs, - rescan_filesystem, - run_backup, - run_manual_import, - run_restore_backup, - subscribe_to, - update_subscribed, -) +from home.tasks import run_restore_backup, subscribe_to class PostData: @@ -46,20 +36,13 @@ class PostData: exec_map = { "change_view": self._change_view, "change_grid": self._change_grid, - "rescan_pending": self._rescan_pending, - "dl_pending": self._dl_pending, - "queue": self._queue_handler, "unsubscribe": self._unsubscribe, "subscribe": self._subscribe, "sort_order": self._sort_order, "hide_watched": self._hide_watched, "show_subed_only": self._show_subed_only, "show_ignored_only": self._show_ignored_only, - "manual-import": self._manual_import, - "re-embed": self._re_embed, - "db-backup": self._db_backup, "db-restore": self._db_restore, - "fs-rescan": self._fs_rescan, "delete-playlist": self._delete_playlist, } @@ -84,39 +67,6 @@ class PostData: RedisArchivist().set_message(key, {"status": grid_items}) return {"success": True} - @staticmethod - def _rescan_pending(): - """look for new items in subscribed channels""" - print("rescan subscribed channels") - update_subscribed.delay() - return {"success": True} - - @staticmethod - def _dl_pending(): - """start the download queue""" - print("download pending") - running = download_pending.delay() - task_id = running.id - print(f"{task_id}: set task id") - RedisArchivist().set_message("dl_queue_id", task_id) - return {"success": True} - - def _queue_handler(self): - """queue controls from frontend""" - to_execute = self.exec_val - if to_execute == "stop": - print("stopping download queue") - RedisQueue(queue_name="dl_queue").clear() - elif to_execute == "kill": - task_id = RedisArchivist().get_message("dl_queue_id") - if not isinstance(task_id, str): - task_id = False - else: - print("brutally killing " + task_id) - kill_dl(task_id) - - return {"success": True} - def _unsubscribe(self): """unsubscribe from channels or playlists""" id_unsub = self.exec_val @@ -183,27 +133,6 @@ class PostData: RedisArchivist().set_message(key, value) return {"success": True} - @staticmethod - def _manual_import(): - """run manual import from settings page""" - print("starting manual import") - run_manual_import.delay() - return {"success": True} - - @staticmethod - def _re_embed(): - """rewrite thumbnails into media files""" - print("start video thumbnail embed process") - re_sync_thumbs.delay() - return {"success": True} - - @staticmethod - def _db_backup(): - """backup es to zip from settings page""" - print("backing up database") - run_backup.delay("manual") - return {"success": True} - def _db_restore(self): """restore es zip from settings page""" print("restoring index from backup zip") @@ -211,13 +140,6 @@ class PostData: run_restore_backup.delay(filename) return {"success": True} - @staticmethod - def _fs_rescan(): - """start file system rescan task""" - print("start filesystem scan") - rescan_filesystem.delay() - return {"success": True} - def _delete_playlist(self): """delete playlist, only metadata or incl all videos""" playlist_dict = self.exec_val diff --git a/tubearchivist/home/tasks.py b/tubearchivist/home/tasks.py index e6876b01..8a9fed83 100644 --- a/tubearchivist/home/tasks.py +++ b/tubearchivist/home/tasks.py @@ -23,8 +23,7 @@ from home.src.index.filesystem import Filesystem from home.src.index.manual import ImportFolderScanner from home.src.index.reindex import Reindex, ReindexManual, ReindexOutdated from home.src.ta.config import AppConfig, ReleaseVersion, ScheduleBuilder -from home.src.ta.helper import clear_dl_cache -from home.src.ta.ta_redis import RedisArchivist, RedisQueue +from home.src.ta.ta_redis import RedisArchivist from home.src.ta.task_manager import TaskManager CONFIG = AppConfig().config diff --git a/tubearchivist/static/script.js b/tubearchivist/static/script.js index 0f12ff1d..968a6b89 100644 --- a/tubearchivist/static/script.js +++ b/tubearchivist/static/script.js @@ -167,18 +167,18 @@ function reindex(button) { // download page buttons function rescanPending() { - let payload = JSON.stringify({ rescan_pending: true }); + let apiEndpoint = '/api/task-name/update_subscribed/'; + apiRequest(apiEndpoint, 'POST'); animate('rescan-icon', 'rotate-img'); - sendPost(payload); setTimeout(function () { checkMessages(); }, 500); } function dlPending() { - let payload = JSON.stringify({ dl_pending: true }); + let apiEndpoint = '/api/task-name/download_pending/'; + apiRequest(apiEndpoint, 'POST'); animate('download-icon', 'bounce-img'); - sendPost(payload); setTimeout(function () { checkMessages(); }, 500); @@ -244,8 +244,8 @@ function killTask(icon) { // settings page buttons function manualImport() { - let payload = JSON.stringify({ 'manual-import': true }); - sendPost(payload); + let apiEndpoint = '/api/task-name/manual_import/'; + apiRequest(apiEndpoint, 'POST'); // clear button let message = document.createElement('p'); message.innerText = 'processing import'; @@ -259,8 +259,8 @@ function manualImport() { } function reEmbed() { - let payload = JSON.stringify({ 're-embed': true }); - sendPost(payload); + let apiEndpoint = '/api/task-name/resync_thumbs/'; + apiRequest(apiEndpoint, 'POST'); // clear button let message = document.createElement('p'); message.innerText = 'processing thumbnails'; @@ -274,8 +274,8 @@ function reEmbed() { } function dbBackup() { - let payload = JSON.stringify({ 'db-backup': true }); - sendPost(payload); + let apiEndpoint = '/api/task-name/run_backup/'; + apiRequest(apiEndpoint, 'POST'); // clear button let message = document.createElement('p'); message.innerText = 'backing up archive'; @@ -305,8 +305,8 @@ function dbRestore(button) { } function fsRescan() { - let payload = JSON.stringify({ 'fs-rescan': true }); - sendPost(payload); + let apiEndpoint = '/api/task-name/rescan_filesystem/'; + apiRequest(apiEndpoint, 'POST'); // clear button let message = document.createElement('p'); message.innerText = 'File system scan in progress';