From 875d48870b007d2f8f9879755e9d9ab9128020e0 Mon Sep 17 00:00:00 2001 From: arabcoders Date: Fri, 20 Jun 2025 20:35:46 +0300 Subject: [PATCH 1/3] add api/item/{id} endpoint --- API.md | 29 +++++++++++++++++++++++++++++ app/routes/api/history.py | 26 ++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/API.md b/API.md index d9c714d7..45e76ab3 100644 --- a/API.md +++ b/API.md @@ -23,6 +23,7 @@ This document describes the available endpoints and their usage. All endpoints r - [POST /api/history](#post-apihistory) - [DELETE /api/history](#delete-apihistory) - [POST /api/history/{id}](#post-apihistoryid) + - [GET /api/history/{id}](#get-apihistoryid) - [GET /api/history](#get-apihistory) - [GET /api/tasks](#get-apitasks) - [PUT /api/tasks](#put-apitasks) @@ -296,6 +297,34 @@ or an error: --- +### GET /api/history/{id} +**Purpose**: View details of a specific item in the database. + +**Path Parameter**: +- `id` = Unique item ID. + +**Response**: +```json +{ + "_id": "", + "title": "Video Title", + "url": "https://youtube.com/watch?v=...", + .... +} +``` +or an error: +```json +{ + "error": "text" +} +``` + +- `200 OK` If the item exists and is returned. +- `404 Not Found` if the item doesn’t exist. +- `400 Bad Request` if id is missing. + +--- + ### GET /api/history **Purpose**: Returns the download queue and the download history. diff --git a/app/routes/api/history.py b/app/routes/api/history.py index 6765c24b..bc7e2aad 100644 --- a/app/routes/api/history.py +++ b/app/routes/api/history.py @@ -69,6 +69,32 @@ async def item_delete(request: Request, queue: DownloadQueue, encoder: Encoder) ) +@route("GET", "api/history/{id}", "item_view") +async def item_view(request: Request, queue: DownloadQueue, encoder: Encoder) -> Response: + """ + Update an item in the history. + + Args: + request (Request): The request object. + queue (DownloadQueue): The download queue instance. + encoder (Encoder): The encoder instance. + notify (EventBus): The event bus instance. + + Returns: + Response: The response object. + + """ + id: str = request.match_info.get("id") + if not id: + return web.json_response(data={"error": "id is required."}, status=web.HTTPBadRequest.status_code) + + item: Download | None = queue.done.get_by_id(id) or queue.queue.get_by_id(id) + if not item: + return web.json_response(data={"error": "item not found."}, status=web.HTTPNotFound.status_code) + + return web.json_response(data=item.info, status=web.HTTPOk.status_code, dumps=encoder.encode) + + @route("POST", "api/history/{id}", "item_update") async def item_update(request: Request, queue: DownloadQueue, encoder: Encoder, notify: EventBus) -> Response: """ From 7dca15a5aa2024502d6068b9b5b9947d64d5edf6 Mon Sep 17 00:00:00 2001 From: arabcoders Date: Fri, 20 Jun 2025 20:36:10 +0300 Subject: [PATCH 2/3] clean up item object --- app/library/ItemDTO.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/library/ItemDTO.py b/app/library/ItemDTO.py index b66c54fc..d6075072 100644 --- a/app/library/ItemDTO.py +++ b/app/library/ItemDTO.py @@ -6,6 +6,8 @@ from dataclasses import dataclass, field from email.utils import formatdate from typing import Any +from app.library.Utils import clean_item + LOG = logging.getLogger("ItemDTO") @@ -224,7 +226,8 @@ class ItemDTO: eta: str | None = None def serialize(self) -> dict: - return self.__dict__.copy() + item, _ = clean_item(self.__dict__.copy(), ItemDTO.removed_fields()) + return item def json(self) -> str: return json.dumps(self.serialize(), default=lambda o: o.__dict__, sort_keys=True, indent=4) From c8dbd93efb4311b84e027f74ab15cdbdd6a16279 Mon Sep 17 00:00:00 2001 From: arabcoders Date: Fri, 20 Jun 2025 20:36:22 +0300 Subject: [PATCH 3/3] make it possible to view local item info --- ui/components/History.vue | 29 +++++++++++++++++++++++++---- ui/pages/index.vue | 35 ++++++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/ui/components/History.vue b/ui/components/History.vue index 0aecc6ee..9ca1b4cb 100644 --- a/ui/components/History.vue +++ b/ui/components/History.vue @@ -190,7 +190,12 @@ - Information + yt-dlp Information + + + + + Local Information