Fix randomItems and images api url on android

This commit is contained in:
Zoe Roux 2023-12-09 00:07:34 +01:00
parent 6e530786b9
commit a6eb744cc9
7 changed files with 60 additions and 19 deletions

View File

@ -18,6 +18,7 @@
* along with Kyoo. If not, see <https://www.gnu.org/licenses/>. * along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { HomePage } from "@kyoo/ui"; import { HomePage, BrowsePage } from "@kyoo/ui";
import { withRoute } from "../utils";
export default HomePage; export default withRoute(BrowsePage);

View File

@ -0,0 +1,41 @@
/*
* Kyoo - A portable and vast media library solution.
* Copyright (c) Kyoo.
*
* See AUTHORS.md and LICENSE file in the project root for full license information.
*
* Kyoo is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Kyoo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
*/
import { NavbarTitle } from "@kyoo/ui";
import { Stack } from "expo-router";
import { useTheme } from "yoshiki/native";
export default function PublicLayout() {
const theme = useTheme();
return (
<Stack
screenOptions={{
headerTitle: () => <NavbarTitle />,
contentStyle: {
backgroundColor: theme.background,
},
headerStyle: {
backgroundColor: theme.accent,
},
headerTintColor: theme.colors.white,
}}
/>
);
}

View File

@ -23,6 +23,8 @@ import { ComponentType, useEffect } from "react";
import { StatusBar, StatusBarProps } from "react-native"; import { StatusBar, StatusBarProps } from "react-native";
import * as ScreenOrientation from "expo-screen-orientation"; import * as ScreenOrientation from "expo-screen-orientation";
import * as NavigationBar from "expo-navigation-bar"; import * as NavigationBar from "expo-navigation-bar";
import arrayShuffle from "array-shuffle";
import { QueryPage } from "@kyoo/models";
const FullscreenProvider = () => { const FullscreenProvider = () => {
useEffect(() => { useEffect(() => {
@ -52,7 +54,12 @@ export const withRoute = <Props,>(
{routeOptions && <Stack.Screen {...routeOptions} />} {routeOptions && <Stack.Screen {...routeOptions} />}
{statusBar && <StatusBar {...statusBar} />} {statusBar && <StatusBar {...statusBar} />}
{fullscreen && <FullscreenProvider />} {fullscreen && <FullscreenProvider />}
<Component {...defaultProps} {...routeParams} {...props} /> <Component
{...defaultProps}
randomItems={arrayShuffle((Component as QueryPage).randomItems ?? [])}
{...routeParams}
{...props}
/>
</> </>
); );
}; };

View File

@ -31,19 +31,12 @@ import { KyooErrors } from "./kyoo-errors";
import { Page, Paged } from "./page"; import { Page, Paged } from "./page";
import { Platform } from "react-native"; import { Platform } from "react-native";
import { getToken } from "./login"; import { getToken } from "./login";
import { getCurrentAccount } from "./account-internal";
const kyooUrl = const kyooUrl =
Platform.OS !== "web" typeof window === "undefined" ? process.env.KYOO_URL ?? "http://localhost:5000" : "/api";
? process.env.PUBLIC_BACK_URL // The url of kyoo, set after each query (used by the image parser).
: typeof window === "undefined" export let kyooApiUrl = kyooUrl;
? process.env.KYOO_URL ?? "http://localhost:5000"
: "/api";
export let kyooApiUrl: string | null = kyooUrl || null;
export const setApiUrl = (apiUrl: string) => {
kyooApiUrl = apiUrl;
};
export const queryFn = async <Data,>( export const queryFn = async <Data,>(
context: context:
@ -60,8 +53,7 @@ export const queryFn = async <Data,>(
token?: string | null, token?: string | null,
): Promise<Data> => { ): Promise<Data> => {
// @ts-ignore // @ts-ignore
let url: string | null = context.apiUrl ?? kyooApiUrl; const url = context.apiUrl ?? (Platform.OS === "web" ? kyooUrl : getCurrentAccount()!.apiUrl);
if (!url) console.error("Kyoo's url is not defined.");
kyooApiUrl = url; kyooApiUrl = url;
// @ts-ignore // @ts-ignore
@ -71,8 +63,8 @@ export const queryFn = async <Data,>(
"path" in context "path" in context
? (context.path.filter((x) => x) as string[]) ? (context.path.filter((x) => x) as string[])
: "pageParam" in context && context.pageParam : "pageParam" in context && context.pageParam
? [context.pageParam as string] ? [context.pageParam as string]
: (context.queryKey.filter((x) => x) as string[]), : (context.queryKey.filter((x) => x) as string[]),
) )
.join("/") .join("/")
.replace("/?", "?"); .replace("/?", "?");
@ -93,7 +85,7 @@ export const queryFn = async <Data,>(
signal: controller?.signal, signal: controller?.signal,
}); });
} catch (e) { } catch (e) {
console.log("Fetch error", e); console.log("Fetch error", e, path);
throw { errors: ["Could not reach Kyoo's server."] } as KyooErrors; throw { errors: ["Could not reach Kyoo's server."] } as KyooErrors;
} }
if (resp.status === 404) { if (resp.status === 404) {