mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-08 18:54:22 -04:00
Fix base uri handling
This commit is contained in:
parent
c7103410dc
commit
aa342cfbd3
@ -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<typeof User>;
|
||||
|
||||
@ -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<typeof Account>;
|
||||
|
@ -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")) {
|
||||
|
@ -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);
|
||||
|
@ -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) => ({
|
||||
|
@ -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 <Parser extends z.ZodTypeAny>(context: {
|
||||
@ -31,6 +30,7 @@ export const queryFn = async <Parser extends z.ZodTypeAny>(context: {
|
||||
parser: Parser | null;
|
||||
signal?: AbortSignal;
|
||||
}): Promise<z.infer<Parser>> => {
|
||||
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<typeof toQueryKey>) => {
|
||||
|
@ -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<Show> => ({
|
||||
Header.query = (
|
||||
kind: "serie" | "movie" | "collection",
|
||||
slug: string,
|
||||
): QueryIdentifier<Show> => ({
|
||||
parser: Show,
|
||||
path: [kind, slug],
|
||||
path: ["api", `${kind}s`, slug],
|
||||
params: {
|
||||
with: ["studio", "watchStatus"],
|
||||
with: ["studios"],
|
||||
},
|
||||
});
|
||||
|
@ -20,7 +20,7 @@ export const login = async (
|
||||
apiUrl: string | null;
|
||||
},
|
||||
): Promise<Result<Account, string>> => {
|
||||
apiUrl ??= "";
|
||||
apiUrl ??= "/";
|
||||
try {
|
||||
const controller = new AbortController();
|
||||
setTimeout(() => controller.abort(), 5_000);
|
||||
|
Loading…
x
Reference in New Issue
Block a user