-
-
Folders
-
-
-
-
-
-
+ {#if $userBlobsQuery.isLoading}
+
+ {:else if $userBlobsQuery.isError}
+
+
+ Failed to Load
-
-
-
-
-
-
-
-
+
+ {#each $userBlobsQuery.data! as file (file.id)}
+
+ {/each}
+
+ {/if}
diff --git a/src/routes/(app)/uploadFileFAB.svelte b/src/routes/(app)/uploadFileFAB.svelte
index dd7f1ff..6911fb6 100644
--- a/src/routes/(app)/uploadFileFAB.svelte
+++ b/src/routes/(app)/uploadFileFAB.svelte
@@ -30,6 +30,7 @@
import { filesize } from "filesize";
const rpc = trpc($page);
+ const utils = rpc.createUtils();
let dialogOpen = $state(false);
@@ -47,10 +48,12 @@
if (file_element) file_element.value = "";
keyToUse = "";
isUploading = false;
+
+ utils.user.fetchUploadedFileMetadata.refetch();
};
const startEverythingMutation =
- rpc.keyManagement.uploadSymmetricKeyAndCreateEmptyBlob.createMutation();
+ rpc.blobManagement.uploadSymmetricKeyAndCreateEmptyBlob.createMutation();
let keyList: ReturnType
[] = $state([]);
@@ -59,39 +62,48 @@
isUploading = true;
- console.group("Uploading Blob");
- console.log("generating key");
-
- const generated_key = await generate_symmetrical_key();
- const wrapping_key = await import_public_key(keyToUse);
-
- const wrapped_key = await wrap_symmetrical_key(
- wrapping_key,
- generated_key,
- );
- const iv = window.crypto.getRandomValues(new Uint8Array(96));
-
- console.log("uploading sym key");
-
- const file_id = await $startEverythingMutation.mutateAsync({
- file_name: file.name,
- key_b64: btoa(String.fromCharCode(...new Uint8Array(wrapped_key))),
- iv_b64: btoa(String.fromCharCode(...new Uint8Array(iv))),
- pubkey: keyToUse,
- });
-
- console.log("encrypting and uploading call");
-
- const encryped_size = await encryptAndUpload(
- iv,
- generated_key,
- file_id,
- );
+ try {
+ console.group("Uploading Blob");
+ console.log("generating key");
+
+ const generated_key = await generate_symmetrical_key();
+ const wrapping_key = await import_public_key(keyToUse);
+
+ const wrapped_key = await wrap_symmetrical_key(
+ wrapping_key,
+ generated_key,
+ );
+ const iv = window.crypto.getRandomValues(new Uint8Array(96));
+
+ console.log("uploading sym key");
+
+ const file_id = await $startEverythingMutation.mutateAsync({
+ file_name: file.name,
+ key_b64: btoa(
+ String.fromCharCode(...new Uint8Array(wrapped_key)),
+ ),
+ iv_b64: btoa(String.fromCharCode(...new Uint8Array(iv))),
+ pubkey: keyToUse,
+ });
+
+ console.log("encrypting and uploading call");
+
+ const encryped_size = await encryptAndUpload(
+ iv,
+ generated_key,
+ file_id,
+ );
+
+ toast.success(
+ `Uploaded file ${file.name} (${filesize(encryped_size)})`,
+ );
+ closeAndReset();
+ } catch (e) {
+ console.error(e);
+ toast.error("failed to upload file");
+ }
- toast.success(
- `Uploaded file ${file.name} (${filesize(encryped_size)})`,
- );
- closeAndReset();
+ console.groupEnd();
};
const encryptAndUpload = async (
@@ -137,8 +149,6 @@
console.info("uploaded success");
}
- console.groupEnd();
-
return encrypted_size;
};
diff --git a/src/routes/api/blobs/[blob_id]/+server.ts b/src/routes/api/blobs/[blob_id]/+server.ts
index 9a758a5..04ab413 100644
--- a/src/routes/api/blobs/[blob_id]/+server.ts
+++ b/src/routes/api/blobs/[blob_id]/+server.ts
@@ -76,3 +76,40 @@ export const POST = (async ({ params, locals, request }: RequestEvent) => {
});
}
}) satisfies RequestHandler;
+
+/**
+ * Since the blobs are encrypted, we don't really care about trying to protect them
+ *
+ * So we'll just make sure the user is logged in
+ */
+export const GET = (async ({ params, locals }: RequestEvent) => {
+ const { blob_id } = params;
+
+ if (!ULID_SCHEMA.safeParse(blob_id).success) {
+ return new Response(null, {
+ status: 400,
+ });
+ }
+
+ if (!(locals.session && locals.user)) {
+ return new Response(null, {
+ status: 401,
+ });
+ }
+
+ const result = await DB.select({
+ blob: encryptedBlobTable.blob,
+ })
+ .from(encryptedBlobTable)
+ .where(eq(encryptedBlobTable.kid, blob_id));
+
+ if (result.length === 1) {
+ return new Response(result[0].blob as Blob, {
+ status: 200,
+ });
+ } else {
+ return new Response(null, {
+ status: 404,
+ });
+ }
+}) satisfies RequestHandler;