Files
sexy/packages/frontend/src/routes/videos/[slug]/+page.server.ts

37 lines
1.0 KiB
TypeScript
Raw Normal View History

2025-10-25 22:04:41 +02:00
import { error } from "@sveltejs/kit";
import {
getCommentsForVideo,
getVideoBySlug,
getVideoLikeStatus,
getVideos,
getArticles,
} from "$lib/services.js";
2025-10-25 22:04:41 +02:00
export async function load({ fetch, params, locals }) {
const video = await getVideoBySlug(params.slug, fetch);
const [comments, likeStatus, relatedVideos, featuredArticle] = await Promise.all([
getCommentsForVideo(video.id, fetch),
locals.authStatus.authenticated
? getVideoLikeStatus(video.id, fetch).catch(() => ({ liked: false }))
: Promise.resolve({ liked: false }),
video.tags?.length
? getVideos({ tag: video.tags[0], excludeId: video.id, limit: 5 }, fetch)
: Promise.resolve({ items: [], total: 0 }),
getArticles({ featured: true, limit: 1 }, fetch),
]);
try {
return {
video,
comments,
authStatus: locals.authStatus,
likeStatus,
relatedVideos: relatedVideos.items,
featuredArticle: featuredArticle.items[0] ?? null,
};
} catch {
error(404, "Video not found");
}
2025-10-25 22:04:41 +02:00
}