openreader/src/types/documents.ts
Richard R 936aa50f9a refactor(api): remove all legacy unclaimed user scope logic and enforce strict userId scoping
Eliminate all code, tests, and utilities related to the legacy 'unclaimed' user
scope. All API endpoints, document and audiobook storage, and access logic now
require a valid authenticated userId and only operate on resources owned by that
user. Remove related helper functions, test cases, and conditional flows for
anonymous/unclaimed data. Update types, client APIs, and UI logic to reflect
that only 'user' scope is supported. This simplifies ownership checks and
removes ambiguity around document and audiobook access.
2026-05-31 13:01:55 -06:00

87 lines
2.1 KiB
TypeScript

export type DocumentType = 'pdf' | 'epub' | 'docx' | 'html';
export interface BaseDocument {
id: string;
name: string;
size: number;
lastModified: number;
recentlyOpenedAt?: number;
type: DocumentType;
parseStatus?: 'pending' | 'running' | 'ready' | 'failed' | null;
parsedJsonKey?: string | null;
scope?: 'user';
folderId?: string;
isConverting?: boolean;
}
export interface PDFDocument extends BaseDocument {
type: 'pdf';
data: ArrayBuffer;
}
export interface HTMLDocument extends BaseDocument {
type: 'html';
data: string; // Store as string since it's text content
}
export interface EPUBDocument extends BaseDocument {
type: 'epub';
data: ArrayBuffer;
}
export interface DOCXDocument extends BaseDocument {
type: 'docx';
data: ArrayBuffer;
}
export type AnyDocument =
| PDFDocument
| EPUBDocument
| HTMLDocument
| DOCXDocument;
export type BinaryDocument = PDFDocument | EPUBDocument | DOCXDocument;
// Representation used when syncing binary documents to/from the server.
// Data is converted from ArrayBuffer to a numeric array for JSON transport.
export interface SyncedDocument extends BaseDocument {
data: number[];
}
export interface DocumentListDocument extends BaseDocument {
type: DocumentType;
}
export interface Folder {
id: string;
name: string;
documents: DocumentListDocument[];
}
export type SortBy = 'name' | 'type' | 'date' | 'size';
export type SortDirection = 'asc' | 'desc';
export type ViewMode = 'icons' | 'list' | 'gallery';
export type IconSize = 'sm' | 'md' | 'lg' | 'xl';
// Filter applied from the sidebar.
// Examples: 'all', 'recents', 'pdf', 'epub', 'html', or `folder:<folderId>`.
export type SidebarFilter = string;
export interface DocumentListState {
sortBy: SortBy;
sortDirection: SortDirection;
folders: Folder[];
collapsedFolders: string[];
showHint: boolean;
viewMode?: ViewMode | 'grid';
iconSize?: IconSize;
sidebarWidth?: number;
sidebarFilter?: SidebarFilter;
sidebarCollapsed?: boolean;
}
export interface LibraryDocument extends BaseDocument {
// `id` is a stable server-provided reference, not necessarily the same as the local document id.
id: string;
}