2025-10-25 22:04:41 +02:00
|
|
|
import { error } from "@sveltejs/kit";
|
2026-03-12 18:35:04 +01:00
|
|
|
import {
|
|
|
|
|
getCommentsForVideo,
|
|
|
|
|
getVideoBySlug,
|
|
|
|
|
getVideoLikeStatus,
|
|
|
|
|
getVideos,
|
|
|
|
|
getArticles,
|
|
|
|
|
} from "$lib/services.js";
|
2025-10-28 10:31:06 +01:00
|
|
|
|
2025-10-25 22:04:41 +02:00
|
|
|
export async function load({ fetch, params, locals }) {
|
2026-03-04 22:27:54 +01:00
|
|
|
const video = await getVideoBySlug(params.slug, fetch);
|
2025-10-28 10:31:06 +01:00
|
|
|
|
2026-03-12 18:35:04 +01:00
|
|
|
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),
|
|
|
|
|
]);
|
2025-10-28 10:31:06 +01:00
|
|
|
|
2026-03-04 22:27:54 +01:00
|
|
|
try {
|
|
|
|
|
return {
|
|
|
|
|
video,
|
|
|
|
|
comments,
|
|
|
|
|
authStatus: locals.authStatus,
|
|
|
|
|
likeStatus,
|
2026-03-12 18:35:04 +01:00
|
|
|
relatedVideos: relatedVideos.items,
|
|
|
|
|
featuredArticle: featuredArticle.items[0] ?? null,
|
2026-03-04 22:27:54 +01:00
|
|
|
};
|
|
|
|
|
} catch {
|
|
|
|
|
error(404, "Video not found");
|
|
|
|
|
}
|
2025-10-25 22:04:41 +02:00
|
|
|
}
|