Fix types

This commit is contained in:
Zoe Roux 2024-01-30 18:19:12 +01:00
parent 93608c9549
commit e3908da7a9
3 changed files with 8 additions and 6 deletions

View File

@ -41,6 +41,8 @@ export const login = async (
timeout?: number,
): Promise<Result<Account, string>> => {
try {
const controller = new AbortController();
setTimeout(() => controller.abort(), 5_000);
const token = await queryFn(
{
path: ["auth", action],
@ -48,7 +50,7 @@ export const login = async (
body,
authenticated: false,
apiUrl,
timeout,
signal: controller.signal,
},
TokenP,
);

View File

@ -38,7 +38,7 @@ const kyooUrl =
// The url of kyoo, set after each query (used by the image parser).
export let kyooApiUrl = kyooUrl;
export const queryFn = async <Data,>(
export const queryFn = async <Parser extends z.ZodTypeAny>(
context: {
apiUrl?: string;
authenticated?: boolean;
@ -51,9 +51,9 @@ export const queryFn = async <Data,>(
plainText?: boolean;
} & Partial<QueryFunctionContext>)
),
type?: z.ZodType<Data>,
type?: Parser,
token?: string | null,
): Promise<Data> => {
): Promise<z.infer<Parser>> => {
const url = context.apiUrl ?? (Platform.OS === "web" ? kyooUrl : getCurrentAccount()!.apiUrl);
kyooApiUrl = url;
@ -106,10 +106,9 @@ export const queryFn = async <Data,>(
throw data as KyooErrors;
}
// @ts-expect-error Assume Data is nullable.
if (resp.status === 204) return null;
if ("plainText" in context && context.plainText) return (await resp.text()) as unknown as Data;
if ("plainText" in context && context.plainText) return (await resp.text()) as unknown;
let data;
try {

View File

@ -170,6 +170,7 @@ export const QualitiesMenu = (props: CustomMenu) => {
}}
/>
{/* TODO: Support video tracks when the play mode is not hls. */}
{/* @ts-expect-error They forgot to type this. */}
{info?.videoTracks.map((x) => (
<Menu.Item
key={x.height}