Read a PDF where it is imported, and keep the text with the file
A PDF was searchable on a device once that device had opened it, because the extracted text lived in that browser's IndexedDB and nowhere else. So a document imported on the desktop was invisible to a search on the phone — which is exactly the case that matters for filing invoices, since those are imported and then never opened again. The reading still never happens on the server. It has no PDF library and is not getting one: the bytes arrive encrypted and are stored that way. The device that imports the file reads it there and then, and the result is stored beside the file in attachments.text_index, encrypted at rest like everything else and opaque to the server. Every other device asks for it after login and can then find a document it has never downloaded. Not storing it was the earlier decision, on the reasoning that text derivable from bytes the server already holds should not be kept twice. True, and useless. A few hundred kilobytes against a file measured in megabytes is a trade worth making. A `null` answer is not an error — it means nobody has read this file yet. Documents extracted before this existed are sent up the next time they are opened. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
228552d453
commit
8e38404a69
8 files changed
+268
-23
No files matched your search
@@ -1127,6 +1127,22 @@ export async function loadPdfBytes(attachmentId: string): Promise<Uint8Array> {
|
||||
return new Uint8Array(await blob.arrayBuffer());
|
||||
}
|
||||
|
||||
/* ─── The text inside a PDF ───
|
||||
*
|
||||
* Read on a device, stored with the file, handed to every other device. The
|
||||
* server never opens a PDF; it keeps this the way it keeps a note body —
|
||||
* encrypted, and unread by it. */
|
||||
|
||||
/** The stored text of a PDF, page by page, or null if nobody has read it yet. */
|
||||
export async function fetchPdfText(attachmentId: string): Promise<string[] | null> {
|
||||
const r = await api.get<{ pages: string[] | null }>(`/attachments/${attachmentId}/text`);
|
||||
return r.pages ?? null;
|
||||
}
|
||||
|
||||
export async function storePdfText(attachmentId: string, pages: string[]): Promise<void> {
|
||||
await api.put(`/attachments/${attachmentId}/text`, { pages });
|
||||
}
|
||||
|
||||
/** Creates a note that holds a PDF. */
|
||||
export async function createPdfNote(
|
||||
folderId: string | null,
|
||||
|
||||
Reference in new issue
Block a user