Files
vces/src/db.ts
T
2026-10-29 20:44:26 -03:00

48 lines
1.2 KiB
TypeScript

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<string, unknown> {
name: string;
code: string;
admin: boolean;
key_check?: string;
passphrase_backup?: PassphraseBackup;
}
export interface StoredFile extends Record<string, unknown> {
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<string, unknown> {
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<Schema>(DATABASE_PATH ?? ":memory:", {
users: ["code"],
files: ["user_id"],
shares: ["user_id", "file_id"],
});