mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-01 12:44:45 -04:00
Format front
This commit is contained in:
parent
49d225532c
commit
7dab3fd094
@ -170,7 +170,6 @@ App.getInitialProps = async (ctx: AppContext) => {
|
|||||||
|
|
||||||
if (typeof window !== "undefined") return { pageProps: superjson.serialize(appProps.pageProps) };
|
if (typeof window !== "undefined") return { pageProps: superjson.serialize(appProps.pageProps) };
|
||||||
|
|
||||||
|
|
||||||
const getUrl = Component.getFetchUrls;
|
const getUrl = Component.getFetchUrls;
|
||||||
const getLayoutUrl =
|
const getLayoutUrl =
|
||||||
Component.getLayout && "Layout" in Component.getLayout
|
Component.getLayout && "Layout" in Component.getLayout
|
||||||
|
@ -63,7 +63,7 @@ export const AccountProvider = ({
|
|||||||
}) => {
|
}) => {
|
||||||
if (Platform.OS === "web" && typeof window === "undefined") {
|
if (Platform.OS === "web" && typeof window === "undefined") {
|
||||||
const accs = ssrAccount
|
const accs = ssrAccount
|
||||||
? [{ ...ssrAccount, selected: true, select: () => { }, remove: () => { } }]
|
? [{ ...ssrAccount, selected: true, select: () => {}, remove: () => {} }]
|
||||||
: [];
|
: [];
|
||||||
return (
|
return (
|
||||||
<AccountContext.Provider value={accs}>
|
<AccountContext.Provider value={accs}>
|
||||||
|
@ -59,9 +59,10 @@ export const login = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getTokenWJ = async (account?: Account | null): Promise<[string, Token] | [null, null]> => {
|
export const getTokenWJ = async (
|
||||||
if (account === undefined)
|
account?: Account | null,
|
||||||
account = getCurrentAccount();
|
): Promise<[string, Token] | [null, null]> => {
|
||||||
|
if (account === undefined) account = getCurrentAccount();
|
||||||
if (!account) return [null, null];
|
if (!account) return [null, null];
|
||||||
|
|
||||||
if (account.token.expire_at <= new Date(new Date().getTime() + 10 * 1000)) {
|
if (account.token.expire_at <= new Date(new Date().getTime() + 10 * 1000)) {
|
||||||
@ -81,8 +82,7 @@ export const getTokenWJ = async (account?: Account | null): Promise<[string, Tok
|
|||||||
return [`${account.token.token_type} ${account.token.access_token}`, account.token];
|
return [`${account.token.token_type} ${account.token.access_token}`, account.token];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getToken = async (): Promise<string | null> =>
|
export const getToken = async (): Promise<string | null> => (await getTokenWJ())[0];
|
||||||
(await getTokenWJ())[0];
|
|
||||||
|
|
||||||
export const logout = () => {
|
export const logout = () => {
|
||||||
removeAccounts((x) => x.selected);
|
removeAccounts((x) => x.selected);
|
||||||
|
@ -37,8 +37,8 @@ const kyooUrl =
|
|||||||
Platform.OS !== "web"
|
Platform.OS !== "web"
|
||||||
? process.env.PUBLIC_BACK_URL
|
? process.env.PUBLIC_BACK_URL
|
||||||
: typeof window === "undefined"
|
: typeof window === "undefined"
|
||||||
? process.env.KYOO_URL ?? "http://localhost:5000"
|
? process.env.KYOO_URL ?? "http://localhost:5000"
|
||||||
: "/api";
|
: "/api";
|
||||||
|
|
||||||
export let kyooApiUrl: string | null = kyooUrl || null;
|
export let kyooApiUrl: string | null = kyooUrl || null;
|
||||||
|
|
||||||
@ -50,13 +50,13 @@ export const queryFn = async <Data,>(
|
|||||||
context:
|
context:
|
||||||
| (QueryFunctionContext & { timeout?: number })
|
| (QueryFunctionContext & { timeout?: number })
|
||||||
| {
|
| {
|
||||||
path: (string | false | undefined | null)[];
|
path: (string | false | undefined | null)[];
|
||||||
body?: object;
|
body?: object;
|
||||||
method: "GET" | "POST" | "DELETE";
|
method: "GET" | "POST" | "DELETE";
|
||||||
authenticated?: boolean;
|
authenticated?: boolean;
|
||||||
apiUrl?: string;
|
apiUrl?: string;
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
},
|
},
|
||||||
type?: z.ZodType<Data>,
|
type?: z.ZodType<Data>,
|
||||||
token?: string | null,
|
token?: string | null,
|
||||||
): Promise<Data> => {
|
): Promise<Data> => {
|
||||||
@ -72,8 +72,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, i) => x && i) as string[]),
|
: (context.queryKey.filter((x, i) => x && i) as string[]),
|
||||||
)
|
)
|
||||||
.join("/")
|
.join("/")
|
||||||
.replace("/?", "?");
|
.replace("/?", "?");
|
||||||
@ -109,7 +109,8 @@ export const queryFn = async <Data,>(
|
|||||||
data = { errors: [error] } as KyooErrors;
|
data = { errors: [error] } as KyooErrors;
|
||||||
}
|
}
|
||||||
console.log(
|
console.log(
|
||||||
`Invalid response (${"method" in context && context.method ? context.method : "GET"
|
`Invalid response (${
|
||||||
|
"method" in context && context.method ? context.method : "GET"
|
||||||
} ${path}):`,
|
} ${path}):`,
|
||||||
data,
|
data,
|
||||||
resp.status,
|
resp.status,
|
||||||
@ -173,8 +174,8 @@ export type QueryPage<Props = {}, Items = unknown> = ComponentType<
|
|||||||
> & {
|
> & {
|
||||||
getFetchUrls?: (route: { [key: string]: string }, randomItems: Items[]) => QueryIdentifier<any>[];
|
getFetchUrls?: (route: { [key: string]: string }, randomItems: Items[]) => QueryIdentifier<any>[];
|
||||||
getLayout?:
|
getLayout?:
|
||||||
| QueryPage<{ page: ReactElement }>
|
| QueryPage<{ page: ReactElement }>
|
||||||
| { Layout: QueryPage<{ page: ReactElement }>; props: object };
|
| { Layout: QueryPage<{ page: ReactElement }>; props: object };
|
||||||
randomItems?: Items[];
|
randomItems?: Items[];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -186,10 +187,10 @@ const toQueryKey = <Data, Ret>(query: QueryIdentifier<Data, Ret>) => {
|
|||||||
...prefix,
|
...prefix,
|
||||||
...query.path,
|
...query.path,
|
||||||
"?" +
|
"?" +
|
||||||
Object.entries(query.params)
|
Object.entries(query.params)
|
||||||
.filter(([_, v]) => v !== undefined)
|
.filter(([_, v]) => v !== undefined)
|
||||||
.map(([k, v]) => `${k}=${Array.isArray(v) ? v.join(",") : v}`)
|
.map(([k, v]) => `${k}=${Array.isArray(v) ? v.join(",") : v}`)
|
||||||
.join("&"),
|
.join("&"),
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
return [...prefix, ...query.path];
|
return [...prefix, ...query.path];
|
||||||
|
@ -74,7 +74,11 @@ export const LoginPage: QueryPage = () => {
|
|||||||
<Button
|
<Button
|
||||||
text={t("login.login")}
|
text={t("login.login")}
|
||||||
onPress={async () => {
|
onPress={async () => {
|
||||||
const { error } = await login("login", { username, password, apiUrl: cleanApiUrl(apiUrl) });
|
const { error } = await login("login", {
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
apiUrl: cleanApiUrl(apiUrl),
|
||||||
|
});
|
||||||
setError(error);
|
setError(error);
|
||||||
if (error) return;
|
if (error) return;
|
||||||
router.replace("/", undefined, {
|
router.replace("/", undefined, {
|
||||||
|
@ -100,10 +100,10 @@ const VolumeSlider = () => {
|
|||||||
isMuted || volume == 0
|
isMuted || volume == 0
|
||||||
? VolumeOff
|
? VolumeOff
|
||||||
: volume < 25
|
: volume < 25
|
||||||
? VolumeMute
|
? VolumeMute
|
||||||
: volume < 65
|
: volume < 65
|
||||||
? VolumeDown
|
? VolumeDown
|
||||||
: VolumeUp
|
: VolumeUp
|
||||||
}
|
}
|
||||||
onPress={() => setMuted(!isMuted)}
|
onPress={() => setMuted(!isMuted)}
|
||||||
{...tooltip(t("player.mute"), true)}
|
{...tooltip(t("player.mute"), true)}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user