fix(news): restore publication flow and deduplicate dashboard friends
CI / check (push) Successful in 1m6s
CI / deploy (push) Successful in 59s

This commit is contained in:
Simo committed 2026-09-06 18:32:43 +02:00
1 parent ef94646d60
commit 9b0ea2fb16
22 files changed
+638 -195

No files matched your search

+1 -7
View File
@@ -99,13 +99,7 @@ export default async function MePage({
);
const canClaim = referralTotal >= needed;
const remaining = Math.max(0, needed - referralTotal);
const onlineFriends = [
...new Map(
friends
.filter((friend) => friend.online === "1")
.map((friend) => [friend.id, friend]),
).values(),
];
const onlineFriends = friends.filter((friend) => friend.online === "1");
const date = (value: number) =>
value
? format.dateTime(new Date(value * 1000), { dateStyle: "medium" })
+32 -35
View File
@@ -8,8 +8,8 @@ import { toggleReaction } from "@/actions/article-reactions";
import Link from "@/components/link";
import { ContentCard, EmptyState } from "@/components/public/ui";
import { SanitizedHtml } from "@/components/shared/sanitized-html";
import { articleSlug } from "@/lib/article-input";
import { auth } from "@/lib/auth";
import { cachedQuery } from "@/lib/cached-db";
import {
db,
User,
@@ -20,6 +20,7 @@ import {
import { excerpt } from "@/lib/format";
import { formatDate } from "@/lib/format-date";
import { sanitize } from "@/lib/sanitize";
import { cacheNews } from "@/lib/services/news-cache";
type SearchParams = Promise<{
comment?: string;
@@ -46,10 +47,10 @@ function feedbackStyle(tone: "success" | "error"): CSSProperties {
export async function generateMetadata({
params,
}: {
params: Promise<{ slug: string }>;
params: Promise<{ slug: string[] }>;
}): Promise<Metadata> {
const appUrl = process.env.APP_URL ?? "http://localhost:3000";
const { slug } = await params;
const slug = articleSlug((await params).slug);
const [article] = await db
.select({
title: WebsiteArticles.title,
@@ -95,44 +96,40 @@ export default async function ArticlePage({
params,
searchParams,
}: {
params: Promise<{ slug: string }>;
params: Promise<{ slug: string[] }>;
searchParams: SearchParams;
}) {
const { slug } = await params;
const slug = articleSlug((await params).slug);
const { comment, reaction, error } = await searchParams;
const t = await getTranslations("pages.article");
const article = await cachedQuery(
`article:slug:${slug}`,
async () => {
const [row] = await db
.select({
id: WebsiteArticles.id,
slug: WebsiteArticles.slug,
title: WebsiteArticles.title,
shortStory: WebsiteArticles.shortStory,
fullStory: WebsiteArticles.fullStory,
image: WebsiteArticles.image,
createdAt: WebsiteArticles.createdAt,
updatedAt: WebsiteArticles.updatedAt,
})
.from(WebsiteArticles)
.where(
and(
eq(WebsiteArticles.slug, slug),
eq(WebsiteArticles.status, "published"),
or(
sql`${WebsiteArticles.publishAt} IS NULL`,
sql`${WebsiteArticles.publishAt} <= NOW()`,
),
const article = await cacheNews(`article:slug:${slug}`, 60_000, async () => {
const [row] = await db
.select({
id: WebsiteArticles.id,
slug: WebsiteArticles.slug,
title: WebsiteArticles.title,
shortStory: WebsiteArticles.shortStory,
fullStory: WebsiteArticles.fullStory,
image: WebsiteArticles.image,
createdAt: WebsiteArticles.createdAt,
updatedAt: WebsiteArticles.updatedAt,
})
.from(WebsiteArticles)
.where(
and(
eq(WebsiteArticles.slug, slug),
eq(WebsiteArticles.status, "published"),
or(
sql`${WebsiteArticles.publishAt} IS NULL`,
sql`${WebsiteArticles.publishAt} <= NOW()`,
),
)
.limit(1)
.catch(() => []);
return row ?? null;
},
60,
);
),
)
.limit(1)
.catch(() => []);
return row ?? null;
});
if (!article) notFound();
const articleId = article.id;
+5 -1
View File
@@ -31,6 +31,8 @@ export default async function EditArticle({
title: WebsiteArticles.title,
shortStory: WebsiteArticles.shortStory,
fullStory: WebsiteArticles.fullStory,
status: WebsiteArticles.status,
publishAt: WebsiteArticles.publishAt,
image: WebsiteArticles.image,
})
.from(WebsiteArticles)
@@ -63,7 +65,7 @@ export default async function EditArticle({
action={async (fd) => {
"use server";
fd.set("id", String(article.id));
await updateArticle(fd);
return updateArticle(fd);
}}
defaultValues={{
title: article.title,
@@ -71,6 +73,8 @@ export default async function EditArticle({
image: article.image,
shortStory: article.shortStory,
fullStory: article.fullStory,
status: article.status,
publishAt: article.publishAt?.toISOString(),
}}
/>
<form action={deleteArticle} style={{ marginTop: "1rem" }}>
+7 -4
View File
@@ -1,7 +1,9 @@
import { and, eq, or, sql } from "drizzle-orm";
import { apiJson } from "@/lib/api";
import { db, WebsiteArticles } from "@/lib/db";
import { apiCacheKey, cacheSafe, redisCache } from "@/lib/redis-cache";
import { logger } from "@/lib/logger";
import { apiCacheKey, cacheSafe } from "@/lib/redis-cache";
import { cacheNews } from "@/lib/services/news-cache";
/**
* GET /api/articles/:slug — single website_article by slug, including the
@@ -14,9 +16,9 @@ export async function GET(
const { slug } = await params;
try {
const data = await redisCache(
const data = await cacheNews(
apiCacheKey(`articles:${slug}`),
60,
60_000,
async () => {
const [article] = await db
.select({
@@ -55,7 +57,8 @@ export async function GET(
}
return apiJson(data);
} catch {
} catch (error) {
logger.error("Public news query failed", { module: "news", error });
// DB unavailable — treat as not found rather than a 500.
return apiJson({ error: "Article not found" }, { status: 200 });
}
+7 -4
View File
@@ -1,7 +1,9 @@
import { and, count, desc, eq, or, sql } from "drizzle-orm";
import { apiJson, pagination } from "@/lib/api";
import { db, WebsiteArticles } from "@/lib/db";
import { apiCacheKey, cacheSafe, redisCache } from "@/lib/redis-cache";
import { logger } from "@/lib/logger";
import { apiCacheKey, cacheSafe } from "@/lib/redis-cache";
import { cacheNews } from "@/lib/services/news-cache";
/**
* GET /api/articles — paginated list of website_articles, newest first.
@@ -13,9 +15,9 @@ export async function GET(req: Request) {
const { page, perPage, skip, take } = pagination(sp);
try {
const data = await redisCache(
const data = await cacheNews(
apiCacheKey(`articles:${page}:${perPage}`),
60,
60_000,
async () => {
const publishedFilter = and(
eq(WebsiteArticles.status, "published"),
@@ -60,7 +62,8 @@ export async function GET(req: Request) {
);
return apiJson(data);
} catch {
} catch (error) {
logger.error("Public news query failed", { module: "news", error });
// DB unavailable — return an empty payload instead of a 500.
return apiJson(
{ data: [], meta: { page, perPage, total: 0, lastPage: 1 } },
+6 -3
View File
@@ -3,7 +3,9 @@ import { env } from "@/env";
import { apiJson } from "@/lib/api";
import { db, User, WebsiteArticles } from "@/lib/db";
import { resolveHotelName } from "@/lib/hotel-name";
import { apiCacheKey, cacheSafe, redisCache } from "@/lib/redis-cache";
import { logger } from "@/lib/logger";
import { apiCacheKey, cacheSafe } from "@/lib/redis-cache";
import { cacheNews } from "@/lib/services/news-cache";
/**
* GET /api/home — combined landing payload: the latest 4 website_articles and
@@ -12,7 +14,7 @@ import { apiCacheKey, cacheSafe, redisCache } from "@/lib/redis-cache";
*/
export async function GET(_req: Request) {
try {
const data = await redisCache(apiCacheKey("home"), 15, async () => {
const data = await cacheNews(apiCacheKey("home"), 15_000, async () => {
const [articles, onlineRows, hotelName] = await Promise.all([
db
.select({
@@ -45,7 +47,8 @@ export async function GET(_req: Request) {
});
});
return apiJson(data);
} catch {
} catch (error) {
logger.error("Public news query failed", { module: "news", error });
return apiJson(
{ articles: [], online: 0, hotelName: env.HOTEL_NAME },
{ status: 200 },