mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 08:06:56 +00:00
/api/hsk, /api/mek, /api/user 아래의 Endpoint들을 tRPC로 마이그레이션
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { getContext, setContext } from "svelte";
|
||||
import { callGetApi, callPostApi } from "$lib/hooks";
|
||||
import { callPostApi } from "$lib/hooks";
|
||||
import { storeHmacSecrets } from "$lib/indexedDB";
|
||||
import { generateDataKey, wrapDataKey, unwrapHmacSecret, encryptString } from "$lib/modules/crypto";
|
||||
import {
|
||||
@@ -13,10 +13,10 @@ import type {
|
||||
DirectoryRenameRequest,
|
||||
DirectoryCreateRequest,
|
||||
FileRenameRequest,
|
||||
HmacSecretListResponse,
|
||||
DirectoryDeleteResponse,
|
||||
} from "$lib/server/schemas";
|
||||
import { hmacSecretStore, type MasterKey, type HmacSecret } from "$lib/stores";
|
||||
import { useTRPC } from "$trpc/client";
|
||||
|
||||
export interface SelectedEntry {
|
||||
type: "directory" | "file";
|
||||
@@ -40,10 +40,16 @@ export const useContext = () => {
|
||||
export const requestHmacSecretDownload = async (masterKey: CryptoKey) => {
|
||||
// TODO: MEK rotation
|
||||
|
||||
const res = await callGetApi("/api/hsk/list");
|
||||
if (!res.ok) return false;
|
||||
const trpc = useTRPC();
|
||||
|
||||
let hmacSecretsWrapped;
|
||||
try {
|
||||
hmacSecretsWrapped = await trpc.hsk.list.query();
|
||||
} catch {
|
||||
// TODO: Error Handling
|
||||
return false;
|
||||
}
|
||||
|
||||
const { hsks: hmacSecretsWrapped }: HmacSecretListResponse = await res.json();
|
||||
const hmacSecrets = await Promise.all(
|
||||
hmacSecretsWrapped.map(async ({ version, state, hsk: hmacSecretWrapped }) => {
|
||||
const { hmacSecret } = await unwrapHmacSecret(hmacSecretWrapped, masterKey);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { error } from "@sveltejs/kit";
|
||||
import { callGetApi } from "$lib/hooks";
|
||||
import type { UserInfoResponse } from "$lib/server/schemas";
|
||||
import { useTRPC } from "$trpc/client";
|
||||
import type { PageLoad } from "./$types";
|
||||
|
||||
export const load: PageLoad = async ({ fetch }) => {
|
||||
const res = await callGetApi("/api/user", fetch);
|
||||
if (!res.ok) {
|
||||
const trpc = useTRPC(fetch);
|
||||
|
||||
try {
|
||||
const { nickname } = await trpc.user.info.query();
|
||||
return { nickname };
|
||||
} catch {
|
||||
error(500, "Internal server error");
|
||||
}
|
||||
|
||||
const { nickname }: UserInfoResponse = await res.json();
|
||||
return { nickname };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user