Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

feat(documents): add notes to documents (#1133)

Corentin Thomasseta0f24554d549
diff --git a/.changeset/mighty-wasps-stop.md b/.changeset/mighty-wasps-stop.md
new file mode 100644
index 00000000..9b767808
--- /dev/null
+++ b/.changeset/mighty-wasps-stop.md
@@ -0,0 +1,5 @@
+---
+"@papra/app": patch
+---
+
+Added the possibility to add notes to documents, which can be used to add additional information or context to a document.
diff --git a/apps/papra-client/src/locales/en.dictionary.ts b/apps/papra-client/src/locales/en.dictionary.ts
index 4b5f1b73..9b987d42 100644
--- a/apps/papra-client/src/locales/en.dictionary.ts
+++ b/apps/papra-client/src/locales/en.dictionary.ts
@@ -369,6 +369,11 @@ export const translations = {
'documents.info.document-date': 'Date',
'documents.info.no-date': 'No date',
'documents.info.today': 'Today',
+ 'documents.notes.label': 'Notes',
+ 'documents.notes.placeholder': 'Add some notes about this document',
+ 'documents.notes.saving': 'Saving',
+ 'documents.notes.saved': 'Saved',
+ 'documents.notes.save-error': 'Failed to save notes',
'custom-properties.types.text': 'Text',
'custom-properties.types.number': 'Number',
diff --git a/apps/papra-client/src/modules/demo/demo-api-mock.ts b/apps/papra-client/src/modules/demo/demo-api-mock.ts
index 72b8d52f..91696d43 100644
--- a/apps/papra-client/src/modules/demo/demo-api-mock.ts
+++ b/apps/papra-client/src/modules/demo/demo-api-mock.ts
@@ -1002,13 +1002,14 @@ const inMemoryApiMock: Record<string, { handler: any }> = {
assert(document, { status: 404 });
- const { name, content, documentDate } = body as { name?: string; content?: string; documentDate?: string };
+ const { name, content, documentDate, notes } = body as { name?: string; content?: string; documentDate?: string; notes?: string };
const newDocument = {
...document,
...(name !== undefined && { name }),
...(content !== undefined && { content }),
...(documentDate !== undefined && { documentDate: documentDate === null ? null : new Date(documentDate) }),
+ ...(notes !== undefined && { notes }),
updatedAt: new Date(),
};
diff --git a/apps/papra-client/src/modules/documents/documents.services.ts b/apps/papra-client/src/modules/documents/documents.services.ts
index 0b8ab996..ca231597 100644
--- a/apps/papra-client/src/modules/documents/documents.services.ts
+++ b/apps/papra-client/src/modules/documents/documents.services.ts
@@ -184,18 +184,20 @@ export async function updateDocument({
organizationId,
content,
name,
+ notes,
documentDate,
}: {
documentId: string;
organizationId: string;
content?: string;
name?: string;
+ notes?: string;
documentDate?: Date | null;
}) {
const { document } = await apiClient<{ document: AsDto<Document> }>({
method: 'PATCH',
path: `/api/organizations/${organizationId}/documents/${documentId}`,
- body: { content, name, documentDate },
+ body: { content, name, documentDate, notes },
});
return {
diff --git a/apps/papra-client/src/modules/documents/documents.types.ts b/apps/papra-client/src/modules/documents/documents.types.ts
index fddae0f3..a7fdd088 100644
--- a/apps/papra-client/src/modules/documents/documents.types.ts
+++ b/apps/papra-client/src/modules/documents/documents.types.ts
@@ -16,6 +16,7 @@ export type Document = {
deletedAt?: Date;
deletedBy?: string;
content: string;
+ notes?: string;
tags: Tag[];
customProperties?: DocumentCustomProperty[];
};
diff --git a/apps/papra-client/src/modules/documents/pages/document.page.tsx b/apps/papra-client/src/modules/documents/pages/document.page.tsx
index bc8d081a..0605c544 100644
--- a/apps/papra-client/src/modules/documents/pages/document.page.tsx
+++ b/apps/papra-client/src/modules/documents/pages/document.page.tsx
@@ -3,21 +3,25 @@ import type { Component, JSX } from 'solid-js';
import type { Document, DocumentActivity } from '../documents.types';
import { formatBytes } from '@corentinth/chisels';
import { A, useNavigate, useParams, useSearchParams } from '@solidjs/router';
-import { useInfiniteQuery, useQuery } from '@tanstack/solid-query';
-import { createEffect, createSignal, For, Match, Show, Suspense, Switch } from 'solid-js';
+import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/solid-query';
+import { createEffect, createSignal, For, Match, onCleanup, Show, Suspense, Switch } from 'solid-js';
import { useConfig } from '@/modules/config/config.provider';
import { DocumentCustomPropertiesPanel } from '@/modules/custom-properties/components/document-custom-properties-panel.component';
import { fetchCustomPropertyDefinitions } from '@/modules/custom-properties/custom-properties.services';
import { useShareDocumentDialog } from '@/modules/document-share-links/components/share-document-dialog.component';
import { RelativeTime } from '@/modules/i18n/components/RelativeTime';
import { useI18n } from '@/modules/i18n/i18n.provider';
+import { debounce } from '@/modules/shared/utils/timing';
import { DocumentTagsList } from '@/modules/tags/components/tag-list.component';
import { TagLink } from '@/modules/tags/components/tag.component';
import { Alert } from '@/modules/ui/components/alert';
import { Button } from '@/modules/ui/components/button';
import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from '@/modules/ui/components/dropdown-menu';
import { Separator } from '@/modules/ui/components/separator';
+import { createToast } from '@/modules/ui/components/sonner';
import { Tabs, TabsContent, TabsIndicator, TabsList, TabsTrigger } from '@/modules/ui/components/tabs';
+import { TextArea } from '@/modules/ui/components/textarea';
+import { TextFieldLabel, TextFieldRoot } from '@/modules/ui/components/textfield';
import { DocumentContentEditionPanel } from '../components/document-content-edition-panel.component';
import { DocumentDatePicker } from '../components/document-date-picker.component';
import { DocumentPreview } from '../components/document-preview.component';
@@ -25,7 +29,7 @@ import { DocumentOpenWithDropdownItems } from '../components/open-with.component
import { useRenameDocumentDialog } from '../components/rename-document-button.component';
import { getDaysBeforePermanentDeletion, getDocumentActivityIcon, getDocumentOpenWithApps } from '../document.models';
import { useDeleteDocument, useDownloadDocument, useRestoreDocument } from '../documents.composables';
-import { fetchDocument, fetchDocumentActivities } from '../documents.services';
+import { fetchDocument, fetchDocumentActivities, updateDocument } from '../documents.services';
type KeyValueItem = {
label: string | JSX.Element;
@@ -33,6 +37,86 @@ type KeyValueItem = {
icon?: string;
};
+const DocumentNotes: Component<{ documentId: string; organizationId: string; notes?: string }> = (props) => {
+ const { t } = useI18n();
+ const queryClient = useQueryClient();
+ const [notes, setNotes] = createSignal(props.notes ?? '');
+ const [getStatus, setStatus] = createSignal<'idle' | 'pending' | 'saved'>('idle');
+ const [getIsSavedVisible, setIsSavedVisible] = createSignal(false);
+
+ let fadeTimeout: ReturnType<typeof setTimeout> | undefined;
+ onCleanup(() => clearTimeout(fadeTimeout));
+
+ const updateNotesMutation = useMutation(() => ({
+ mutationFn: ({ notes }: { notes: string }) => updateDocument({
+ documentId: props.documentId,
+ organizationId: props.organizationId,
+ notes,
+ }),
+ onSuccess: () => {
+ setStatus('saved');
+ setIsSavedVisible(true);
+
+ clearTimeout(fadeTimeout);
+ fadeTimeout = setTimeout(() => setIsSavedVisible(false), 2000);
+
+ queryClient.invalidateQueries({
+ queryKey: ['organizations', props.organizationId, 'documents', props.documentId],
+ exact: true, // To avoid refetching the document file content
+ });
+ },
+ onError: () => {
+ setStatus('idle');
+ createToast({ type: 'error', message: t('documents.notes.save-error') });
+ },
+ }));
+
+ const debouncedSave = debounce((value: string) => updateNotesMutation.mutate({ notes: value }), 500);
+
+ const handleInput = (value: string) => {
+ setNotes(value);
+ setStatus('pending');
+ debouncedSave(value);
+ };
+
+ return (
+ <div>
+ <Separator class="mb-3" />
+ <TextFieldRoot>
+ <TextFieldLabel class="text-xs font-medium text-muted-foreground mb-2 uppercase tracking-wide flex items-center gap-2">
+ {t('documents.notes.label')}
+
+ <Switch>
+ <Match when={getStatus() === 'pending'}>
+ <span class="flex items-center gap-1 normal-case tracking-normal">
+ <div class="i-tabler-loader-2 size-3 animate-spin" />
+ {t('documents.notes.saving')}
+ </span>
+ </Match>
+ <Match when={getStatus() === 'saved'}>
+ <span
+ class="flex items-center gap-1 normal-case tracking-normal text-primary transition-opacity duration-1000"
+ classList={{ 'opacity-0': !getIsSavedVisible() }}
+ >
+ <div class="i-tabler-check size-3" />
+ {t('documents.notes.saved')}
+ </span>
+ </Match>
+ </Switch>
+ </TextFieldLabel>
+
+ <TextArea
+ rows={2}
+ autoResize
+ value={notes()}
+ onInput={e => handleInput(e.currentTarget.value)}
+ placeholder={t('documents.notes.placeholder')}
+ />
+ </TextFieldRoot>
+ </div>
+ );
+};
+
const KeyValues: Component<{ data?: KeyValueItem[] }> = (props) => {
return (
<For each={props.data}>
@@ -365,7 +449,13 @@ export const DocumentPage: Component = () => {
/>
)}
</Show>
+
</div>
+ <DocumentNotes
+ documentId={getDocument().id}
+ organizationId={params.organizationId}
+ notes={getDocument().notes}
+ />
</TabsContent>
<TabsContent value="content">
diff --git a/apps/papra-server/src/migrations/list/0022-documents-notes.migration.ts b/apps/papra-server/src/migrations/list/0022-documents-notes.migration.ts
new file mode 100644
index 00000000..f9da90eb
--- /dev/null
+++ b/apps/papra-server/src/migrations/list/0022-documents-notes.migration.ts
@@ -0,0 +1,20 @@
+import type { Migration } from '../migrations.types';
+import { sql } from 'drizzle-orm';
+import { getRuntimeTableColumns } from '../../modules/app/database/database.usecases';
+
+export const documentsNotesMigration = {
+ name: 'documents-notes',
+
+ up: async ({ db }) => {
+ const existingColumns = await getRuntimeTableColumns({ tableName: 'documents', db });
+ const hasColumn = (columnName: string) => existingColumns.includes(columnName);
+
+ if (!hasColumn('notes')) {
+ await db.run(sql`ALTER TABLE documents ADD COLUMN notes TEXT`);
+ }
+ },
+
+ down: async ({ db }) => {
+ await db.run(sql`ALTER TABLE documents DROP COLUMN notes`);
+ },
+} satisfies Migration;
diff --git a/apps/papra-server/src/migrations/migrations.registry.test.ts b/apps/papra-server/src/migrations/migrations.registry.test.ts
index bf4f6328..dfb58606 100644
--- a/apps/papra-server/src/migrations/migrations.registry.test.ts
+++ b/apps/papra-server/src/migrations/migrations.registry.test.ts
@@ -117,7 +117,7 @@ describe('migrations registry', () => {
CREATE TABLE "document_activity_log" ( "id" text PRIMARY KEY NOT NULL, "created_at" integer NOT NULL, "document_id" text NOT NULL, "event" text NOT NULL, "event_data" text, "user_id" text, "tag_id" text, FOREIGN KEY ("document_id") REFERENCES "documents"("id") ON UPDATE cascade ON DELETE cascade, FOREIGN KEY ("user_id") REFERENCES "users"("id") ON UPDATE cascade ON DELETE set null, FOREIGN KEY ("tag_id") REFERENCES "tags"("id") ON UPDATE cascade ON DELETE set null );
CREATE TABLE "document_custom_property_values" ( "id" text PRIMARY KEY NOT NULL, "created_at" integer NOT NULL, "updated_at" integer NOT NULL, "document_id" text NOT NULL REFERENCES "documents"("id") ON DELETE CASCADE ON UPDATE CASCADE, "property_definition_id" text NOT NULL REFERENCES "custom_property_definitions"("id") ON DELETE CASCADE ON UPDATE CASCADE, "text_value" text, "number_value" real, "date_value" integer, "boolean_value" integer, "select_option_id" text REFERENCES "custom_property_select_options"("id") ON DELETE CASCADE ON UPDATE CASCADE, "user_id" text REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE, "related_document_id" text REFERENCES "documents"("id") ON DELETE CASCADE ON UPDATE CASCADE );
CREATE TABLE "document_share_links" ( "id" text PRIMARY KEY NOT NULL, "created_at" integer NOT NULL, "updated_at" integer NOT NULL, "organization_id" text NOT NULL, "document_id" text NOT NULL, "created_by" text, "token" text NOT NULL, "expires_at" integer, "password_hash" text, "is_enabled" integer DEFAULT true NOT NULL, "last_accessed_at" integer, FOREIGN KEY ("organization_id") REFERENCES "organizations"("id") ON UPDATE cascade ON DELETE cascade, FOREIGN KEY ("document_id") REFERENCES "documents"("id") ON UPDATE cascade ON DELETE cascade, FOREIGN KEY ("created_by") REFERENCES "users"("id") ON UPDATE cascade ON DELETE set null );
- CREATE TABLE "documents" ( "id" text PRIMARY KEY NOT NULL, "created_at" integer NOT NULL, "updated_at" integer NOT NULL, "is_deleted" integer DEFAULT false NOT NULL, "deleted_at" integer, "organization_id" text NOT NULL, "created_by" text, "deleted_by" text, "original_name" text NOT NULL, "original_size" integer DEFAULT 0 NOT NULL, "original_storage_key" text NOT NULL, "original_sha256_hash" text NOT NULL, "name" text NOT NULL, "mime_type" text NOT NULL, "content" text DEFAULT '' NOT NULL, file_encryption_key_wrapped TEXT, file_encryption_kek_version TEXT, file_encryption_algorithm TEXT, document_date INTEGER, FOREIGN KEY ("organization_id") REFERENCES "organizations"("id") ON UPDATE cascade ON DELETE cascade, FOREIGN KEY ("created_by") REFERENCES "users"("id") ON UPDATE cascade ON DELETE set null, FOREIGN KEY ("deleted_by") REFERENCES "users"("id") ON UPDATE cascade ON DELETE set null );
+ CREATE TABLE "documents" ( "id" text PRIMARY KEY NOT NULL, "created_at" integer NOT NULL, "updated_at" integer NOT NULL, "is_deleted" integer DEFAULT false NOT NULL, "deleted_at" integer, "organization_id" text NOT NULL, "created_by" text, "deleted_by" text, "original_name" text NOT NULL, "original_size" integer DEFAULT 0 NOT NULL, "original_storage_key" text NOT NULL, "original_sha256_hash" text NOT NULL, "name" text NOT NULL, "mime_type" text NOT NULL, "content" text DEFAULT '' NOT NULL, file_encryption_key_wrapped TEXT, file_encryption_kek_version TEXT, file_encryption_algorithm TEXT, document_date INTEGER, notes TEXT, FOREIGN KEY ("organization_id") REFERENCES "organizations"("id") ON UPDATE cascade ON DELETE cascade, FOREIGN KEY ("created_by") REFERENCES "users"("id") ON UPDATE cascade ON DELETE set null, FOREIGN KEY ("deleted_by") REFERENCES "users"("id") ON UPDATE cascade ON DELETE set null );
CREATE VIRTUAL TABLE documents_fts USING fts5( document_id, organization_id, name, content, prefix='2 3 4' );
CREATE TABLE 'documents_fts_config'(k PRIMARY KEY, v) WITHOUT ROWID;
CREATE TABLE 'documents_fts_content'(id INTEGER PRIMARY KEY, c0, c1, c2, c3);
diff --git a/apps/papra-server/src/migrations/migrations.registry.ts b/apps/papra-server/src/migrations/migrations.registry.ts
index 946f2505..09ce8ccd 100644
--- a/apps/papra-server/src/migrations/migrations.registry.ts
+++ b/apps/papra-server/src/migrations/migrations.registry.ts
@@ -21,6 +21,7 @@ import { customPropertiesMigration } from './list/0018-custom-properties.migrati
import { twoFactorVerifiedMigration } from './list/0019-two-factor-verified.migration';
import { kvStoreMigration } from './list/0020-kv-store.migration';
import { documentShareLinksMigration } from './list/0021-document-share-links.migration';
+import { documentsNotesMigration } from './list/0022-documents-notes.migration';
export const migrations: Migration[] = [
initialSchemaSetupMigration,
@@ -44,4 +45,5 @@ export const migrations: Migration[] = [
twoFactorVerifiedMigration,
kvStoreMigration,
documentShareLinksMigration,
+ documentsNotesMigration,
];
diff --git a/apps/papra-server/src/modules/app/database/database.usecases.test.ts b/apps/papra-server/src/modules/app/database/database.usecases.test.ts
index 7df7908c..d28ca7dd 100644
--- a/apps/papra-server/src/modules/app/database/database.usecases.test.ts
+++ b/apps/papra-server/src/modules/app/database/database.usecases.test.ts
@@ -1,7 +1,8 @@
import { describe, expect, test } from 'vitest';
import { usersTable } from '../../users/users.table';
+import { setupDatabase } from './database';
import { createInMemoryDatabase } from './database.test-utils';
-import { createBatchedIterator, createIterator } from './database.usecases';
+import { createBatchedIterator, createIterator, getRuntimeTableColumns } from './database.usecases';
const createUsers = ({ count }: { count: number }) => Array.from({ length: count }, (_, i) => ({ id: `usr_${i}`, email: `user-${i}@papra.dev` }));
@@ -106,4 +107,20 @@ describe('database usecases', () => {
expect(results).to.eql([1, 2, 3, 4, 5, 6]);
});
});
+
+ describe('getRuntimeTableColumns', () => {
+ test('returns the list of columns for a given table', async () => {
+ const { db } = setupDatabase({ url: ':memory:' });
+
+ await db.run(`CREATE TABLE test_table (id INTEGER PRIMARY KEY, name TEXT)`);
+
+ expect(await getRuntimeTableColumns({ tableName: 'test_table', db })).to.eql(['id', 'name']);
+ });
+
+ test('returns an empty array for a non-existing table', async () => {
+ const { db } = setupDatabase({ url: ':memory:' });
+
+ expect(await getRuntimeTableColumns({ tableName: 'non_existing_table', db })).to.eql([]);
+ });
+ });
});
diff --git a/apps/papra-server/src/modules/app/database/database.usecases.ts b/apps/papra-server/src/modules/app/database/database.usecases.ts
index 6b7979de..d36cf2c5 100644
--- a/apps/papra-server/src/modules/app/database/database.usecases.ts
+++ b/apps/papra-server/src/modules/app/database/database.usecases.ts
@@ -1,5 +1,7 @@
import type { SQLiteSelect } from 'drizzle-orm/sqlite-core';
import type { ArrayElement } from '../../shared/types';
+import type { Database } from './database.types';
+import { sql } from 'drizzle-orm';
export function createIterator<T extends SQLiteSelect>({
query,
@@ -37,3 +39,9 @@ export async function* createBatchedIterator<T>({
offset += batchSize;
}
}
+
+export async function getRuntimeTableColumns({ tableName, db}: { tableName: string; db: Database }): Promise<string[]> {
+ const { rows } = await db.run(sql`SELECT name FROM pragma_table_info(${tableName})`);
+
+ return rows.map(row => String(row.name));
+}
diff --git a/apps/papra-server/src/modules/documents/document-search/events/sync-document-search.handlers.test.ts b/apps/papra-server/src/modules/documents/document-search/events/sync-document-search.handlers.test.ts
index 91d6a1cb..3b58783e 100644
--- a/apps/papra-server/src/modules/documents/document-search/events/sync-document-search.handlers.test.ts
+++ b/apps/papra-server/src/modules/documents/document-search/events/sync-document-search.handlers.test.ts
@@ -64,6 +64,7 @@ describe('sync-document-search event handlers', () => {
createdAt: new Date('2026-01-01'),
updatedAt: new Date('2026-01-02'),
documentDate: new Date('2025-12-24'),
+ notes: null,
createdBy: 'user-1',
originalSize: 1024,
deletedAt: null,
@@ -109,6 +110,7 @@ describe('sync-document-search event handlers', () => {
createdAt: new Date('2026-01-01'),
updatedAt: new Date('2026-01-02'),
documentDate: new Date('2025-12-24'),
+ notes: null,
createdBy: 'user-1',
originalSize: 1024,
deletedAt: null,
@@ -254,6 +256,7 @@ describe('sync-document-search event handlers', () => {
createdAt: new Date('2026-01-01'),
updatedAt: new Date('2026-01-02'),
documentDate: new Date('2025-12-24'),
+ notes: null,
createdBy: 'user-1',
originalSize: 1024,
deletedAt: null,
diff --git a/apps/papra-server/src/modules/documents/documents.events.types.ts b/apps/papra-server/src/modules/documents/documents.events.types.ts
index dff50949..e48c5bd3 100644
--- a/apps/papra-server/src/modules/documents/documents.events.types.ts
+++ b/apps/papra-server/src/modules/documents/documents.events.types.ts
@@ -10,6 +10,7 @@ export type DocumentEvents = {
changes: {
name?: string;
content?: string;
+ notes?: string;
};
};
'document.deleted': { documentId: string; organizationId: string }; // Hard deleted from trash
diff --git a/apps/papra-server/src/modules/documents/documents.models.test.ts b/apps/papra-server/src/modules/documents/documents.models.test.ts
index b6d475c8..594d2bfe 100644
--- a/apps/papra-server/src/modules/documents/documents.models.test.ts
+++ b/apps/papra-server/src/modules/documents/documents.models.test.ts
@@ -9,7 +9,7 @@ describe('documents models', () => {
});
describe('buildOriginalDocumentKey', () => {
- test(`the original document storage key is composed of
+ test(`the original document storage key is composed of
- the organization id
- the original documents storage key "originals"
- the document id withe the same extension as the original file (if any)`, () => {
@@ -80,6 +80,7 @@ describe('documents models', () => {
createdAt: new Date('2025-01-01'),
updatedAt: new Date('2025-01-01'),
documentDate: new Date('2025-12-24'),
+ notes: null,
},
})).to.eql({
content: 'Hello, world!',
@@ -97,6 +98,7 @@ describe('documents models', () => {
originalSize: 100,
updatedAt: new Date('2025-01-01'),
documentDate: new Date('2025-12-24'),
+ notes: null,
});
});
});
diff --git a/apps/papra-server/src/modules/documents/documents.repository.ts b/apps/papra-server/src/modules/documents/documents.repository.ts
index 4669e436..8e22d5c9 100644
--- a/apps/papra-server/src/modules/documents/documents.repository.ts
+++ b/apps/papra-server/src/modules/documents/documents.repository.ts
@@ -338,10 +338,10 @@ function getAllOrganizationUndeletedDocumentsIterator({ organizationId, batchSiz
return createIterator({ query, batchSize });
}
-async function updateDocument({ documentId, organizationId, name, content, documentDate, db }: { documentId: string; organizationId: string; name?: string; content?: string; documentDate?: Date | null; db: Database }) {
+async function updateDocument({ documentId, organizationId, name, content, documentDate, notes, db }: { documentId: string; organizationId: string; name?: string; content?: string; documentDate?: Date | null; notes?: string; db: Database }) {
const [document] = await db
.update(documentsTable)
- .set(omitUndefined({ name, content, documentDate }))
+ .set(omitUndefined({ name, content, documentDate, notes }))
.where(
and(
eq(documentsTable.id, documentId),
diff --git a/apps/papra-server/src/modules/documents/documents.routes.ts b/apps/papra-server/src/modules/documents/documents.routes.ts
index 8c93923d..338ec6bb 100644
--- a/apps/papra-server/src/modules/documents/documents.routes.ts
+++ b/apps/papra-server/src/modules/documents/documents.routes.ts
@@ -394,7 +394,7 @@ function setupUpdateDocumentRoute({ app, db, eventServices }: RouteDefinitionCon
async (context) => {
const { userId } = getUser({ context });
const { organizationId, documentId } = context.req.valid('param');
- const changes = context.req.valid('json');
+ const { content, documentDate, name, notes } = context.req.valid('json');
const documentsRepository = createDocumentsRepository({ db });
const organizationsRepository = createOrganizationsRepository({ db });
@@ -408,7 +408,7 @@ function setupUpdateDocumentRoute({ app, db, eventServices }: RouteDefinitionCon
userId,
documentsRepository,
eventServices,
- changes,
+ changes: { content, documentDate, name, notes },
});
return context.json({ document: formatDocumentForApi({ document }) });
diff --git a/apps/papra-server/src/modules/documents/documents.schemas.ts b/apps/papra-server/src/modules/documents/documents.schemas.ts
index 5a21ccf3..8ecb3ab6 100644
--- a/apps/papra-server/src/modules/documents/documents.schemas.ts
+++ b/apps/papra-server/src/modules/documents/documents.schemas.ts
@@ -10,10 +10,11 @@ export const updateDocumentBodySchema = v.pipe(
name: v.optional(v.pipe(v.string(), v.minLength(1), v.maxLength(255))),
content: v.optional(v.string()),
documentDate: v.optional(v.nullable(v.pipe(v.string(), v.toDate()))),
+ notes: v.optional(v.pipe(v.string(), v.maxLength(2048))),
}),
v.check(
- data => data.name !== undefined || data.content !== undefined || data.documentDate !== undefined,
- 'At least one of \'name\', \'content\', or \'documentDate\' must be provided',
+ data => data.name !== undefined || data.content !== undefined || data.documentDate !== undefined || data.notes !== undefined,
+ 'At least one of \'name\', \'content\', \'documentDate\' or \'notes\' must be provided',
),
);
diff --git a/apps/papra-server/src/modules/documents/documents.table.ts b/apps/papra-server/src/modules/documents/documents.table.ts
index f5de8e1e..e203336a 100644
--- a/apps/papra-server/src/modules/documents/documents.table.ts
+++ b/apps/papra-server/src/modules/documents/documents.table.ts
@@ -20,6 +20,7 @@ export const documentsTable = sqliteTable('documents', {
mimeType: text('mime_type').notNull(),
content: text('content').notNull().default(''),
documentDate: integer('document_date', { mode: 'timestamp_ms' }),
+ notes: text('notes'),
fileEncryptionKeyWrapped: text('file_encryption_key_wrapped'), // The wrapped encryption key
fileEncryptionKekVersion: text('file_encryption_kek_version'), // The key encryption key version used to encrypt the file encryption key
diff --git a/apps/papra-server/src/modules/documents/documents.usecases.test.ts b/apps/papra-server/src/modules/documents/documents.usecases.test.ts
index 6f3a7f23..09e20293 100644
--- a/apps/papra-server/src/modules/documents/documents.usecases.test.ts
+++ b/apps/papra-server/src/modules/documents/documents.usecases.test.ts
@@ -1088,6 +1088,7 @@ describe('documents usecases', () => {
id: 'document-1',
isDeleted: false,
mimeType: 'text/plain',
+ notes: null,
name: 'new-name.txt',
documentDate: null,
organizationId: 'organization-1',
diff --git a/apps/papra-server/src/modules/documents/documents.usecases.ts b/apps/papra-server/src/modules/documents/documents.usecases.ts
index cd1be9a6..fd37b28c 100644
--- a/apps/papra-server/src/modules/documents/documents.usecases.ts
+++ b/apps/papra-server/src/modules/documents/documents.usecases.ts
@@ -689,6 +689,7 @@ export async function updateDocument({
name?: string;
content?: string;
documentDate?: Date | null;
+ notes?: string;
};
}) {
// It throws if the document does not exist