diff --git a/media_manager/torrent/router.py b/media_manager/torrent/router.py index 2df2edd..eeb1936 100644 --- a/media_manager/torrent/router.py +++ b/media_manager/torrent/router.py @@ -1,10 +1,16 @@ +from fastapi.exceptions import HTTPException + from fastapi import APIRouter from fastapi import status from fastapi.params import Depends from media_manager.auth.users import current_active_user, current_superuser -from media_manager.torrent.dependencies import torrent_service_dep, torrent_dep -from media_manager.torrent.schemas import Torrent +from media_manager.torrent.dependencies import ( + torrent_service_dep, + torrent_dep, + torrent_repository_dep, +) +from media_manager.torrent.schemas import Torrent, TorrentStatus router = APIRouter() @@ -53,3 +59,29 @@ def retry_torrent_download( ): service.pause_download(torrent=torrent) service.resume_download(torrent=torrent) + + +@router.patch( + "/{torrent_id}/status", + status_code=status.HTTP_200_OK, + dependencies=[Depends(current_superuser)], + response_model=Torrent, +) +def update_torrent_status( + rep: torrent_repository_dep, + torrent: torrent_dep, + state: TorrentStatus | None = None, + imported: bool | None = None, +): + if imported is not None: + torrent.imported = imported + if state is not None: + torrent.status = state + if status is None and imported is None: + return HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail="No status or imported value provided", + ) + + rep.save_torrent(torrent=torrent) + return torrent diff --git a/web/src/lib/api/api.d.ts b/web/src/lib/api/api.d.ts index 9e32386..f517fc0 100644 --- a/web/src/lib/api/api.d.ts +++ b/web/src/lib/api/api.d.ts @@ -633,6 +633,23 @@ export interface paths { patch?: never; trace?: never; }; + '/api/v1/torrent/{torrent_id}/status': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + get?: never; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + /** Update Torrent Status */ + patch: operations['update_torrent_status_api_v1_torrent__torrent_id__status_patch']; + trace?: never; + }; '/api/v1/movies': { parameters: { query?: never; @@ -3150,6 +3167,40 @@ export interface operations { }; }; }; + update_torrent_status_api_v1_torrent__torrent_id__status_patch: { + parameters: { + query?: { + state?: components['schemas']['TorrentStatus'] | null; + imported?: boolean | null; + }; + header?: never; + path: { + torrent_id: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description Successful Response */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': components['schemas']['Torrent']; + }; + }; + /** @description Validation Error */ + 422: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': components['schemas']['HTTPValidationError']; + }; + }; + }; + }; get_all_movies_api_v1_movies_get: { parameters: { query?: never; diff --git a/web/src/lib/components/edit-torrent-dialog.svelte b/web/src/lib/components/edit-torrent-dialog.svelte new file mode 100644 index 0000000..27cd318 --- /dev/null +++ b/web/src/lib/components/edit-torrent-dialog.svelte @@ -0,0 +1,66 @@ + + + + + + + + + Edit Torrent + + Edit torrent "{torrent.torrent_title}". + + +
+ + +
+ + + + +
+
diff --git a/web/src/lib/components/torrent-table.svelte b/web/src/lib/components/torrent-table.svelte index 9219121..b45f10a 100644 --- a/web/src/lib/components/torrent-table.svelte +++ b/web/src/lib/components/torrent-table.svelte @@ -12,7 +12,7 @@ import client from '$lib/api'; import { toast } from 'svelte-sonner'; import DeleteTorrentDialog from '$lib/components/delete-torrent-dialog.svelte'; - + import EditTorrentDialog from '$lib/components/edit-torrent-dialog.svelte'; let { torrents, isShow = true @@ -96,6 +96,7 @@ {/if} + {/if}