import { error } from "@sveltejs/kit"; import { getCommentsForVideo, getVideoBySlug, getVideoLikeStatus, getVideos, getArticles, } from "$lib/services.js"; 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"); } }