mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
Fix: catch sessionStorage errors for large documents (#6150)
This commit is contained in:
parent
8c9fe4da06
commit
ebe1479503
@ -76,7 +76,10 @@ const mock = () => {
|
|||||||
let storage: { [key: string]: string } = {}
|
let storage: { [key: string]: string } = {}
|
||||||
return {
|
return {
|
||||||
getItem: (key: string) => (key in storage ? storage[key] : null),
|
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],
|
removeItem: (key: string) => delete storage[key],
|
||||||
clear: () => (storage = {}),
|
clear: () => (storage = {}),
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,11 @@ import {
|
|||||||
HttpTestingController,
|
HttpTestingController,
|
||||||
} from '@angular/common/http/testing'
|
} from '@angular/common/http/testing'
|
||||||
import { environment } from 'src/environments/environment'
|
import { environment } from 'src/environments/environment'
|
||||||
import { Subscription } from 'rxjs'
|
import { Subscription, throwError } from 'rxjs'
|
||||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
||||||
import { ConfirmDialogComponent } from '../components/common/confirm-dialog/confirm-dialog.component'
|
import { ConfirmDialogComponent } from '../components/common/confirm-dialog/confirm-dialog.component'
|
||||||
import { OPEN_DOCUMENT_SERVICE } from '../data/storage-keys'
|
import { OPEN_DOCUMENT_SERVICE } from '../data/storage-keys'
|
||||||
|
import { wind } from 'ngx-bootstrap-icons'
|
||||||
|
|
||||||
const documents = [
|
const documents = [
|
||||||
{
|
{
|
||||||
@ -233,4 +234,12 @@ describe('OpenDocumentsService', () => {
|
|||||||
req.error(new ErrorEvent('timeout'))
|
req.error(new ErrorEvent('timeout'))
|
||||||
expect(openDocumentsService.getOpenDocuments()).toHaveLength(0)
|
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()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -152,9 +152,13 @@ export class OpenDocumentsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
save() {
|
save() {
|
||||||
sessionStorage.setItem(
|
try {
|
||||||
OPEN_DOCUMENT_SERVICE.DOCUMENTS,
|
sessionStorage.setItem(
|
||||||
JSON.stringify(this.openDocuments)
|
OPEN_DOCUMENT_SERVICE.DOCUMENTS,
|
||||||
)
|
JSON.stringify(this.openDocuments)
|
||||||
|
)
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error saving open documents to session storage', e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user