feat(api): series, season and episode endpoints (#81)
ci / web (push) Successful in 26s
e2e / e2e (push) Successful in 47s
ci / rust (push) Successful in 2m39s

This commit was merged in pull request #81.
This commit is contained in:
2026-08-22 23:02:34 +01:00
parent e650a762f9
commit d3cea8693b
34 changed files with 2762 additions and 21 deletions
+31
View File
@@ -70,6 +70,8 @@ pub struct AppState {
database: Option<Db>,
movie_commands: mpsc::Sender<MovieCommand>,
pending_movie_commands: Arc<tokio::sync::Mutex<mpsc::Receiver<MovieCommand>>>,
episode_commands: mpsc::Sender<EpisodeCommand>,
pending_episode_commands: Arc<tokio::sync::Mutex<mpsc::Receiver<EpisodeCommand>>>,
}
/// Work explicitly requested through the movie API.
@@ -79,6 +81,16 @@ pub enum MovieCommand {
Grab { movie_id: i64, release_id: i64 },
}
/// Work explicitly requested through the series API.
///
/// Intent lives at the leaf (`DESIGN.md` §4.1), so a manual action names an
/// episode even when the release that satisfies it is a season pack.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EpisodeCommand {
Search { episode_id: i64 },
Grab { episode_id: i64, release_id: i64 },
}
impl AppState {
/// Build the state, including the shared HTTP client.
///
@@ -88,12 +100,15 @@ impl AppState {
pub fn new(upstreams: Upstreams) -> Result<Self, reqwest::Error> {
let http = reqwest::Client::builder().timeout(PROBE_TIMEOUT).build()?;
let (movie_commands, pending_movie_commands) = mpsc::channel(64);
let (episode_commands, pending_episode_commands) = mpsc::channel(64);
Ok(Self {
http,
upstreams: Arc::new(upstreams),
database: None,
movie_commands,
pending_movie_commands: Arc::new(tokio::sync::Mutex::new(pending_movie_commands)),
episode_commands,
pending_episode_commands: Arc::new(tokio::sync::Mutex::new(pending_episode_commands)),
})
}
@@ -113,6 +128,15 @@ impl AppState {
self.pending_movie_commands.lock().await.recv().await
}
/// Wait for the next manual episode action in the daemon's reconcile loop.
///
/// # Errors
///
/// If every sender has been dropped.
pub async fn next_episode_command(&self) -> Option<EpisodeCommand> {
self.pending_episode_commands.lock().await.recv().await
}
pub(crate) fn http(&self) -> &reqwest::Client {
&self.http
}
@@ -131,4 +155,11 @@ impl AppState {
) -> Result<(), mpsc::error::TrySendError<MovieCommand>> {
self.movie_commands.try_send(command)
}
pub(crate) fn send_episode_command(
&self,
command: EpisodeCommand,
) -> Result<(), mpsc::error::TrySendError<EpisodeCommand>> {
self.episode_commands.try_send(command)
}
}