A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Fix: catch sessionStorage errors for large documents (#6150)
shamoonebe1479503c9
diff --git a/src-ui/setup-jest.ts b/src-ui/setup-jest.tsindex 39f018c6d..8e754589b 100644--- a/src-ui/setup-jest.ts+++ b/src-ui/setup-jest.ts@@ -76,7 +76,10 @@ const mock = () => {let storage: { [key: string]: string } = {}return {getItem: (key: string) => (key in storage ? storage[key] : null),- setItem: (key: string, value: string) => (storage[key] = value || ''),+ setItem: (key: string, value: string) => {+ if (value.length > 1000000) throw new Error('localStorage overflow')+ storage[key] = value || ''+ },removeItem: (key: string) => delete storage[key],clear: () => (storage = {}),}diff --git a/src-ui/src/app/services/open-documents.service.spec.ts b/src-ui/src/app/services/open-documents.service.spec.tsindex 69d2a4a37..09341da62 100644--- a/src-ui/src/app/services/open-documents.service.spec.ts+++ b/src-ui/src/app/services/open-documents.service.spec.ts@@ -5,10 +5,11 @@ import {HttpTestingController,} from '@angular/common/http/testing'import { environment } from 'src/environments/environment'-import { Subscription } from 'rxjs'+import { Subscription, throwError } from 'rxjs'import { NgbModal } from '@ng-bootstrap/ng-bootstrap'import { ConfirmDialogComponent } from '../components/common/confirm-dialog/confirm-dialog.component'import { OPEN_DOCUMENT_SERVICE } from '../data/storage-keys'+import { wind } from 'ngx-bootstrap-icons'const documents = [{@@ -233,4 +234,12 @@ describe('OpenDocumentsService', () => {req.error(new ErrorEvent('timeout'))expect(openDocumentsService.getOpenDocuments()).toHaveLength(0)})++ it('should log error on sessionStorage save', () => {+ const doc = { ...documents[0] }+ doc.content = 'a'.repeat(1000000)+ const consoleSpy = jest.spyOn(console, 'error').mockImplementation()+ openDocumentsService.openDocument(doc)+ expect(consoleSpy).toHaveBeenCalled()+ })})diff --git a/src-ui/src/app/services/open-documents.service.ts b/src-ui/src/app/services/open-documents.service.tsindex 71b1586fd..363a51b03 100644--- a/src-ui/src/app/services/open-documents.service.ts+++ b/src-ui/src/app/services/open-documents.service.ts@@ -152,9 +152,13 @@ export class OpenDocumentsService {}save() {- sessionStorage.setItem(- OPEN_DOCUMENT_SERVICE.DOCUMENTS,- JSON.stringify(this.openDocuments)- )+ try {+ sessionStorage.setItem(+ OPEN_DOCUMENT_SERVICE.DOCUMENTS,+ JSON.stringify(this.openDocuments)+ )+ } catch (e) {+ console.error('Error saving open documents to session storage', e)+ }}}