refactor(gpodder): add authenticated view of repository

This commit is contained in:
Jef Roosens 2025-06-20 10:43:46 +02:00
parent 0e91eef0e8
commit 346c27fc3f
Signed by: Jef Roosens
GPG key ID: 21FD3D77D56BAF49
10 changed files with 133 additions and 80 deletions

View file

@ -23,15 +23,14 @@ impl Command {
match self {
Self::Sync { username, devices } => {
let user = store.get_user(username)?;
store.update_device_sync_status(
&user,
store.user(&user).update_device_sync_status(
vec![devices.iter().map(|s| s.as_ref()).collect()],
Vec::new(),
)?;
}
Self::Devices { username } => {
let user = store.get_user(username)?;
let devices = store.devices_for_user(&user)?;
let devices = store.user(&user).devices()?;
for device in devices {
println!("{} ({} subscriptions)", device.id, device.subscriptions);

View file

@ -66,7 +66,7 @@ async fn post_login(
.validate_credentials(auth.username(), auth.password())?;
let user_agent = user_agent.map(|header| header.to_string());
let session = ctx.store.create_session(&user, user_agent)?;
let session = ctx.store.user(&user).create_session(user_agent)?;
Ok::<_, AuthErr>(session)
})

View file

@ -39,7 +39,7 @@ async fn get_devices(
}
Ok(
tokio::task::spawn_blocking(move || ctx.store.devices_for_user(&user))
tokio::task::spawn_blocking(move || ctx.store.user(&user).devices())
.await
.unwrap()
.map(|devices| Json(devices.into_iter().map(models::Device::from).collect()))?,
@ -56,9 +56,11 @@ async fn post_device(
return Err(AppError::NotFound);
}
tokio::task::spawn_blocking(move || ctx.store.update_device_info(&user, &id, patch.into()))
.await
.unwrap()?;
tokio::task::spawn_blocking(move || {
ctx.store.user(&user).update_device_info(&id, patch.into())
})
.await
.unwrap()?;
Ok(())
}

View file

@ -46,7 +46,8 @@ async fn post_episode_actions(
Ok(tokio::task::spawn_blocking(move || {
ctx.store
.add_episode_actions(&user, actions.into_iter().map(Into::into).collect())
.user(&user)
.add_episode_actions(actions.into_iter().map(Into::into).collect())
})
.await
.unwrap()
@ -90,8 +91,7 @@ async fn get_episode_actions(
let since = filter.since.and_then(|ts| DateTime::from_timestamp(ts, 0));
Ok(tokio::task::spawn_blocking(move || {
ctx.store.episode_actions_for_user(
&user,
ctx.store.user(&user).episode_actions_for_user(
since,
filter.podcast,
filter.device,

View file

@ -44,7 +44,8 @@ pub async fn post_subscription_changes(
Ok(tokio::task::spawn_blocking(move || {
ctx.store
.update_subscriptions_for_device(&user, &id, delta.add, delta.remove)
.user(&user)
.update_subscriptions_for_device(&id, delta.add, delta.remove)
})
.await
.unwrap()
@ -79,7 +80,9 @@ pub async fn get_subscription_changes(
let since = chrono::DateTime::from_timestamp(query.since, 0).ok_or(AppError::BadRequest)?;
Ok(tokio::task::spawn_blocking(move || {
ctx.store.subscription_updates_for_device(&user, &id, since)
ctx.store
.user(&user)
.subscription_updates_for_device(&id, since)
})
.await
.unwrap()

View file

@ -41,7 +41,7 @@ pub async fn get_sync_status(
}
Ok(
tokio::task::spawn_blocking(move || ctx.store.devices_by_sync_group(&user))
tokio::task::spawn_blocking(move || ctx.store.user(&user).devices_by_sync_group())
.await
.unwrap()
.map(|(not_synchronized, synchronized)| {
@ -68,8 +68,7 @@ pub async fn post_sync_status_changes(
}
Ok(tokio::task::spawn_blocking(move || {
ctx.store.update_device_sync_status(
&user,
ctx.store.user(&user).update_device_sync_status(
delta
.synchronize
.iter()
@ -78,7 +77,7 @@ pub async fn post_sync_status_changes(
delta.stop_synchronize.iter().map(|s| s.as_ref()).collect(),
)?;
ctx.store.devices_by_sync_group(&user)
ctx.store.user(&user).devices_by_sync_group()
})
.await
.unwrap()

View file

@ -34,7 +34,7 @@ pub async fn get_device_subscriptions(
}
Ok(
tokio::task::spawn_blocking(move || ctx.store.subscriptions_for_device(&user, &id))
tokio::task::spawn_blocking(move || ctx.store.user(&user).subscriptions_for_device(&id))
.await
.unwrap()
.map(|subs| Json(subs.into_iter().map(|s| s.url).collect()))?,
@ -51,7 +51,7 @@ pub async fn get_user_subscriptions(
}
Ok(
tokio::task::spawn_blocking(move || ctx.store.subscriptions_for_user(&user))
tokio::task::spawn_blocking(move || ctx.store.user(&user).subscriptions())
.await
.unwrap()
.map(|subs| Json(subs.into_iter().map(|s| s.url).collect()))?,
@ -69,7 +69,9 @@ pub async fn put_device_subscriptions(
}
Ok(tokio::task::spawn_blocking(move || {
ctx.store.set_subscriptions_for_device(&user, &id, urls)
ctx.store
.user(&user)
.set_subscriptions_for_device(&id, urls)
})
.await
.unwrap()

View file

@ -125,7 +125,7 @@ async fn post_login(
.validate_credentials(&login.username, &login.password)?;
let user_agent = user_agent.map(|header| header.to_string());
let session = ctx.store.create_session(&user, user_agent)?;
let session = ctx.store.user(&user).create_session(user_agent)?;
Ok::<_, AuthErr>(session)
})

View file

@ -31,7 +31,9 @@ pub async fn get_sessions(
) -> AppResult<TemplateResponse<Page<View>>> {
let next_page = page.next_page();
let sessions = tokio::task::spawn_blocking(move || {
ctx.store.paginated_sessions(&session.user, page.into())
ctx.store
.user(&session.user)
.paginated_sessions(page.into())
})
.await
.unwrap()?;