File sharing
This commit is contained in:
+17
-4
@@ -1,21 +1,34 @@
|
||||
import { Signal, useSignal, useSignalEffect } from "@preact/signals";
|
||||
|
||||
import HubFileList, { type HubFile } from "@/islands/HubFileList.tsx";
|
||||
import HubFileList, { type HubFile, type HubShare } from "@/islands/HubFileList.tsx";
|
||||
import HubUpload, { type UploadState } from "@/islands/HubUpload.tsx";
|
||||
import { post_json } from "@/src/client.ts";
|
||||
import { decrypt_metadata, encrypt_file } from "@/src/file_crypto.ts";
|
||||
import type { FileEntry } from "@/src/files.ts";
|
||||
import type { FileEntry, ShareEntry } from "@/src/files.ts";
|
||||
import { list_files, upload_file } from "@/src/files_api.ts";
|
||||
import { load_master_key } from "@/src/key_store.ts";
|
||||
import { type GetKeyResponse, verify_key_check } from "@/src/keys.ts";
|
||||
import { open_share_secret, share_link } from "@/src/share_crypto.ts";
|
||||
|
||||
function has_files(event: DragEvent) {
|
||||
return event.dataTransfer?.types.includes("Files") ?? false;
|
||||
}
|
||||
|
||||
async function to_hub_share(master_key: CryptoKey, share: ShareEntry): Promise<HubShare | null> {
|
||||
const link_secret = await open_share_secret(master_key, share.secret).catch(() => null);
|
||||
return link_secret ? { link: share_link(share.id, link_secret) } : null;
|
||||
}
|
||||
|
||||
async function to_hub_file(master_key: CryptoKey, entry: FileEntry): Promise<HubFile> {
|
||||
const metadata = await decrypt_metadata(master_key, entry.metadata).catch(() => null);
|
||||
return { id: entry.id, uploaded_at: entry.date_created, stored_size: entry.size, metadata };
|
||||
return {
|
||||
id: entry.id,
|
||||
uploaded_at: entry.date_created,
|
||||
stored_size: entry.size,
|
||||
encrypted_metadata: entry.metadata,
|
||||
metadata,
|
||||
share: entry.share && await to_hub_share(master_key, entry.share),
|
||||
};
|
||||
}
|
||||
|
||||
interface HubProps {
|
||||
@@ -161,7 +174,7 @@ export default function Hub(props: HubProps) {
|
||||
/>
|
||||
</div>
|
||||
<div class="flex min-h-0 flex-col md:w-1/2">
|
||||
<HubFileList files={files} />
|
||||
<HubFileList files={files} master_key={master_key.value} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user