fix: use native fetch for getVideoBySlug to fix authenticated SSR

- Convert getVideoBySlug from Directus SDK to native fetch API
- Fixes serialization errors when authenticated users view video pages
- Remove unused readUsers import from @directus/sdk
- Directus SDK returns non-serializable objects with circular refs
- Native fetch returns plain JSON that works with SvelteKit SSR

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Valknar XXX
2025-10-29 05:36:16 +01:00
parent cd4c33a3f2
commit 5333bfd87a

View File

@@ -5,7 +5,6 @@ import {
updateMe,
readMe,
registerUserVerify,
readUsers,
passwordRequest,
passwordReset,
customEndpoint,
@@ -243,27 +242,28 @@ export async function getVideoBySlug(
return loggedApiCall(
"getVideoBySlug",
async () => {
const directus = getDirectusInstance(fetch);
return directus
.request<Video[]>(
readItems("sexy_videos", {
fields: [
"*",
{
models: [
"*",
{
directus_users_id: ["*"],
},
],
},
"movie.*",
],
filter: { slug },
}),
)
.then((videos) => {
if (videos.length === 0) {
const fetchFn = fetch || globalThis.fetch;
return fetchFn(
`${directusApiUrl}/items/sexy_videos?${new URLSearchParams({
filter: JSON.stringify({ slug: { _eq: slug } }),
fields: JSON.stringify([
"*",
{
models: [
"*",
{
directus_users_id: ["*"],
},
],
},
"movie.*",
]),
})}`,
)
.then((res) => res.json())
.then((response) => {
const videos = response.data;
if (!videos || videos.length === 0) {
throw new Error("Video not found");
}
// Handle models array - filter out null/undefined and map to user objects