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