사소한 리팩토링 2

This commit is contained in:
static
2025-12-26 15:45:03 +09:00
parent d94d14cf83
commit c9d4b10356
16 changed files with 54 additions and 84 deletions

View File

@@ -1,10 +1,8 @@
import { useTRPC } from "$trpc/client";
import { trpc } from "$trpc/client";
export const requestPasswordChange = async (oldPassword: string, newPassword: string) => {
const trpc = useTRPC();
try {
await trpc.auth.changePassword.mutate({ oldPassword, newPassword });
await trpc().auth.changePassword.mutate({ oldPassword, newPassword });
return true;
} catch {
// TODO: Error Handling

View File

@@ -1,4 +1,4 @@
import { useTRPC } from "$trpc/client";
import { trpc } from "$trpc/client";
export { requestLogout } from "$lib/services/auth";
export { requestDeletedFilesCleanup } from "$lib/services/file";
@@ -8,10 +8,8 @@ export {
} from "$lib/services/key";
export const requestLogin = async (email: string, password: string) => {
const trpc = useTRPC();
try {
await trpc.auth.login.mutate({ email, password });
await trpc().auth.login.mutate({ email, password });
return true;
} catch {
// TODO: Error Handling

View File

@@ -1,7 +1,7 @@
import { encryptData } from "$lib/modules/crypto";
import { storeFileThumbnailCache } from "$lib/modules/file";
import { requestFileThumbnailUpload } from "$lib/services/file";
import { useTRPC } from "$trpc/client";
import { trpc } from "$trpc/client";
export { requestCategoryCreation, requestFileRemovalFromCategory } from "$lib/services/category";
export { requestFileDownload } from "$lib/services/file";
@@ -22,10 +22,8 @@ export const requestThumbnailUpload = async (
};
export const requestFileAdditionToCategory = async (fileId: number, categoryId: number) => {
const trpc = useTRPC();
try {
await trpc.category.addFile.mutate({ id: categoryId, file: fileId });
await trpc().category.addFile.mutate({ id: categoryId, file: fileId });
return true;
} catch {
// TODO: Error Handling

View File

@@ -1,14 +1,13 @@
import { error } from "@sveltejs/kit";
import { useTRPC } from "$trpc/client";
import { trpc } from "$trpc/client";
import type { PageLoad } from "./$types";
export const load: PageLoad = async ({ fetch }) => {
const trpc = useTRPC(fetch);
try {
const files = await trpc.file.listWithoutThumbnail.query();
const files = await trpc(fetch).file.listWithoutThumbnail.query();
return { files };
} catch {
// TODO: Error Handling
error(500, "Internal server error");
}
};

View File

@@ -1,7 +1,7 @@
import { getContext, setContext } from "svelte";
import { encryptString } from "$lib/modules/crypto";
import type { SelectedCategory } from "$lib/components/molecules";
import { useTRPC } from "$trpc/client";
import { trpc } from "$trpc/client";
export { requestCategoryCreation, requestFileRemovalFromCategory } from "$lib/services/category";
@@ -17,11 +17,10 @@ export const useContext = () => {
};
export const requestCategoryRename = async (category: SelectedCategory, newName: string) => {
const trpc = useTRPC();
const newNameEncrypted = await encryptString(newName, category.dataKey);
try {
await trpc.category.rename.mutate({
await trpc().category.rename.mutate({
id: category.id,
dekVersion: category.dataKeyVersion,
name: newNameEncrypted.ciphertext,
@@ -35,10 +34,8 @@ export const requestCategoryRename = async (category: SelectedCategory, newName:
};
export const requestCategoryDeletion = async (category: SelectedCategory) => {
const trpc = useTRPC();
try {
await trpc.category.delete.mutate({ id: category.id });
await trpc().category.delete.mutate({ id: category.id });
return true;
} catch {
// TODO: Error Handling

View File

@@ -9,7 +9,7 @@ import {
uploadFile,
} from "$lib/modules/file";
import { hmacSecretStore, type MasterKey, type HmacSecret } from "$lib/stores";
import { useTRPC } from "$trpc/client";
import { trpc } from "$trpc/client";
export interface SelectedEntry {
type: "directory" | "file";
@@ -33,11 +33,9 @@ export const useContext = () => {
export const requestHmacSecretDownload = async (masterKey: CryptoKey) => {
// TODO: MEK rotation
const trpc = useTRPC();
let hmacSecretsWrapped;
try {
hmacSecretsWrapped = await trpc.hsk.list.query();
hmacSecretsWrapped = await trpc().hsk.list.query();
} catch {
// TODO: Error Handling
return false;
@@ -61,12 +59,11 @@ export const requestDirectoryCreation = async (
parentId: "root" | number,
masterKey: MasterKey,
) => {
const trpc = useTRPC();
const { dataKey, dataKeyVersion } = await generateDataKey();
const nameEncrypted = await encryptString(name, dataKey);
try {
await trpc.directory.create.mutate({
await trpc().directory.create.mutate({
parent: parentId,
mekVersion: masterKey.version,
dek: await wrapDataKey(dataKey, masterKey.key),
@@ -100,19 +97,18 @@ export const requestFileUpload = async (
};
export const requestEntryRename = async (entry: SelectedEntry, newName: string) => {
const trpc = useTRPC();
const newNameEncrypted = await encryptString(newName, entry.dataKey);
try {
if (entry.type === "directory") {
await trpc.directory.rename.mutate({
await trpc().directory.rename.mutate({
id: entry.id,
dekVersion: entry.dataKeyVersion,
name: newNameEncrypted.ciphertext,
nameIv: newNameEncrypted.iv,
});
} else {
await trpc.file.rename.mutate({
await trpc().file.rename.mutate({
id: entry.id,
dekVersion: entry.dataKeyVersion,
name: newNameEncrypted.ciphertext,
@@ -127,11 +123,9 @@ export const requestEntryRename = async (entry: SelectedEntry, newName: string)
};
export const requestEntryDeletion = async (entry: SelectedEntry) => {
const trpc = useTRPC();
try {
if (entry.type === "directory") {
const { deletedFiles } = await trpc.directory.delete.mutate({ id: entry.id });
const { deletedFiles } = await trpc().directory.delete.mutate({ id: entry.id });
await Promise.all(
deletedFiles.flatMap((fileId) => [
deleteFileCache(fileId),
@@ -139,7 +133,7 @@ export const requestEntryDeletion = async (entry: SelectedEntry) => {
]),
);
} else {
await trpc.file.delete.mutate({ id: entry.id });
await trpc().file.delete.mutate({ id: entry.id });
await Promise.all([deleteFileCache(entry.id), deleteFileThumbnailCache(entry.id)]);
}
return true;

View File

@@ -1,14 +1,13 @@
import { error } from "@sveltejs/kit";
import { useTRPC } from "$trpc/client";
import { trpc } from "$trpc/client";
import type { PageLoad } from "./$types";
export const load: PageLoad = async ({ fetch }) => {
const trpc = useTRPC(fetch);
try {
const { nickname } = await trpc.user.get.query();
const { nickname } = await trpc(fetch).user.get.query();
return { nickname };
} catch {
// TODO: Error Handling
error(500, "Internal server error");
}
};