forked from Furumi/furumi-web
Fix podcast page
This commit is contained in:
1 parent
319f0bcba7
commit
eefe8a9777
16 files changed
+692
-222
No files matched your search
@@ -722,7 +722,7 @@ impl Federation {
|
||||
.map(|r| Arc::clone(&r.podcast_dht))
|
||||
.context("federation is not running")?;
|
||||
let hits = overlay.search(query, 100).await?;
|
||||
Ok(Value::Array(hits.into_iter().map(|hit| json!({"id":hit.podcast_id,"url":hit.feed_url,"metadata":{"title":hit.card.title,"author":hit.card.author,"description":hit.card.description}})).collect()))
|
||||
Ok(Value::Array(hits.into_iter().map(|hit| json!({"id":hit.podcast_id,"url":hit.feed_url,"metadata":{"title":hit.card.title,"author":hit.card.author,"description":hit.card.description,"image_url":hit.card.image_url}})).collect()))
|
||||
}
|
||||
|
||||
async fn similarity_services(&self) -> Result<(Arc<MusicDhtService>, Arc<SimilarityDht>)> {
|
||||
|
||||
@@ -33,6 +33,11 @@ fn renders_podcast_navigation_and_views() {
|
||||
2
|
||||
);
|
||||
assert!(html.contains("/api/podcasts/action"));
|
||||
assert!(
|
||||
html.find("Alpine.store('podcasts',").unwrap()
|
||||
< html.find("Alpine.store('library',").unwrap(),
|
||||
"podcast navigation must be registered before library.init restores the hash"
|
||||
);
|
||||
if std::env::var_os("FURU_PODCAST_RENDER_FIXTURE").is_some() {
|
||||
std::fs::write("target/podcast-player-fixture.html", html).unwrap();
|
||||
}
|
||||
@@ -187,6 +192,22 @@ async fn postgres_multiuser_progress_retention_and_admin() {
|
||||
1
|
||||
);
|
||||
let request = |value| serde_json::from_value::<Action>(value).unwrap();
|
||||
let preview = action(
|
||||
pool.clone(),
|
||||
config.clone(),
|
||||
99,
|
||||
false,
|
||||
request(json!({"action":"detail","id":podcast})),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(preview["subscribed"], false);
|
||||
let count: i64 =
|
||||
sqlx::query_scalar("SELECT count(*) FROM furumusic__podcast_subscription WHERE user_id=99")
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(count, 0);
|
||||
action(
|
||||
pool.clone(),
|
||||
config.clone(),
|
||||
@@ -196,6 +217,18 @@ async fn postgres_multiuser_progress_retention_and_admin() {
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(
|
||||
action(
|
||||
pool.clone(),
|
||||
config.clone(),
|
||||
99,
|
||||
false,
|
||||
request(json!({"action":"detail","id":podcast}))
|
||||
)
|
||||
.await
|
||||
.is_err(),
|
||||
"private podcasts must not be exposed by the detail route"
|
||||
);
|
||||
assert_eq!(
|
||||
list(&pool, 2, false).await.unwrap()["mine"]
|
||||
.as_array()
|
||||
|
||||
+7
-2
@@ -104,17 +104,22 @@ async fn action(
|
||||
}
|
||||
match body.action.as_str() {
|
||||
"list" => return list(&pool, user, false).await,
|
||||
"detail" => {
|
||||
let detail:Option<Value>=sqlx::query_scalar("SELECT jsonb_build_object('id',p.id,'url',p.origin_url,'metadata',p.metadata,'subscribed',EXISTS(SELECT 1 FROM furumusic__podcast_subscription s WHERE s.user_id=$1 AND s.podcast_id=p.id),'episodes',(SELECT count(*) FROM furumusic__podcast_episode e WHERE e.podcast_id=p.id)) FROM furumusic__podcast p WHERE p.id=$2 AND EXISTS(SELECT 1 FROM furumusic__podcast_subscription s WHERE s.podcast_id=p.id AND (s.user_id=$1 OR s.shared))").bind(user).bind(&body.id).fetch_optional(&pool).await?;
|
||||
return detail.context("podcast not found");
|
||||
}
|
||||
"admin_list" => return list(&pool, user, true).await,
|
||||
"add" => {
|
||||
let id = subscribe(&pool, user, &body.url).await?;
|
||||
sync::ensure_subscribed(&pool, user, &id).await?;
|
||||
sync::seed_user(&pool, user).await?;
|
||||
let checked = refresh(&pool, &id).await;
|
||||
let download_id = id.clone();
|
||||
tokio::spawn(async move {
|
||||
let _ = download_pending(&pool, &config, Some(&id)).await;
|
||||
let _ = download_pending(&pool, &config, Some(&download_id)).await;
|
||||
});
|
||||
return Ok(
|
||||
json!({"ok":true,"warning":checked.err().map(|_| "Feed check failed; the subscription was saved") }),
|
||||
json!({"ok":true,"id":id,"warning":checked.err().map(|_| "Feed check failed; the subscription was saved") }),
|
||||
);
|
||||
}
|
||||
"remove" => {
|
||||
|
||||
Reference in new issue
Block a user