Weekly horoscope landing page, link previews for the forum, and fixes from the review
- /heti-horoszkop for visitors: what it is, a real example written for the example chart, login and sign-up buttons; its own link preview image. - Forum: link previews (image, title; a public thread's opening words) for every forum page; none of a members-only thread's content. - Review fixes: a removed thread's photos are no longer served; public photos are cached for an hour, not a year (removals take effect); photos of threads removed a year ago are cleaned up; deleting one forum question no longer revokes the chart link another question still shows; the daily digest leaves out closed topics the member is no longer in; typing notices at most one a second per connection; the weekly page asks for the text once and then only reads it (no repeated paid runs after a failure); turning the Monday e-mail back on from the e-mail page waits for next Monday, like the site's switch; the week's last day is right in the week the clocks go back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -302,6 +302,10 @@ pub async fn serve(
|
||||
let thread = super::threads::readable_thread(&state.db, &viewer, thread)
|
||||
.await
|
||||
.map_err(|_| ApiError::NotFound("photo"))?;
|
||||
// A removed thread takes its photos down too (moderators still see them).
|
||||
if thread.deleted_at.is_some() && !viewer.is_moderator() {
|
||||
return Err(ApiError::NotFound("photo"));
|
||||
}
|
||||
thread.deleted_at.is_none() && thread.visibility == "public" && !deleted
|
||||
}
|
||||
};
|
||||
@@ -312,18 +316,22 @@ pub async fn serve(
|
||||
.map_err(|e| ApiError::Internal(format!("reading a photo: {e}")))?
|
||||
.ok_or(ApiError::NotFound("photo"))?;
|
||||
let content_type = if file.ends_with(".webp") { "image/webp" } else { "image/jpeg" };
|
||||
let cache = if public { "public, max-age=31536000, immutable" } else { "private, max-age=3600" };
|
||||
// Not for long even when public: a moderator may remove the post, and the
|
||||
// CDN and the browsers must let go of the photo within the hour.
|
||||
let cache = if public { "public, max-age=3600" } else { "private, max-age=3600" };
|
||||
Ok(([(header::CONTENT_TYPE, content_type), (header::CACHE_CONTROL, cache)], object.bytes).into_response())
|
||||
}
|
||||
|
||||
/// Every hour: unattached photos older than a day, and the photos of posts
|
||||
/// removed more than a year ago, leave the storage and the table.
|
||||
/// (or whole threads) removed more than a year ago, leave the storage and the table.
|
||||
pub async fn cleanup(state: &AppState) -> anyhow::Result<u64> {
|
||||
let Some(storage) = &state.storage else { return Ok(0) };
|
||||
let gone: Vec<(Uuid, String, String)> = sqlx::query_as(
|
||||
"SELECT ph.id, ph.file, ph.thumb FROM forum.photos ph LEFT JOIN forum.posts p ON p.id = ph.post_id \
|
||||
LEFT JOIN forum.threads t ON t.id = p.thread_id \
|
||||
WHERE (ph.post_id IS NULL AND ph.created_at < now() - interval '1 day') \
|
||||
OR (p.deleted_at IS NOT NULL AND p.deleted_at < now() - interval '1 year') \
|
||||
OR (t.deleted_at IS NOT NULL AND t.deleted_at < now() - interval '1 year') \
|
||||
LIMIT 500",
|
||||
)
|
||||
.fetch_all(&state.db)
|
||||
|
||||
@@ -316,13 +316,19 @@ async fn set_helped(
|
||||
Ok(Json(posts_json(&state.db, &viewer, std::slice::from_ref(&post)).await?.remove(0)))
|
||||
}
|
||||
|
||||
/// The sharer's link goes (as when revoked on the main site).
|
||||
/// The sharer's link goes (as when revoked on the main site), unless another
|
||||
/// live question of theirs still shows it: asking twice about the same chart
|
||||
/// reuses one link (call it after this post let go of it).
|
||||
async fn revoke_share(db: impl sqlx::PgExecutor<'_>, share: uuid::Uuid, owner: uuid::Uuid) -> Result<(), sqlx::Error> {
|
||||
sqlx::query("UPDATE shares SET revoked_at = now() WHERE id = $1 AND owner_id = $2 AND revoked_at IS NULL")
|
||||
.bind(share)
|
||||
.bind(owner)
|
||||
.execute(db)
|
||||
.await?;
|
||||
sqlx::query(
|
||||
"UPDATE shares SET revoked_at = now() WHERE id = $1 AND owner_id = $2 AND revoked_at IS NULL \
|
||||
AND NOT EXISTS (SELECT 1 FROM forum.posts p JOIN forum.threads t ON t.id = p.thread_id \
|
||||
WHERE p.share_id = $1 AND p.deleted_at IS NULL AND t.deleted_at IS NULL)",
|
||||
)
|
||||
.bind(share)
|
||||
.bind(owner)
|
||||
.execute(db)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user