File size: 1,333 Bytes
131b00f 0a89d37 131b00f 7c36fbe 0a89d37 131b00f 0a89d37 131b00f 0a89d37 7c36fbe 0a89d37 131b00f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | export function exportSession(s) {
return JSON.stringify({
version: 2,
savedAt: new Date().toISOString(),
fileName: s.fileName,
pdfHash: s.pdfHash || '',
screen: 'reader',
noteModes: s.noteModes,
commentary: s.commentary,
paper: s.paper,
litPapers: s.litPapers,
litByPara: s.litByPara,
figures: s.figures || [],
litByFig: s.litByFig || {},
equations: s.equations || [],
references: s.references || [],
citeIndex: s.citeIndex || {},
userNotes: s.userNotes || {},
paperNote: s.paperNote || '',
}, null, 2);
}
export function importSession(json) {
const s = JSON.parse(json);
if ((s.version !== 1 && s.version !== 2) || !s.paper || !s.paper.paragraphs) {
throw new Error('could not read that session file');
}
// Tolerant defaults for fields absent in older sessions
if (!s.figures) s.figures = [];
if (!s.litByFig) s.litByFig = {};
if (!s.equations) s.equations = [];
if (!s.references) s.references = [];
if (!s.citeIndex) s.citeIndex = {};
if (!s.userNotes) s.userNotes = {};
if (!s.paperNote) s.paperNote = '';
return s;
}
export async function hashPdf(arrayBuffer) {
const digest = await crypto.subtle.digest('SHA-256', arrayBuffer);
return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, '0')).join('');
}
|