From aa342cfbd3d3ccb59ea3c6290eb5a29b13372d05 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 7 Jul 2025 23:13:52 +0200 Subject: [PATCH] Fix base uri handling --- front/src/models/user.ts | 4 ++-- front/src/primitives/links.tsx | 3 ++- front/src/providers/account-context.tsx | 2 +- front/src/providers/account-provider.tsx | 3 +-- front/src/query/query.tsx | 12 ++++++------ front/src/ui/details/header.tsx | 13 +++++++++---- front/src/ui/login/logic.tsx | 2 +- 7 files changed, 22 insertions(+), 17 deletions(-) diff --git a/front/src/models/user.ts b/front/src/models/user.ts index 097bddee..c8a05452 100644 --- a/front/src/models/user.ts +++ b/front/src/models/user.ts @@ -43,7 +43,7 @@ export const User = z ...x, logo: `auth/users/${x.id}/logo`, // isVerified: x.permissions.length > 0, - // isAdmin: x.permissions?.includes("admin.write"), + isAdmin: true, //x.permissions?.includes("admin.write"), })); export type User = z.infer; @@ -54,5 +54,5 @@ export const Account = User.and( token: z.string(), selected: z.boolean(), }), -).transform((x) => ({ ...x, isAdmin: true })); +); export type Account = z.infer; diff --git a/front/src/primitives/links.tsx b/front/src/primitives/links.tsx index 87a175d6..c7d01936 100644 --- a/front/src/primitives/links.tsx +++ b/front/src/primitives/links.tsx @@ -20,8 +20,9 @@ function useLinkTo({ }) { const router = useRouter(); - // TODO: add href attr for web return { + // @ts-expect-error href is not known + href: href, onPress: (e) => { if (e?.defaultPrevented) return; if (href.startsWith("http")) { diff --git a/front/src/providers/account-context.tsx b/front/src/providers/account-context.tsx index b17cf594..2357d44d 100644 --- a/front/src/providers/account-context.tsx +++ b/front/src/providers/account-context.tsx @@ -6,7 +6,7 @@ export const AccountContext = createContext<{ authToken: string | null; selectedAccount: Account | null; accounts: (Account & { select: () => void; remove: () => void })[]; -}>({ apiUrl: "", authToken: null, selectedAccount: null, accounts: [] }); +}>({ apiUrl: "/", authToken: null, selectedAccount: null, accounts: [] }); export const useToken = () => { const { apiUrl, authToken } = useContext(AccountContext); diff --git a/front/src/providers/account-provider.tsx b/front/src/providers/account-provider.tsx index aa3a785a..35fbab84 100644 --- a/front/src/providers/account-provider.tsx +++ b/front/src/providers/account-provider.tsx @@ -1,6 +1,5 @@ import { useQueryClient } from "@tanstack/react-query"; import { type ReactNode, useEffect, useMemo, useRef } from "react"; -import { Platform } from "react-native"; import { z } from "zod/v4"; import { Account, User } from "~/models"; import { useFetch } from "~/query"; @@ -16,7 +15,7 @@ export const AccountProvider = ({ children }: { children: ReactNode }) => { const ret = useMemo(() => { const acc = accounts.find((x) => x.selected); return { - apiUrl: acc?.apiUrl ?? "", + apiUrl: acc?.apiUrl ?? "/", authToken: acc?.token ?? null, selectedAccount: acc ?? null, accounts: accounts.map((account) => ({ diff --git a/front/src/query/query.tsx b/front/src/query/query.tsx index 5f47016a..97895b44 100644 --- a/front/src/query/query.tsx +++ b/front/src/query/query.tsx @@ -15,10 +15,9 @@ import { setServerData } from "~/utils"; const ssrApiUrl = process.env.KYOO_URL ?? "http://api:3567/api"; -const cleanSlash = (str: string | null, keepFirst = false) => { - if (!str) return null; - if (keepFirst) return str.replace(/\/$/g, ""); - return str.replace(/^\/|\/$/g, ""); +const cleanSlash = (str: string | null) => { + if (str === null) return null; + return str.replace(/\/$/g, ""); }; export const queryFn = async (context: { @@ -31,6 +30,7 @@ export const queryFn = async (context: { parser: Parser | null; signal?: AbortSignal; }): Promise> => { + console.log(context.url); if ( Platform.OS === "web" && typeof window === "undefined" && @@ -154,7 +154,7 @@ const toQueryKey = (query: { }; }) => { return [ - cleanSlash(query.apiUrl, true), + cleanSlash(query.apiUrl), ...query.path, query.params ? `?${Object.entries(query.params) @@ -162,7 +162,7 @@ const toQueryKey = (query: { .map(([k, v]) => `${k}=${Array.isArray(v) ? v.join(",") : v}`) .join("&")}` : null, - ].filter((x) => x); + ].filter((x) => x !== undefined); }; export const keyToUrl = (key: ReturnType) => { diff --git a/front/src/ui/details/header.tsx b/front/src/ui/details/header.tsx index a50fd259..ce29d95e 100644 --- a/front/src/ui/details/header.tsx +++ b/front/src/ui/details/header.tsx @@ -541,7 +541,9 @@ export const Header = ({ // studio={data.studio} playHref={data.kind !== "collection" ? data.playHref : null} trailerUrl={data.kind !== "collection" ? data.trailerUrl : null} - watchStatus={data.kind !== "collection" ? data.watchStatus?.status! : null} + watchStatus={ + data.kind !== "collection" ? data.watchStatus?.status! : null + } {...css({ marginTop: { xs: max(vh(20), px(200)), @@ -596,10 +598,13 @@ export const Header = ({ ); }; -Header.query = (kind: string, slug: string): QueryIdentifier => ({ +Header.query = ( + kind: "serie" | "movie" | "collection", + slug: string, +): QueryIdentifier => ({ parser: Show, - path: [kind, slug], + path: ["api", `${kind}s`, slug], params: { - with: ["studio", "watchStatus"], + with: ["studios"], }, }); diff --git a/front/src/ui/login/logic.tsx b/front/src/ui/login/logic.tsx index ec7f3ab8..13a6fa6e 100644 --- a/front/src/ui/login/logic.tsx +++ b/front/src/ui/login/logic.tsx @@ -20,7 +20,7 @@ export const login = async ( apiUrl: string | null; }, ): Promise> => { - apiUrl ??= ""; + apiUrl ??= "/"; try { const controller = new AbortController(); setTimeout(() => controller.abort(), 5_000);