wip episode actions

This commit is contained in:
Jef Roosens 2025-02-28 13:48:44 +01:00
parent 7ce41cd034
commit 3e79bec974
No known key found for this signature in database
GPG key ID: 21FD3D77D56BAF49
16 changed files with 319 additions and 13 deletions

View file

@ -0,0 +1,44 @@
use axum::{
extract::{Path, State},
middleware,
routing::post,
Extension, Json, Router,
};
use crate::{
db,
server::{
error::{AppError, AppResult},
gpodder::{
auth_middleware,
format::{Format, StringWithFormat},
models::{EpisodeAction, UpdatedUrlsResponse},
},
Context,
},
};
pub fn router(ctx: Context) -> Router<Context> {
Router::new()
.route("/{username}", post(post_episode_actions))
.layer(middleware::from_fn_with_state(ctx.clone(), auth_middleware))
}
async fn post_episode_actions(
State(ctx): State<Context>,
Path(username): Path<StringWithFormat>,
Extension(user): Extension<db::User>,
Json(actions): Json<Vec<EpisodeAction>>,
) -> AppResult<Json<UpdatedUrlsResponse>> {
if username.format != Format::Json {
return Err(AppError::NotFound);
}
if *username != user.username {
return Err(AppError::BadRequest);
}
tracing::debug!("{:?}", actions);
todo!()
}

View file

@ -1,5 +1,6 @@
mod auth;
mod devices;
mod episodes;
mod subscriptions;
use axum::Router;
@ -11,4 +12,5 @@ pub fn router(ctx: Context) -> Router<Context> {
.nest("/auth", auth::router())
.nest("/devices", devices::router(ctx.clone()))
.nest("/subscriptions", subscriptions::router(ctx.clone()))
.nest("/episodes", episodes::router(ctx.clone()))
}

View file

@ -13,7 +13,9 @@ use crate::{
gpodder::{
auth_middleware,
format::{Format, StringWithFormat},
models::{SubscriptionChangeResponse, SubscriptionDelta, SubscriptionDeltaResponse},
models::{
DeviceType, SubscriptionDelta, SubscriptionDeltaResponse, UpdatedUrlsResponse,
},
},
Context,
},
@ -33,7 +35,7 @@ pub async fn post_subscription_changes(
Path((username, id)): Path<(String, StringWithFormat)>,
Extension(user): Extension<gpodder::User>,
Json(delta): Json<SubscriptionDelta>,
) -> AppResult<Json<SubscriptionChangeResponse>> {
) -> AppResult<Json<UpdatedUrlsResponse>> {
if id.format != Format::Json {
return Err(AppError::NotFound);
}
@ -49,7 +51,7 @@ pub async fn post_subscription_changes(
.await
.unwrap()
.map(|timestamp| {
Json(SubscriptionChangeResponse {
Json(UpdatedUrlsResponse {
timestamp,
update_urls: Vec::new(),
})

View file

@ -1,3 +1,4 @@
use chrono::{NaiveDateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::db;
@ -64,7 +65,34 @@ pub struct SubscriptionDeltaResponse {
}
#[derive(Serialize)]
pub struct SubscriptionChangeResponse {
pub struct UpdatedUrlsResponse {
pub timestamp: i64,
pub update_urls: Vec<(String, String)>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "lowercase")]
#[serde(tag = "action")]
pub enum EpisodeActionType {
Download,
Play {
#[serde(default)]
started: Option<i32>,
position: i32,
#[serde(default)]
total: Option<i32>,
},
Delete,
New,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct EpisodeAction {
podcast: String,
episode: String,
timestamp: Option<NaiveDateTime>,
#[serde(default)]
device: Option<String>,
#[serde(flatten)]
action: EpisodeActionType,
}