2025-10-25 22:04:41 +02:00
|
|
|
import { error } from "@sveltejs/kit";
|
2025-10-28 10:31:06 +01:00
|
|
|
import { getCommentsForVideo, getVideoBySlug, getVideoLikeStatus } 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 = await getCommentsForVideo(video.id, fetch);
|
2025-10-28 10:31:06 +01:00
|
|
|
|
|
|
|
|
let likeStatus = { liked: false };
|
|
|
|
|
if (locals.authStatus.authenticated) {
|
|
|
|
|
try {
|
|
|
|
|
likeStatus = await getVideoLikeStatus(video.id, fetch);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Failed to get like status:", error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-25 22:04:41 +02:00
|
|
|
try {
|
2025-10-28 10:31:06 +01:00
|
|
|
return {
|
|
|
|
|
video,
|
|
|
|
|
comments,
|
|
|
|
|
authStatus: locals.authStatus,
|
|
|
|
|
likeStatus
|
|
|
|
|
};
|
2025-10-25 22:04:41 +02:00
|
|
|
} catch {
|
|
|
|
|
error(404, "Video not found");
|
|
|
|
|
}
|
|
|
|
|
}
|