add api/item/{id} endpoint

This commit is contained in:
arabcoders 2025-06-20 20:35:46 +03:00
parent e77ed11a09
commit 875d48870b
2 changed files with 55 additions and 0 deletions

29
API.md
View file

@ -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": "<uuid>",
"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 doesnt exist.
- `400 Bad Request` if id is missing.
---
### GET /api/history
**Purpose**: Returns the download queue and the download history.

View file

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