mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 15:42:24 +00:00
feat(documents): search and import from Paperless-ngx and Papra on request
A person stores one connection per system (base address, Papra organization id, API token encrypted at rest) and can search it by document name with tag and date filters, then import picked documents one per request through the same ingest path as an upload: source-key answer before any download, content dedup, deleted stays deleted, quota, provenance, and the person's own AI reading setting. An import can link the document to the visit, condition or vaccination it was picked for. The operator lists the instances in DOCUMENT_SOURCE_ORIGINS; unset, the feature is off. Only listed origins are contacted, through safeFetch with the origin pinned, redirects refused, timeouts and byte caps. The routes are cookie-only and owner-only. The token is registered for rotation, removed by Delete all data, and not carried in backups.
This commit is contained in:
1 parent
89b18e001e
commit
fdc60f69c2
26 files changed
+2305
-1
No files matched your search
@@ -0,0 +1,22 @@
|
||||
-- Document picker (#1038). One connection per person per system (Paperless-ngx
|
||||
-- or Papra) with the API token encrypted at rest. The picker searches the
|
||||
-- source and imports picked documents on request only; nothing polls.
|
||||
CREATE TABLE "document_source_connections" (
|
||||
"id" TEXT NOT NULL,
|
||||
"user_id" TEXT NOT NULL,
|
||||
"system" VARCHAR(16) NOT NULL,
|
||||
"base_url" VARCHAR(2048) NOT NULL,
|
||||
"organization_id" VARCHAR(128),
|
||||
"token_encrypted" TEXT NOT NULL,
|
||||
"last_verified_at" TIMESTAMP(3),
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
CONSTRAINT "document_source_connections_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX "document_source_connections_user_id_system_key"
|
||||
ON "document_source_connections" ("user_id", "system");
|
||||
|
||||
ALTER TABLE "document_source_connections"
|
||||
ADD CONSTRAINT "document_source_connections_user_id_fkey"
|
||||
FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -928,6 +928,9 @@ model User {
|
||||
// v1.39.2 — further source keys an import answered with an existing
|
||||
// document (same bytes under another key). See DocumentSourceAlias.
|
||||
documentSourceAliases DocumentSourceAlias[]
|
||||
// v1.39.3 — the person's own connection to a Paperless-ngx or Papra
|
||||
// instance for the document picker. See DocumentSourceConnection.
|
||||
documentSourceConnections DocumentSourceConnection[]
|
||||
extractedFacts ExtractedFact[]
|
||||
documentConditionLinks DocumentConditionLink[]
|
||||
documentContentIndexes DocumentContentIndex[]
|
||||
@@ -8114,6 +8117,43 @@ model DocumentImportKey {
|
||||
@@map("document_import_keys")
|
||||
}
|
||||
|
||||
/// v1.39.3 (#1038) — one person's connection to a Paperless-ngx or Papra
|
||||
/// instance, used by the document picker to search that system by name, tag
|
||||
/// and date and import the documents the person picks. One per system per
|
||||
/// person. Only reachable when the operator lists the instance's origin in
|
||||
/// `DOCUMENT_SOURCE_ORIGINS`; the origin is re-checked on every request, so
|
||||
/// removing it from the list cuts the connection off without touching the
|
||||
/// row. No background job reads it: every request to the source is one the
|
||||
/// person started. Not carried in backups (a third-party credential for a
|
||||
/// service on the operator's network; see `NOT_IN_BACKUP_MODELS`); removed by
|
||||
/// Delete all data and with the account.
|
||||
model DocumentSourceConnection {
|
||||
id String @id @default(cuid())
|
||||
userId String @map("user_id")
|
||||
/// `PAPERLESS` | `PAPRA` (`DOCUMENT_PICKER_SYSTEMS` in
|
||||
/// `src/lib/documents/sources/types.ts`).
|
||||
system String @map("system") @db.VarChar(16)
|
||||
/// Base address of the instance, origin plus an optional path. Plaintext:
|
||||
/// its origin is compared with the operator's list on every use, and the
|
||||
/// settings card shows it. Not health data.
|
||||
baseUrl String @map("base_url") @db.VarChar(2048)
|
||||
/// Papra organization id; null for Paperless-ngx.
|
||||
organizationId String? @map("organization_id") @db.VarChar(128)
|
||||
/// The API token (Paperless-ngx) or API key (Papra), AES-256-GCM via
|
||||
/// `encrypt()`. No route returns it, in whole or in part.
|
||||
tokenEncrypted String @map("token_encrypted")
|
||||
/// Last time the source answered a test with this token: the save's live
|
||||
/// check or the settings card's Test button. Shown on the card.
|
||||
lastVerifiedAt DateTime? @map("last_verified_at")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([userId, system])
|
||||
@@map("document_source_connections")
|
||||
}
|
||||
|
||||
model ExtractedFact {
|
||||
id String @id @default(cuid())
|
||||
documentId String @map("document_id")
|
||||
|
||||
Reference in new issue
Block a user