Skip to content

Commit

Permalink
feat: Add endpoint to manually request items (#551)
Browse files Browse the repository at this point in the history
* feat: Add endpoint to manually request items

* fix: made imdb_id required in request endpoint

* fix: let fastapi handle invalid params
  • Loading branch information
davidemarcoli authored Jul 22, 2024
1 parent eeb2d00 commit 652671e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/controllers/actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from typing import Any, Dict, Optional

import pydantic
from fastapi import APIRouter, Request
from program.content.overseerr import Overseerr
from program.indexers.trakt import TraktIndexer, get_imdbid_from_tmdb
from program.media.item import MediaItem, Show
from requests import RequestException
from utils.logger import logger

from .models.overseerr import OverseerrWebhook

router = APIRouter(
prefix="/actions",
responses={404: {"description": "Not found"}},
)


@router.post("/request/{imdb_id}")
async def request(request: Request, imdb_id: str) -> Dict[str, Any]:
try:
new_item = MediaItem({"imdb_id": imdb_id, "requested_by": "manually"})
request.app.program.add_to_queue(new_item)
except Exception as e:
logger.error(f"Failed to create item from imdb_id: {imdb_id}")
return {"success": False, "message": "Failed to create item from imdb_id"}

return {"success": True, "message": f"Added {imdb_id} to queue"}
2 changes: 2 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from controllers.settings import router as settings_router
from controllers.tmdb import router as tmdb_router
from controllers.webhooks import router as webhooks_router
from controllers.actions import router as actions_router
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from program import Program
Expand Down Expand Up @@ -74,6 +75,7 @@ async def dispatch(self, request: Request, call_next):
app.include_router(items_router)
app.include_router(webhooks_router)
app.include_router(tmdb_router)
app.include_router(actions_router)
# app.include_router(metrics_router)


Expand Down

0 comments on commit 652671e

Please sign in to comment.