diff --git a/src/lib/components/organisms/Category/Category.svelte b/src/lib/components/organisms/Category/Category.svelte index 0d62b25..b42aeef 100644 --- a/src/lib/components/organisms/Category/Category.svelte +++ b/src/lib/components/organisms/Category/Category.svelte @@ -92,7 +92,7 @@ {#key info} 56 + (index + 1 < files.length ? 4 : 0)} + itemHeight={(index) => 48 + (index + 1 < files.length ? 4 : 0)} > {#snippet item(index)} {@const { info, isRecursive } = files[index]!} diff --git a/src/lib/modules/filesystem.ts b/src/lib/modules/filesystem.ts index 9f447bf..f2995ef 100644 --- a/src/lib/modules/filesystem.ts +++ b/src/lib/modules/filesystem.ts @@ -1,4 +1,3 @@ -import { TRPCClientError } from "@trpc/client"; import { get, writable, type Writable } from "svelte/store"; import { getDirectoryInfos as getDirectoryInfosFromIndexedDB, @@ -18,7 +17,7 @@ import { type CategoryId, } from "$lib/indexedDB"; import { unwrapDataKey, decryptString } from "$lib/modules/crypto"; -import { trpc } from "$trpc/client"; +import { trpc, isTRPCClientError } from "$trpc/client"; export type DirectoryInfo = | { @@ -114,7 +113,7 @@ const fetchDirectoryInfoFromServer = async ( try { data = await trpc().directory.get.query({ id }); } catch (e) { - if (e instanceof TRPCClientError && e.data?.code === "NOT_FOUND") { + if (isTRPCClientError(e) && e.data?.code === "NOT_FOUND") { info.set(null); await deleteDirectoryInfo(id as number); return; @@ -187,7 +186,7 @@ const fetchFileInfoFromServer = async ( try { metadata = await trpc().file.get.query({ id }); } catch (e) { - if (e instanceof TRPCClientError && e.data?.code === "NOT_FOUND") { + if (isTRPCClientError(e) && e.data?.code === "NOT_FOUND") { info.set(null); await deleteFileInfo(id); return; @@ -283,7 +282,7 @@ const fetchCategoryInfoFromServer = async ( try { data = await trpc().category.get.query({ id }); } catch (e) { - if (e instanceof TRPCClientError && e.data?.code === "NOT_FOUND") { + if (isTRPCClientError(e) && e.data?.code === "NOT_FOUND") { info.set(null); await deleteCategoryInfo(id as number); return; diff --git a/src/lib/services/auth.ts b/src/lib/services/auth.ts index 56d67eb..95f153e 100644 --- a/src/lib/services/auth.ts +++ b/src/lib/services/auth.ts @@ -1,6 +1,5 @@ -import { TRPCClientError } from "@trpc/client"; import { encodeToBase64, decryptChallenge, signMessageRSA } from "$lib/modules/crypto"; -import { trpc } from "$trpc/client"; +import { trpc, isTRPCClientError } from "$trpc/client"; export const requestSessionUpgrade = async ( encryptKeyBase64: string, @@ -16,7 +15,7 @@ export const requestSessionUpgrade = async ( sigPubKey: verifyKeyBase64, })); } catch (e) { - if (e instanceof TRPCClientError && e.data?.code === "FORBIDDEN") { + if (isTRPCClientError(e) && e.data?.code === "FORBIDDEN") { return [false, "Unregistered client"] as const; } return [false] as const; @@ -31,7 +30,7 @@ export const requestSessionUpgrade = async ( force, }); } catch (e) { - if (e instanceof TRPCClientError && e.data?.code === "CONFLICT") { + if (isTRPCClientError(e) && e.data?.code === "CONFLICT") { return [false, "Already logged in"] as const; } return [false] as const; diff --git a/src/lib/services/key.ts b/src/lib/services/key.ts index fd89f74..4e97546 100644 --- a/src/lib/services/key.ts +++ b/src/lib/services/key.ts @@ -1,4 +1,3 @@ -import { TRPCClientError } from "@trpc/client"; import { storeMasterKeys } from "$lib/indexedDB"; import { encodeToBase64, @@ -11,7 +10,7 @@ import { } from "$lib/modules/crypto"; import { requestSessionUpgrade } from "$lib/services/auth"; import { masterKeyStore, type ClientKeys } from "$lib/stores"; -import { trpc } from "$trpc/client"; +import { trpc, isTRPCClientError } from "$trpc/client"; export const requestClientRegistration = async ( encryptKeyBase64: string, @@ -112,10 +111,7 @@ export const requestInitialMasterKeyAndHmacSecretRegistration = async ( mekSig: await signMasterKeyWrapped(masterKeyWrapped, 1, signKey), }); } catch (e) { - if ( - e instanceof TRPCClientError && - (e.data?.code === "FORBIDDEN" || e.data?.code === "CONFLICT") - ) { + if (isTRPCClientError(e) && (e.data?.code === "FORBIDDEN" || e.data?.code === "CONFLICT")) { return true; } // TODO: Error Handling diff --git a/src/routes/(fullscreen)/gallery/+page.server.ts b/src/routes/(fullscreen)/gallery/+page.server.ts new file mode 100644 index 0000000..84d5819 --- /dev/null +++ b/src/routes/(fullscreen)/gallery/+page.server.ts @@ -0,0 +1,7 @@ +import { createCaller } from "$trpc/router.server"; +import type { PageServerLoad } from "./$types"; + +export const load: PageServerLoad = async (event) => { + const files = await createCaller(event).file.list(); + return { files }; +}; diff --git a/src/routes/(fullscreen)/gallery/+page.ts b/src/routes/(fullscreen)/gallery/+page.ts deleted file mode 100644 index 1a241c5..0000000 --- a/src/routes/(fullscreen)/gallery/+page.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { trpc } from "$trpc/client"; -import type { PageLoad } from "./$types"; - -export const load: PageLoad = async ({ fetch }) => { - const files = await trpc(fetch).file.list.query(); - return { files }; -}; diff --git a/src/routes/(fullscreen)/settings/thumbnail/+page.server.ts b/src/routes/(fullscreen)/settings/thumbnail/+page.server.ts new file mode 100644 index 0000000..dc32e56 --- /dev/null +++ b/src/routes/(fullscreen)/settings/thumbnail/+page.server.ts @@ -0,0 +1,7 @@ +import { createCaller } from "$trpc/router.server"; +import type { PageServerLoad } from "./$types"; + +export const load: PageServerLoad = async (event) => { + const files = await createCaller(event).file.listWithoutThumbnail(); + return { files }; +}; diff --git a/src/routes/(fullscreen)/settings/thumbnail/+page.ts b/src/routes/(fullscreen)/settings/thumbnail/+page.ts deleted file mode 100644 index 4d5520c..0000000 --- a/src/routes/(fullscreen)/settings/thumbnail/+page.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { trpc } from "$trpc/client"; -import type { PageLoad } from "./$types"; - -export const load: PageLoad = async ({ fetch }) => { - const files = await trpc(fetch).file.listWithoutThumbnail.query(); - return { files }; -}; diff --git a/src/routes/(main)/directory/[[id]]/DirectoryEntries/DirectoryEntries.svelte b/src/routes/(main)/directory/[[id]]/DirectoryEntries/DirectoryEntries.svelte index f7ced96..527bd1b 100644 --- a/src/routes/(main)/directory/[[id]]/DirectoryEntries/DirectoryEntries.svelte +++ b/src/routes/(main)/directory/[[id]]/DirectoryEntries/DirectoryEntries.svelte @@ -130,7 +130,7 @@ {#if files.length > 0} 48 + (index + 1 < files.length ? 4 : 0)} + itemHeight={(index) => 56 + (index + 1 < files.length ? 4 : 0)} > {#snippet item(index)} {@const file = files[index]!} diff --git a/src/routes/(main)/menu/+page.server.ts b/src/routes/(main)/menu/+page.server.ts new file mode 100644 index 0000000..d27816b --- /dev/null +++ b/src/routes/(main)/menu/+page.server.ts @@ -0,0 +1,7 @@ +import { createCaller } from "$trpc/router.server"; +import type { PageServerLoad } from "./$types"; + +export const load: PageServerLoad = async (event) => { + const { nickname } = await createCaller(event).user.get(); + return { nickname }; +}; diff --git a/src/routes/(main)/menu/+page.ts b/src/routes/(main)/menu/+page.ts deleted file mode 100644 index 8842540..0000000 --- a/src/routes/(main)/menu/+page.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { trpc } from "$trpc/client"; -import type { PageLoad } from "./$types"; - -export const load: PageLoad = async ({ fetch }) => { - const { nickname } = await trpc(fetch).user.get.query(); - return { nickname }; -}; diff --git a/src/trpc/client.ts b/src/trpc/client.ts index a6e2f8b..9c4c5db 100644 --- a/src/trpc/client.ts +++ b/src/trpc/client.ts @@ -1,4 +1,4 @@ -import { createTRPCClient, httpBatchLink } from "@trpc/client"; +import { createTRPCClient, httpBatchLink, TRPCClientError } from "@trpc/client"; import superjson from "superjson"; import { browser } from "$app/environment"; import type { AppRouter } from "./router.server"; @@ -24,3 +24,7 @@ export const trpc = (fetch = globalThis.fetch) => { } return client; }; + +export const isTRPCClientError = (e: unknown): e is TRPCClientError => { + return e instanceof TRPCClientError; +};