Forum: the link module, with YouTube previews

- services/forum/src/links: recognises the links in a post and shows a
  preview for the ones a provider knows; for now YouTube (watch, shorts,
  live, embed and youtu.be links, with the start time). Title and channel
  come from YouTube's oEmbed answer, the thumbnail is cut to 16:9 and kept
  in our own storage, so reading a thread loads nothing from YouTube. Made
  when a post is written or edited; without it the link stays text.
- The card: on a computer a click plays the video in place
  (youtube-nocookie.com); on a phone it opens the YouTube app (Android:
  an intent with the web page as fallback; iOS: the link the app takes
  over), and "Lejátszás itt" plays it in place.
- The privacy notice (HU, EN) says what YouTube sees when one plays it.
- "Pörgős most" is now "Élénk beszélgetések"; the new thread form lost its
  note about text and emoji.
- docs: the Turnstile captcha is on the list before going live.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-26 16:26:37 +00:00
co-authored by Claude Opus 5.5
parent 493539bf56
commit 1d4f18b5d6
21 changed files with 653 additions and 26 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ use crate::error::{ApiError, ApiResult};
/// Threads on one page of a topic.
const PAGE_SIZE: i64 = 30;
/// "Pörgős most": at least this many replies in the last 24 hours.
/// "Élénk beszélgetések": at least this many replies in the last 24 hours.
const HOT_MIN_REPLIES: i64 = 3;
/// "Várják a válaszod": threads without a reply from the last two weeks.
const UNANSWERED_DAYS: i32 = 14;
+1
View File
@@ -55,6 +55,7 @@ pub fn router(state: Arc<AppState>) -> Router {
.route("/v1/forum/replies", get(replies::list))
.route("/v1/forum/search", get(search::search))
.route("/v1/forum/share-card/{slug}", get(attachments::preview))
.route("/v1/forum/link-thumbs/{file}", get(crate::links::thumbnail))
.route("/v1/forum/posts/{id}/share", axum::routing::delete(posts::detach_share))
.route("/v1/forum/sitemap", get(search::sitemap))
.route("/v1/forum/replies/read", post(replies::read_all))
+1
View File
@@ -60,6 +60,7 @@ pub async fn edit(
.bind(&body)
.fetch_one(&state.db)
.await?;
crate::links::process(&state, &body).await;
announce(&state, post.thread_id).await;
super::mentions::after_post(&state, post.thread_id, post.id, member.user_id, &body).await;
Ok(Json(posts_json(&state.db, &viewer, std::slice::from_ref(&post)).await?.remove(0)))
+7
View File
@@ -114,6 +114,9 @@ pub async fn posts_json(db: &PgPool, viewer: &Viewer, posts: &[PostRow]) -> ApiR
let people = authors(db, posts.iter().filter_map(|p| p.author_id)).await?;
let shares: Vec<Uuid> = posts.iter().filter(|p| p.deleted_at.is_none()).filter_map(|p| p.share_id).collect();
let cards = super::attachments::cards(db, viewer, &shares).await?;
let texts: Vec<(i64, &str)> =
posts.iter().filter(|p| p.deleted_at.is_none()).map(|p| (p.id, p.body.as_str())).collect();
let previews = crate::links::previews(db, &texts).await?;
let counts: Vec<(i64, String, i64)> =
sqlx::query_as("SELECT post_id, kind, count(*) FROM forum.reactions WHERE post_id = ANY($1) GROUP BY 1, 2")
.bind(&ids)
@@ -192,6 +195,8 @@ pub async fn posts_json(db: &PgPool, viewer: &Viewer, posts: &[PostRow]) -> ApiR
// The viewer muted the author: the page folds it up.
"muted": p.author_id.is_some_and(|a| viewer.mutes.contains(&a)),
"share": p.share_id.and_then(|id| cards.get(&id).cloned()),
// Previews of the links a provider knows (YouTube).
"links": previews.get(&p.id),
});
if moderator {
post["down"] = json!(down);
@@ -381,6 +386,7 @@ pub async fn create(
tx.commit().await?;
tracing::info!(thread = thread_id, topic = %req.topic, "thread started");
super::mentions::after_post(&state, thread_id, post_id, member.user_id, &body).await;
crate::links::process(&state, &body).await;
Ok((StatusCode::CREATED, Json(json!({ "id": thread_id, "slug": text::slug(&title) }))))
}
@@ -485,6 +491,7 @@ pub async fn reply(
// The one answered hears of it (on the second level, not the branch's first post).
crate::mail::after_reply(&state, id, post.id, member.user_id, post.reply_to_id.or(post.parent_id), &body).await;
super::mentions::after_post(&state, id, post.id, member.user_id, &body).await;
crate::links::process(&state, &body).await;
let followers = crate::live::followers(&state.db, id, member.user_id).await;
crate::live::emit(&state.db, crate::live::Event { thread: Some(id), ..Default::default() }.for_users(followers))
.await;