mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 08:06:56 +00:00
사소한 리팩토링 2
This commit is contained in:
@@ -23,15 +23,14 @@ import {
|
||||
type HmacSecret,
|
||||
type FileUploadStatus,
|
||||
} from "$lib/stores";
|
||||
import { useTRPC } from "$trpc/client";
|
||||
import { trpc } from "$trpc/client";
|
||||
|
||||
const requestDuplicateFileScan = limitFunction(
|
||||
async (file: File, hmacSecret: HmacSecret, onDuplicate: () => Promise<boolean>) => {
|
||||
const trpc = useTRPC();
|
||||
const fileBuffer = await file.arrayBuffer();
|
||||
const fileSigned = encodeToBase64(await signMessageHmac(fileBuffer, hmacSecret.secret));
|
||||
|
||||
const files = await trpc.file.listByHash.query({
|
||||
const files = await trpc().file.listByHash.query({
|
||||
hskVersion: hmacSecret.version,
|
||||
contentHmac: fileSigned,
|
||||
});
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
type CategoryId,
|
||||
} from "$lib/indexedDB";
|
||||
import { unwrapDataKey, decryptString } from "$lib/modules/crypto";
|
||||
import { useTRPC } from "$trpc/client";
|
||||
import { trpc } from "$trpc/client";
|
||||
|
||||
export type DirectoryInfo =
|
||||
| {
|
||||
@@ -101,10 +101,9 @@ const fetchDirectoryInfoFromServer = async (
|
||||
info: Writable<DirectoryInfo | null>,
|
||||
masterKey: CryptoKey,
|
||||
) => {
|
||||
const trpc = useTRPC();
|
||||
let data;
|
||||
try {
|
||||
data = await trpc.directory.get.query({ id });
|
||||
data = await trpc().directory.get.query({ id });
|
||||
} catch (e) {
|
||||
if (e instanceof TRPCClientError && e.data?.code === "NOT_FOUND") {
|
||||
info.set(null);
|
||||
@@ -174,10 +173,9 @@ const fetchFileInfoFromServer = async (
|
||||
info: Writable<FileInfo | null>,
|
||||
masterKey: CryptoKey,
|
||||
) => {
|
||||
const trpc = useTRPC();
|
||||
let metadata;
|
||||
try {
|
||||
metadata = await trpc.file.get.query({ id });
|
||||
metadata = await trpc().file.get.query({ id });
|
||||
} catch (e) {
|
||||
if (e instanceof TRPCClientError && e.data?.code === "NOT_FOUND") {
|
||||
info.set(null);
|
||||
@@ -270,10 +268,9 @@ const fetchCategoryInfoFromServer = async (
|
||||
info: Writable<CategoryInfo | null>,
|
||||
masterKey: CryptoKey,
|
||||
) => {
|
||||
const trpc = useTRPC();
|
||||
let data;
|
||||
try {
|
||||
data = await trpc.category.get.query({ id });
|
||||
data = await trpc().category.get.query({ id });
|
||||
} catch (e) {
|
||||
if (e instanceof TRPCClientError && e.data?.code === "NOT_FOUND") {
|
||||
info.set(null);
|
||||
@@ -293,7 +290,7 @@ const fetchCategoryInfoFromServer = async (
|
||||
|
||||
let files;
|
||||
try {
|
||||
files = await trpc.category.files.query({ id, recurse: true });
|
||||
files = await trpc().category.files.query({ id, recurse: true });
|
||||
} catch {
|
||||
throw new Error("Failed to fetch category files");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { TRPCClientError } from "@trpc/client";
|
||||
import { encodeToBase64, decryptChallenge, signMessageRSA } from "$lib/modules/crypto";
|
||||
import { useTRPC } from "$trpc/client";
|
||||
import { trpc } from "$trpc/client";
|
||||
|
||||
export const requestSessionUpgrade = async (
|
||||
encryptKeyBase64: string,
|
||||
@@ -9,10 +9,9 @@ export const requestSessionUpgrade = async (
|
||||
signKey: CryptoKey,
|
||||
force = false,
|
||||
) => {
|
||||
const trpc = useTRPC();
|
||||
let id, challenge;
|
||||
try {
|
||||
({ id, challenge } = await trpc.auth.upgrade.mutate({
|
||||
({ id, challenge } = await trpc().auth.upgrade.mutate({
|
||||
encPubKey: encryptKeyBase64,
|
||||
sigPubKey: verifyKeyBase64,
|
||||
}));
|
||||
@@ -26,7 +25,7 @@ export const requestSessionUpgrade = async (
|
||||
const answerSig = await signMessageRSA(answer, signKey);
|
||||
|
||||
try {
|
||||
await trpc.auth.verifyUpgrade.mutate({
|
||||
await trpc().auth.verifyUpgrade.mutate({
|
||||
id,
|
||||
answerSig: encodeToBase64(answerSig),
|
||||
force,
|
||||
@@ -42,9 +41,8 @@ export const requestSessionUpgrade = async (
|
||||
};
|
||||
|
||||
export const requestLogout = async () => {
|
||||
const trpc = useTRPC();
|
||||
try {
|
||||
await trpc.auth.logout.mutate();
|
||||
await trpc().auth.logout.mutate();
|
||||
return true;
|
||||
} catch {
|
||||
// TODO: Error Handling
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
import { generateDataKey, wrapDataKey, encryptString } from "$lib/modules/crypto";
|
||||
import type { MasterKey } from "$lib/stores";
|
||||
import { useTRPC } from "$trpc/client";
|
||||
import { trpc } from "$trpc/client";
|
||||
|
||||
export const requestCategoryCreation = async (
|
||||
name: string,
|
||||
parentId: "root" | number,
|
||||
masterKey: MasterKey,
|
||||
) => {
|
||||
const trpc = useTRPC();
|
||||
const { dataKey, dataKeyVersion } = await generateDataKey();
|
||||
const nameEncrypted = await encryptString(name, dataKey);
|
||||
|
||||
try {
|
||||
await trpc.category.create.mutate({
|
||||
await trpc().category.create.mutate({
|
||||
parent: parentId,
|
||||
mekVersion: masterKey.version,
|
||||
dek: await wrapDataKey(dataKey, masterKey.key),
|
||||
@@ -28,10 +27,9 @@ export const requestCategoryCreation = async (
|
||||
};
|
||||
|
||||
export const requestFileRemovalFromCategory = async (fileId: number, categoryId: number) => {
|
||||
const trpc = useTRPC();
|
||||
|
||||
try {
|
||||
await trpc.category.removeFile.mutate({ id: categoryId, file: fileId });
|
||||
await trpc().category.removeFile.mutate({ id: categoryId, file: fileId });
|
||||
return true;
|
||||
} catch {
|
||||
// TODO: Error Handling
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
} from "$lib/modules/file";
|
||||
import { getThumbnailUrl } from "$lib/modules/thumbnail";
|
||||
import type { FileThumbnailUploadRequest } from "$lib/server/schemas";
|
||||
import { useTRPC } from "$trpc/client";
|
||||
import { trpc } from "$trpc/client";
|
||||
|
||||
export const requestFileDownload = async (
|
||||
fileId: number,
|
||||
@@ -49,10 +49,9 @@ export const requestFileThumbnailDownload = async (fileId: number, dataKey?: Cry
|
||||
const cache = await getFileThumbnailCache(fileId);
|
||||
if (cache || !dataKey) return cache;
|
||||
|
||||
const trpc = useTRPC();
|
||||
let thumbnailInfo;
|
||||
try {
|
||||
thumbnailInfo = await trpc.file.thumbnail.query({ id: fileId });
|
||||
thumbnailInfo = await trpc().file.thumbnail.query({ id: fileId });
|
||||
} catch {
|
||||
// TODO: Error Handling
|
||||
return null;
|
||||
@@ -70,10 +69,9 @@ export const requestFileThumbnailDownload = async (fileId: number, dataKey?: Cry
|
||||
};
|
||||
|
||||
export const requestDeletedFilesCleanup = async () => {
|
||||
const trpc = useTRPC();
|
||||
let liveFiles;
|
||||
try {
|
||||
liveFiles = await trpc.file.list.query();
|
||||
liveFiles = await trpc().file.list.query();
|
||||
} catch {
|
||||
// TODO: Error Handling
|
||||
return;
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
} from "$lib/modules/crypto";
|
||||
import { requestSessionUpgrade } from "$lib/services/auth";
|
||||
import { masterKeyStore, type ClientKeys } from "$lib/stores";
|
||||
import { useTRPC } from "$trpc/client";
|
||||
import { trpc } from "$trpc/client";
|
||||
|
||||
export const requestClientRegistration = async (
|
||||
encryptKeyBase64: string,
|
||||
@@ -19,16 +19,14 @@ export const requestClientRegistration = async (
|
||||
verifyKeyBase64: string,
|
||||
signKey: CryptoKey,
|
||||
) => {
|
||||
const trpc = useTRPC();
|
||||
|
||||
try {
|
||||
const { id, challenge } = await trpc.client.register.mutate({
|
||||
const { id, challenge } = await trpc().client.register.mutate({
|
||||
encPubKey: encryptKeyBase64,
|
||||
sigPubKey: verifyKeyBase64,
|
||||
});
|
||||
const answer = await decryptChallenge(challenge, decryptKey);
|
||||
const answerSig = await signMessageRSA(answer, signKey);
|
||||
await trpc.client.verify.mutate({
|
||||
await trpc().client.verify.mutate({
|
||||
id,
|
||||
answerSig: encodeToBase64(answerSig),
|
||||
});
|
||||
@@ -69,11 +67,9 @@ export const requestClientRegistrationAndSessionUpgrade = async (
|
||||
};
|
||||
|
||||
export const requestMasterKeyDownload = async (decryptKey: CryptoKey, verifyKey: CryptoKey) => {
|
||||
const trpc = useTRPC();
|
||||
|
||||
let masterKeysWrapped;
|
||||
try {
|
||||
masterKeysWrapped = await trpc.mek.list.query();
|
||||
masterKeysWrapped = await trpc().mek.list.query();
|
||||
} catch {
|
||||
// TODO: Error Handling
|
||||
return false;
|
||||
@@ -110,10 +106,8 @@ export const requestInitialMasterKeyAndHmacSecretRegistration = async (
|
||||
hmacSecretWrapped: string,
|
||||
signKey: CryptoKey,
|
||||
) => {
|
||||
const trpc = useTRPC();
|
||||
|
||||
try {
|
||||
await trpc.mek.registerInitial.mutate({
|
||||
await trpc().mek.registerInitial.mutate({
|
||||
mek: masterKeyWrapped,
|
||||
mekSig: await signMasterKeyWrapped(masterKeyWrapped, 1, signKey),
|
||||
});
|
||||
@@ -129,7 +123,7 @@ export const requestInitialMasterKeyAndHmacSecretRegistration = async (
|
||||
}
|
||||
|
||||
try {
|
||||
await trpc.hsk.registerInitial.mutate({
|
||||
await trpc().hsk.registerInitial.mutate({
|
||||
mekVersion: 1,
|
||||
hsk: hmacSecretWrapped,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user