fix(app): rescue copy importable, trapping draft held, replace confirmed
The JSON rescue copy could not be restored in the app, a draft that traps the engine left the tab on a reload screen and spent a recovery on every read, and an unsaved or in-progress report could be lost by a reload outside the editor or by New report / Import without warning. Home import reads the copy (content-sniffed, 16 MiB cap, strict UTF-8) through the core's draft.restore before any session change; a trapping (draft, archive) pair is held in the resolution panel and only re-read on Retry; ReplaceSessionDialog guards New report and Import; the beforeunload guard is app-wide while unsaved. Supersedes BDR-055's "never held" for `internal` only.
This commit is contained in:
1 parent
9464651140
commit
9bd9acaf58
22 files changed
+1090
-68
No files matched your search
@@ -1,21 +1,24 @@
|
||||
import type { ArchiveImport } from '@faunosteo/core-wasm/types'
|
||||
import type { ArchiveImport, RebaseOutcome } from '@faunosteo/core-wasm/types'
|
||||
import {
|
||||
ArchiveReadError,
|
||||
readAttachedDocument,
|
||||
type ArchiveReadErrorKind,
|
||||
} from '@faunosteo/pdf'
|
||||
import type { SheetIndex } from '@/services/sheetIndex'
|
||||
import { UNREADABLE_DRAFT_KINDS } from '@/state/reportStore'
|
||||
|
||||
export { MAX_PDF_BYTES } from '@faunosteo/pdf'
|
||||
export { MAX_ATTACHMENT_BYTES, MAX_PDF_BYTES } from '@faunosteo/pdf'
|
||||
|
||||
/**
|
||||
* `lone_surrogate`: the attachment escapes a lone UTF-16 surrogate, which the
|
||||
* core cannot read without altering it (L1): refused, the file untouched.
|
||||
* `invalid_copy`: a file offered as a rescue copy that this build cannot read.
|
||||
*/
|
||||
export type ImportErrorKind =
|
||||
| ArchiveReadErrorKind
|
||||
| 'core_unavailable'
|
||||
| 'lone_surrogate'
|
||||
| 'invalid_copy'
|
||||
|
||||
/**
|
||||
* Localization-agnostic import error. Carries a kind discriminant + an
|
||||
@@ -84,3 +87,17 @@ export async function importReportFromPdf(
|
||||
): Promise<ArchiveImport> {
|
||||
return importAttachment(await readAttachment(pdfBytes), index)
|
||||
}
|
||||
|
||||
/**
|
||||
* A rescue copy (`JSON.stringify(report)`, the byte format of the tab's draft)
|
||||
* read by the core's draft restore, no archive beside it. Content the core
|
||||
* refuses is `invalid_copy`; any other failure is the engine's or the sheet's.
|
||||
*/
|
||||
export function readRescueCopy(text: string, index: SheetIndex): RebaseOutcome {
|
||||
const outcome = index.ops.restoreDraft(text, null)
|
||||
if (outcome.ok) return outcome.value.rebase
|
||||
if (UNREADABLE_DRAFT_KINDS.has(outcome.kind)) {
|
||||
throw new ImportError('invalid_copy')
|
||||
}
|
||||
throw new ImportError('core_unavailable')
|
||||
}
|
||||
Reference in new issue
Block a user