wip episode actions
This commit is contained in:
parent
7ce41cd034
commit
3e79bec974
16 changed files with 319 additions and 13 deletions
44
src/server/gpodder/advanced/episodes.rs
Normal file
44
src/server/gpodder/advanced/episodes.rs
Normal 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!()
|
||||
}
|
||||
|
|
@ -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()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue