From 092bef52eb432ac224aab8162b83a86f05e8c204 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 20 Jul 2025 00:33:55 +0200 Subject: [PATCH] Delete old `models` package --- front/packages/models/package.json | 24 --- front/packages/models/src/account-internal.ts | 19 -- front/packages/models/src/accounts.tsx | 77 -------- front/packages/models/src/index.ts | 26 --- front/packages/models/src/issue.ts | 48 ----- front/packages/models/src/login.ts | 179 ------------------ front/packages/models/src/theme.ts | 44 ----- front/packages/models/src/utils.ts | 39 ---- front/packages/models/tsconfig.json | 26 --- front/packages/ui/package.json | 50 ----- front/packages/ui/src/layout.tsx | 78 -------- 11 files changed, 610 deletions(-) delete mode 100644 front/packages/models/package.json delete mode 100644 front/packages/models/src/account-internal.ts delete mode 100644 front/packages/models/src/accounts.tsx delete mode 100644 front/packages/models/src/index.ts delete mode 100644 front/packages/models/src/issue.ts delete mode 100644 front/packages/models/src/login.ts delete mode 100644 front/packages/models/src/theme.ts delete mode 100644 front/packages/models/src/utils.ts delete mode 100755 front/packages/models/tsconfig.json delete mode 100644 front/packages/ui/package.json delete mode 100644 front/packages/ui/src/layout.tsx diff --git a/front/packages/models/package.json b/front/packages/models/package.json deleted file mode 100644 index 630960ac..00000000 --- a/front/packages/models/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "@kyoo/models", - "main": "src/index.ts", - "types": "src/index.ts", - "sideEffects": false, - "packageManager": "yarn@3.2.4", - "devDependencies": { - "react-native-mmkv": "^2.12.2", - "typescript": "^5.5.4" - }, - "peerDependencies": { - "@tanstack/react-query": "*", - "react": "*", - "react-native": "*" - }, - "peerDependenciesMeta": { - "react-native-web": { - "optional": true - } - }, - "dependencies": { - "zod": "^3.23.8" - } -} diff --git a/front/packages/models/src/account-internal.ts b/front/packages/models/src/account-internal.ts deleted file mode 100644 index 609d690d..00000000 --- a/front/packages/models/src/account-internal.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 . - */ diff --git a/front/packages/models/src/accounts.tsx b/front/packages/models/src/accounts.tsx deleted file mode 100644 index 550d4c77..00000000 --- a/front/packages/models/src/accounts.tsx +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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 . - */ - -import { useQueryClient } from "@tanstack/react-query"; -import { atom, getDefaultStore, useAtomValue, useSetAtom } from "jotai"; -import { - type ReactNode, - createContext, - useContext, - useEffect, - useMemo, - useRef, - useState, -} from "react"; -import { Platform } from "react-native"; -import { useMMKVString } from "react-native-mmkv"; -import { z } from "zod"; -import { removeAccounts, setCookie, updateAccount } from "./account-internal"; -import type { KyooErrors } from "./kyoo-errors"; -import { useFetch } from "./query"; -import { ServerInfoP, type User, UserP } from "./resources"; -import { zdate } from "./utils"; - -const currentApiUrl = atom(defaultApiUrl); -export const getCurrentApiUrl = () => { - const store = getDefaultStore(); - return store.get(currentApiUrl); -}; -export const useCurrentApiUrl = () => { - return useAtomValue(currentApiUrl); -}; -export const setSsrApiUrl = () => { - const store = getDefaultStore(); - store.set(currentApiUrl, process.env.KYOO_URL ?? "http://localhost:5000"); -}; - - -export const useAccount = () => { - const acc = useContext(AccountContext); - return acc.find((x) => x.selected) || null; -}; - -export const useAccounts = () => { - return useContext(AccountContext); -}; - -export const useHasPermission = (perms?: string[]) => { - const account = useAccount(); - const { data } = useFetch({ - path: ["info"], - parser: ServerInfoP, - }); - - if (!perms || !perms[0]) return true; - - const available = account?.permissions ?? data?.guestPermissions; - if (!available) return false; - return perms.every((perm) => available.includes(perm)); -}; - diff --git a/front/packages/models/src/index.ts b/front/packages/models/src/index.ts deleted file mode 100644 index 39f64821..00000000 --- a/front/packages/models/src/index.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 . - */ - -export * from "./accounts"; -export { storage } from "./account-internal"; -export * from "./theme"; -export * from "./utils"; -export * from "./login"; -export * from "./issue"; diff --git a/front/packages/models/src/issue.ts b/front/packages/models/src/issue.ts deleted file mode 100644 index c519db97..00000000 --- a/front/packages/models/src/issue.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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 . - */ - -import { z } from "zod"; -import { zdate } from "./utils"; - -export const IssueP = z.object({ - /** - * The type of issue (for example, "Scanner" if this issue was created due to scanning error). - */ - domain: z.string(), - /** - * Why this issue was caused? An unique cause that can be used to identify this issue. - * For the scanner, a cause should be a video path. - */ - cause: z.string(), - /** - * A human readable string explaining why this issue occured. - */ - reason: z.string(), - /** - * Some extra data that could store domain-specific info. - */ - extra: z.record(z.string(), z.any()), - /** - * The date the issue was reported. - */ - addedDate: zdate(), -}); - -export type Issue = z.infer; diff --git a/front/packages/models/src/login.ts b/front/packages/models/src/login.ts deleted file mode 100644 index e846d74d..00000000 --- a/front/packages/models/src/login.ts +++ /dev/null @@ -1,179 +0,0 @@ -/* - * 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 . - */ - -import { useEffect, useRef, useState } from "react"; -import { Platform } from "react-native"; -import { addAccount, getCurrentAccount, removeAccounts, updateAccount } from "./account-internal"; -import { type Account, type Token, TokenP, getCurrentApiUrl } from "./accounts"; -import type { KyooErrors } from "./kyoo-errors"; -import { queryFn } from "./query"; -import { UserP } from "./resources"; - -type Result = - | { ok: true; value: A; error?: undefined } - | { ok: false; value?: undefined; error: B }; - -export const login = async ( - action: "register" | "login", - { apiUrl, ...body }: { username: string; password: string; email?: string; apiUrl?: string }, -): Promise> => { - if (!apiUrl || apiUrl.length === 0) apiUrl = getCurrentApiUrl()!; - try { - const controller = new AbortController(); - setTimeout(() => controller.abort(), 5_000); - const token = await queryFn( - { - path: ["auth", action], - method: "POST", - body, - authenticated: false, - apiUrl, - signal: controller.signal, - }, - TokenP, - ); - const user = await queryFn( - { path: ["auth", "me"], method: "GET", apiUrl }, - UserP, - `Bearer ${token.access_token}`, - ); - const account: Account = { ...user, apiUrl: apiUrl, token, selected: true }; - addAccount(account); - return { ok: true, value: account }; - } catch (e) { - console.error(action, e); - return { ok: false, error: (e as KyooErrors).errors[0] }; - } -}; - -export const oidcLogin = async (provider: string, code: string, apiUrl?: string) => { - if (!apiUrl || apiUrl.length === 0) apiUrl = getCurrentApiUrl()!; - try { - const token = await queryFn( - { - path: ["auth", "callback", provider, `?code=${code}`], - method: "POST", - authenticated: false, - apiUrl, - }, - TokenP, - ); - const user = await queryFn( - { path: ["auth", "me"], method: "GET", apiUrl }, - UserP, - `Bearer ${token.access_token}`, - ); - const account: Account = { ...user, apiUrl: apiUrl, token, selected: true }; - addAccount(account); - return { ok: true, value: account }; - } catch (e) { - console.error("oidcLogin", e); - return { ok: false, error: (e as KyooErrors).errors[0] }; - } -}; - -let running_id: string | null = null; -let running: ReturnType | null = null; - -export const getTokenWJ = async ( - acc?: Account | null, - forceRefresh = false, -): Promise => { - if (acc === undefined) acc = getCurrentAccount(); - if (!acc) return [null, null, null] as const; - const account = acc; - - async function run() { - let token = account.token; - - if (forceRefresh || account.token.expire_at <= new Date(new Date().getTime() + 10 * 1000)) { - console.log("refreshing token for account", account.slug); - try { - token = await queryFn( - { - path: ["auth", "refresh", `?token=${account.token.refresh_token}`], - method: "GET", - authenticated: false, - }, - TokenP, - ); - if (Platform.OS !== "web" || typeof window !== "undefined") - updateAccount(account.id, { ...account, token }); - } catch (e) { - console.error("Error refreshing token durring ssr:", e); - return [null, null, e as KyooErrors] as const; - } - } - return [`${token.token_type} ${token.access_token}`, token, null] as const; - } - - // Do not cache promise durring ssr. - if (Platform.OS === "web" && typeof window === "undefined") return await run(); - - if (running && running_id === account.id) return await running; - running_id = account.id; - running = run(); - const ret = await running; - running_id = null; - running = null; - return ret; -}; - -export const getToken = async (): Promise => (await getTokenWJ())[0]; - -export const getCurrentToken = () => { - const account = getCurrentAccount(); - return account ? `${account.token.token_type} ${account.token.access_token}` : null; -}; - -export const useToken = () => { - const account = getCurrentAccount(); - const refresher = useRef(null); - const [token, setToken] = useState( - account ? `${account.token.token_type} ${account.token.access_token}` : null, - ); - - // biome-ignore lint/correctness/useExhaustiveDependencies: Refresh token when account change - useEffect(() => { - async function run() { - const nToken = await getTokenWJ(); - setToken(nToken[0]); - if (refresher.current) clearTimeout(refresher.current); - if (nToken[1]) - refresher.current = setTimeout(run, nToken[1].expire_at.getTime() - Date.now()); - } - run(); - return () => { - if (refresher.current) clearTimeout(refresher.current); - }; - }, [account]); - - if (!token) return null; - return token; -}; - -export const logout = () => { - removeAccounts((x) => x.selected); -}; - -export const deleteAccount = async () => { - await queryFn({ path: ["auth", "me"], method: "DELETE" }); - logout(); -}; diff --git a/front/packages/models/src/theme.ts b/front/packages/models/src/theme.ts deleted file mode 100644 index 773389ec..00000000 --- a/front/packages/models/src/theme.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 . - */ - -import { Platform } from "react-native"; -import { useMMKVString } from "react-native-mmkv"; -import { setCookie, storage } from "./account-internal"; - -export const useUserTheme = (ssrTheme?: "light" | "dark" | "auto") => { - if (Platform.OS === "web" && typeof window === "undefined" && ssrTheme) return ssrTheme; - const [value] = useMMKVString("theme", storage); - if (!value) return "auto"; - return value as "light" | "dark" | "auto"; -}; - -export const storeData = (key: string, value: string | number | boolean) => { - storage.set(key, value); - if (Platform.OS === "web") setCookie(key, value); -}; - -export const deleteData = (key: string) => { - storage.delete(key); - if (Platform.OS === "web") setCookie(key, undefined); -}; - -export const setUserTheme = (theme: "light" | "dark" | "auto") => { - storeData("theme", theme); -}; diff --git a/front/packages/models/src/utils.ts b/front/packages/models/src/utils.ts deleted file mode 100644 index 6b35fd2e..00000000 --- a/front/packages/models/src/utils.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 . - */ - -import { Platform } from "react-native"; -import { useMMKVString } from "react-native-mmkv"; -import { z } from "zod"; -import { storage } from "./account-internal"; -import type { Movie, Show } from "./resources"; - -export const zdate = z.coerce.date; - -export const useLocalSetting = (setting: string, def: string) => { - if (Platform.OS === "web" && typeof window === "undefined") return [def, null!] as const; - // eslint-disable-next-line react-hooks/rules-of-hooks - const [val, setter] = useMMKVString(`settings.${setting}`, storage); - return [val ?? def, setter] as const; -}; - -export const getLocalSetting = (setting: string, def: string) => { - if (Platform.OS === "web" && typeof window === "undefined") return def; - return storage.getString(`settings.${setting}`) ?? setting; -}; diff --git a/front/packages/models/tsconfig.json b/front/packages/models/tsconfig.json deleted file mode 100755 index 8376e1ef..00000000 --- a/front/packages/models/tsconfig.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "compilerOptions": { - "target": "es6", - "lib": ["dom", "dom.iterable", "esnext"], - "declaration": true, - "sourceMap": true, - "noEmit": true, - "allowJs": true, - "skipLibCheck": true, - "strict": true, - "forceConsistentCasingInFileNames": true, - "esModuleInterop": true, - "module": "esnext", - "moduleResolution": "node", - "resolveJsonModule": true, - "isolatedModules": true, - "jsx": "react-jsx", - "incremental": true, - "baseUrl": ".", - "paths": { - "~/*": ["src/*"] - } - }, - "include": ["**/*.ts", "**/*.tsx"], - "exclude": ["node_modules"] -} diff --git a/front/packages/ui/package.json b/front/packages/ui/package.json deleted file mode 100644 index cd3408c8..00000000 --- a/front/packages/ui/package.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "name": "@kyoo/ui", - "main": "src/index.ts", - "types": "src/index.ts", - "packageManager": "yarn@3.2.4", - "dependencies": { - "@kyoo/models": "workspace:^", - "@kyoo/primitives": "workspace:^", - "langmap": "^0.0.16" - }, - "devDependencies": { - "@gorhom/portal": "^1.0.14", - "@shopify/flash-list": "^1.7.1", - "@types/langmap": "^0.0.3", - "react-native-uuid": "^2.0.2", - "typescript": "^5.5.4" - }, - "peerDependencies": { - "@gorhom/portal": "*", - "@kesha-antonov/react-native-background-downloader": "*", - "@material-symbols/svg-400": "*", - "@shopify/flash-list": "^1.3.1", - "@tanstack/react-query": "*", - "expo-file-system": "*", - "expo-image-picker": "~14.7.1", - "expo-linear-gradient": "*", - "expo-router": "*", - "i18next": "*", - "moti": "*", - "react": "*", - "react-i18next": "*", - "react-native": "*", - "react-native-reanimated": "*", - "react-native-svg": "*", - "yoshiki": "*" - }, - "optionalDependencies": { - "@kesha-antonov/react-native-background-downloader": "^3.2.0", - "expo-file-system": "^17.0.1", - "expo-router": "^3.5.21" - }, - "peerDependenciesMeta": { - "@kesha-antonov/react-native-background-downloader": { - "optional": true - }, - "expo-router": { - "optional": true - } - } -} diff --git a/front/packages/ui/src/layout.tsx b/front/packages/ui/src/layout.tsx deleted file mode 100644 index 6aff1c9b..00000000 --- a/front/packages/ui/src/layout.tsx +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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 . - */ - -import { Main } from "@kyoo/primitives"; -import { LinearGradient } from "expo-linear-gradient"; -import type { ReactElement } from "react"; -import { useYoshiki, vw } from "yoshiki/native"; -import { Navbar } from "../../../src/ui/navbar/src/ui/navbar"; - -export const DefaultLayout = ({ - page, - transparent, -}: { - page: ReactElement; - transparent?: boolean; -}) => { - const { css, theme } = useYoshiki(); - return ( - <> - - ) : undefined - } - /> -
- {page} -
- - ); -};