import { Database, type Model } from "@paulaboks/boksy"; import { DATABASE_PATH } from "@/src/server_constants.ts"; import type { PassphraseBackup } from "@/src/keys.ts"; export interface User extends Record { name: string; code: string; admin: boolean; key_check?: string; passphrase_backup?: PassphraseBackup; } export interface StoredFile extends Record { user_id: string; // Name of the encrypted file inside FILE_UPLOAD_PATH storage_id: string; // Size of the encrypted file size: number; // Encrypted by the client, holds the name, type and file key metadata: string; } export interface StoredShare extends Record { user_id: string; file_id: string; // The file metadata encrypted with the secret in the share link metadata: string; // The link secret encrypted with the owner's master key secret: string; } // boksy's partial entry types lose the field types export type FileRow = Model & StoredFile; export type ShareRow = Model & StoredShare; type Schema = { users: User; files: StoredFile; shares: StoredShare; }; export const db = await Database.open(DATABASE_PATH ?? ":memory:", { users: ["code"], files: ["user_id"], shares: ["user_id", "file_id"], });