Skip to content

Add Paperless-ngx PDF sync provider with document versioning and task polling#610

Draft
Copilot wants to merge 8 commits intomainfrom
copilot/add-remote-pdf-sync-provider
Draft

Add Paperless-ngx PDF sync provider with document versioning and task polling#610
Copilot wants to merge 8 commits intomainfrom
copilot/add-remote-pdf-sync-provider

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 16, 2026

Paperless-ngx's POST /api/documents/post_document/ always creates a new document, so repeated syncs of a modified app document would accumulate duplicates. The upload endpoint also returns only a task UUID — the actual Paperless document ID is only available once the background task completes.

API wrapper (PaperlessNgx.ts)

  • fetchTasks(service)GET /api/tasks/, returns full task list with task_id, status, related_document
  • updateDocumentVersion(service, paperlessDocId, title, fileData)POST /api/documents/{id}/update_version/ for subsequent syncs
  • PaperlessTask / PaperlessTaskStatus types covering all Celery states (PENDING, STARTED, SUCCESS, FAILURE, REVOKED, RETRY, RECEIVED)
  • Minor fixes: getAuthHeaders accepts string | undefined; endpoint defaults to '' in makeRequest

Sync service (PaperlessNgxPDFSyncService.ts)

  • Stores the linked Paperless document ID in doc.extra['paperless_pdf_id'] (persisted to DB)
  • On writePDF:
    • Existing linkupdateDocumentVersion (no duplicate created)
    • New documentuploadDocument → register task UUID → await polling resolution → persist ID
  • Polling loop (pollLoop) runs every 2 s, shared across concurrent uploads for the same service instance; each task UUID is tracked in pendingTasks: Map<uuid, {resolve, reject}> so writePDF awaits only its own task
// First sync: uploads and waits for Paperless to finish consuming
const taskUuid = await uploadDocument(this, fileName, file);
const paperlessDocId = await this.waitForTask(taskUuid);   // polls /api/tasks/ every 2s
await document.save({ extra: { paperless_pdf_id: paperlessDocId } }, false, false);

// Subsequent syncs: updates the existing document in-place
await updateDocumentVersion(this, existingPaperlessId, fileName, file);

Copilot AI and others added 8 commits April 16, 2026 06:57
- Add PaperlessNgx.ts API helper with token auth, document listing and PDF upload
- Add PaperlessNgxPDFSyncService.ts extending BasePDFSyncService
- Add PaperlessNgxSettingsView.svelte and PaperlessNgxPDFSyncSettings.svelte settings UI
- Register paperless_pdf in types.ts, sync.ts, SyncWorker.ts and SyncListSettings.svelte
- Add i18n strings to en.json

Agent-Logs-Url: https://github.com/ossdocumentscanner/OSS-DocumentScanner/sessions/80eebb5c-7dda-4531-b56c-95ec0e3fbe3b

Co-authored-by: farfromrefug <655344+farfromrefug@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants