@okhay-p/mivra 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/THIRD_PARTY_NOTICES.md +4 -0
- package/dist/chunk-3RMHLZ2Z.js +736 -0
- package/dist/chunk-3RMHLZ2Z.js.map +7 -0
- package/dist/chunk-EICBRY5M.js +381 -0
- package/dist/chunk-EICBRY5M.js.map +7 -0
- package/dist/chunk-FBDML53R.js +933 -0
- package/dist/chunk-FBDML53R.js.map +7 -0
- package/dist/chunk-KE5ZEREE.js +212 -0
- package/dist/chunk-KE5ZEREE.js.map +7 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +7 -0
- package/dist/chunk-TBAR47I6.js +32 -0
- package/dist/chunk-TBAR47I6.js.map +7 -0
- package/dist/cli.js +256 -11188
- package/dist/cli.js.map +4 -4
- package/dist/client-VU3KWV3U.js +12 -0
- package/dist/client-VU3KWV3U.js.map +7 -0
- package/dist/extract-child.js +107 -173
- package/dist/extract-child.js.map +3 -3
- package/dist/key-check-WJ4CVZV5.js +8 -0
- package/dist/key-check-WJ4CVZV5.js.map +7 -0
- package/dist/start-3J3JSJEX.js +10899 -0
- package/dist/start-3J3JSJEX.js.map +7 -0
- package/drizzle/0012_overconfident_the_santerians.sql +66 -0
- package/drizzle/meta/0012_snapshot.json +1741 -0
- package/drizzle/meta/_journal.json +7 -0
- package/package.json +1 -1
- package/web/assets/index-BUYWW1Mc.js +406 -0
- package/web/assets/index-Cmq-m9fI.css +1 -0
- package/web/assets/{render.worker-Bw6rO7Qu.js → render.worker-BEpv9w1x.js} +1 -1
- package/web/index.html +2 -2
- package/web/assets/index-BfT-sp3_.js +0 -406
- package/web/assets/index-FIC4B_yh.css +0 -1
package/dist/extract-child.js
CHANGED
|
@@ -1,195 +1,127 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
DocumentError,
|
|
3
|
+
cleanVaultPath,
|
|
4
|
+
extractDocument
|
|
5
|
+
} from "./chunk-KE5ZEREE.js";
|
|
6
|
+
import {
|
|
7
|
+
MAX_NOTE_CHARS,
|
|
8
|
+
MAX_VAULT_BYTES,
|
|
9
|
+
MAX_VAULT_FILES
|
|
10
|
+
} from "./chunk-FBDML53R.js";
|
|
11
|
+
import "./chunk-PZ5AY32C.js";
|
|
12
|
+
|
|
13
|
+
// ../server/src/notes/vault-zip.ts
|
|
4
14
|
import yauzl from "yauzl";
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
15
|
+
var MAX_VAULT_ZIP_ENTRIES = 5e4;
|
|
16
|
+
var MAX_NOTE_BYTES = MAX_NOTE_CHARS * 4;
|
|
17
|
+
var NOT_A_ZIP = "This isn't a .zip file.";
|
|
18
|
+
var CORRUPT = "This zip looks damaged and can't be read.";
|
|
19
|
+
var TOO_BIG = `The vault's notes come to more than ${MAX_VAULT_BYTES / (1024 * 1024)} MB unpacked, more than one import can take.`;
|
|
20
|
+
var UNSAFE_NAME = "This zip has an entry whose name starts with / or contains .., so it was refused.";
|
|
21
|
+
var S_IFMT = 61440;
|
|
22
|
+
var S_IFLNK = 40960;
|
|
23
|
+
var isSymlink = (entry) => (entry.externalFileAttributes >>> 16 & S_IFMT) === S_IFLNK;
|
|
24
|
+
function commonTopFolder(names) {
|
|
25
|
+
let top;
|
|
26
|
+
for (const name of names) {
|
|
27
|
+
const slash = name.indexOf("/");
|
|
28
|
+
if (slash <= 0) return void 0;
|
|
29
|
+
const first = name.slice(0, slash);
|
|
30
|
+
if (top === void 0) top = first;
|
|
31
|
+
else if (top !== first) return void 0;
|
|
9
32
|
}
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
var MAX_PAGES = 5e3;
|
|
13
|
-
var MAX_TEXT_CHARS = 1e7;
|
|
14
|
-
var MIN_TEXT_CHARS = 20;
|
|
15
|
-
var MAX_ZIP_ENTRIES = 2e4;
|
|
16
|
-
var MAX_ZIP_DECLARED_BYTES = 1024 * 1024 * 1024;
|
|
17
|
-
var MAX_XML_PART_BYTES = 32 * 1024 * 1024;
|
|
18
|
-
var MAX_XML_TOTAL_BYTES = 256 * 1024 * 1024;
|
|
19
|
-
var WRONG_TYPE = "Only PDF and PowerPoint (.pptx) files can be attached.";
|
|
20
|
-
var CORRUPT = "This file looks damaged and can't be read.";
|
|
21
|
-
var ENCRYPTED = "This file is password-protected. Remove the password and upload it again.";
|
|
22
|
-
var TOO_MUCH_TEXT = "This file has too much text to attach. Try uploading the part you need.";
|
|
23
|
-
function cleanText(text) {
|
|
24
|
-
return text.replace(/[^\P{C}\n\t]/gu, "").replace(/[ff-st\u{1D400}-\u{1D7FF}]/gu, (c) => c.normalize("NFKC")).replace(/[ \t]+/g, " ").replace(/ ?\n ?/g, "\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
33
|
+
return top;
|
|
25
34
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
kind === "pdf" ? "This PDF has no readable text; it's probably scanned. Mivra can't read images yet, so try a PDF with selectable text." : "These slides have no readable text; they're probably images. Mivra can't read images yet."
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
return { kind, pageCount, pages };
|
|
35
|
+
var isMacMetadata = (name) => name === "__MACOSX" || name.startsWith("__MACOSX/");
|
|
36
|
+
function zipError(error) {
|
|
37
|
+
if (/^(absolute path|invalid relative path|invalid characters)/.test(error.message)) return new DocumentError("corrupt", UNSAFE_NAME);
|
|
38
|
+
if (/end of central directory record signature not found/i.test(error.message)) return new DocumentError("wrong_type", NOT_A_ZIP);
|
|
39
|
+
return new DocumentError("corrupt", CORRUPT);
|
|
35
40
|
}
|
|
36
|
-
|
|
37
|
-
const { getDocument } = await getResolvedPDFJS();
|
|
38
|
-
const task = getDocument({ data: new Uint8Array(bytes), useSystemFonts: false, disableFontFace: true, verbosity: 0 });
|
|
39
|
-
try {
|
|
40
|
-
const pdf = await task.promise.catch((error) => {
|
|
41
|
-
throw error?.name === "PasswordException" ? new DocumentError("encrypted", ENCRYPTED) : new DocumentError("corrupt", CORRUPT);
|
|
42
|
-
});
|
|
43
|
-
if (pdf.numPages > MAX_PAGES) throw new DocumentError("too_complex", `This PDF has more than ${MAX_PAGES} pages.`);
|
|
44
|
-
const pages = [];
|
|
45
|
-
let chars = 0;
|
|
46
|
-
for (let page = 1; page <= pdf.numPages; page++) {
|
|
47
|
-
const text = await pdf.getPage(page).then(async (handle) => {
|
|
48
|
-
const content = await handle.getTextContent();
|
|
49
|
-
handle.cleanup();
|
|
50
|
-
return content.items.map((item) => "str" in item ? item.str + (item.hasEOL ? "\n" : "") : "").join("");
|
|
51
|
-
}).catch(() => "");
|
|
52
|
-
chars += text.length;
|
|
53
|
-
if (chars > MAX_TEXT_CHARS) throw new DocumentError("too_complex", TOO_MUCH_TEXT);
|
|
54
|
-
pages.push({ page, text });
|
|
55
|
-
}
|
|
56
|
-
return finish("pdf", pdf.numPages, pages);
|
|
57
|
-
} finally {
|
|
58
|
-
await task.destroy().catch(() => {
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function openZip(bytes) {
|
|
63
|
-
const buffer = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
41
|
+
function unzipVault(bytes) {
|
|
64
42
|
return new Promise((resolve, reject) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
43
|
+
const buffer = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
44
|
+
yauzl.fromBuffer(buffer, { lazyEntries: true, strictFileNames: false, validateEntrySizes: true }, (openError, zip) => {
|
|
45
|
+
if (openError || !zip) return reject(zipError(openError ?? new Error()));
|
|
46
|
+
let settled = false;
|
|
47
|
+
const fail = (error) => {
|
|
48
|
+
if (settled) return;
|
|
49
|
+
settled = true;
|
|
50
|
+
zip.close();
|
|
51
|
+
reject(error);
|
|
52
|
+
};
|
|
53
|
+
if (zip.entryCount > MAX_VAULT_ZIP_ENTRIES) return fail(new DocumentError("too_complex", `This zip has more than ${MAX_VAULT_ZIP_ENTRIES.toLocaleString("en")} entries, more than one import can take.`));
|
|
54
|
+
const entries = [];
|
|
55
|
+
zip.on("error", (error) => fail(zipError(error)));
|
|
72
56
|
zip.on("entry", (entry) => {
|
|
73
|
-
if (entry.isEncrypted()) return
|
|
74
|
-
|
|
75
|
-
if (declared > MAX_ZIP_DECLARED_BYTES) return reject(new DocumentError("too_complex", "This file unpacks to too much data to read safely."));
|
|
76
|
-
if (entries.has(entry.fileName)) return reject(new DocumentError("corrupt", CORRUPT));
|
|
77
|
-
entries.set(entry.fileName, entry);
|
|
57
|
+
if (entry.isEncrypted()) return fail(new DocumentError("encrypted", "This zip is password-protected. Zip the vault again without a password."));
|
|
58
|
+
if (!entry.fileName.endsWith("/") && !isMacMetadata(entry.fileName)) entries.push(entry);
|
|
78
59
|
zip.readEntry();
|
|
79
60
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (unpacked > MAX_XML_TOTAL_BYTES) stream.destroy(tooMuch);
|
|
91
|
-
else chunks.push(chunk);
|
|
92
|
-
});
|
|
93
|
-
stream.on("error", (error) => fail(error instanceof DocumentError ? error : new DocumentError("corrupt", CORRUPT)));
|
|
94
|
-
stream.on("end", () => done(Buffer.concat(chunks)));
|
|
95
|
-
});
|
|
61
|
+
zip.on("end", () => {
|
|
62
|
+
void unpack(zip, entries).then(
|
|
63
|
+
(vault) => {
|
|
64
|
+
if (settled) return;
|
|
65
|
+
settled = true;
|
|
66
|
+
zip.close();
|
|
67
|
+
resolve(vault);
|
|
68
|
+
},
|
|
69
|
+
(error) => fail(error instanceof DocumentError ? error : new DocumentError("corrupt", CORRUPT))
|
|
70
|
+
);
|
|
96
71
|
});
|
|
97
|
-
zip.on("end", () => resolve({ names: new Set(entries.keys()), read, close: () => zip.close() }));
|
|
98
72
|
zip.readEntry();
|
|
99
73
|
});
|
|
100
74
|
});
|
|
101
75
|
}
|
|
102
|
-
function
|
|
103
|
-
const
|
|
104
|
-
const
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (name) return NAMED_ENTITIES[name.toLowerCase()] ?? whole;
|
|
113
|
-
const code = dec ? Number(dec) : parseInt(hex, 16);
|
|
114
|
-
return code <= 1114111 ? String.fromCodePoint(code) : whole;
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
function* xmlTokens(xml) {
|
|
118
|
-
for (const [token] of xml.matchAll(/<!--[\s\S]*?-->|<!\[CDATA\[[\s\S]*?\]\]>|<[^>]*>|[^<]+/g)) {
|
|
119
|
-
if (token.startsWith("<!--") || token.startsWith("<?")) continue;
|
|
120
|
-
if (token.startsWith("<![CDATA[")) yield { text: token.slice(9, -3) };
|
|
121
|
-
else if (token.startsWith("<")) {
|
|
122
|
-
const name = /^<\/?(?:[\w.-]+:)?([\w.-]+)/.exec(token)?.[1] ?? "";
|
|
123
|
-
yield { tag: token, name, closing: token.startsWith("</"), selfClosing: token.endsWith("/>") };
|
|
124
|
-
} else yield { text: decodeEntities(token) };
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
function slideText(xml) {
|
|
128
|
-
let out = "";
|
|
129
|
-
let inText = 0;
|
|
130
|
-
let inFallback = 0;
|
|
131
|
-
for (const token of xmlTokens(xml)) {
|
|
132
|
-
if ("text" in token) {
|
|
133
|
-
if (inText > 0 && inFallback === 0) out += token.text;
|
|
76
|
+
async function unpack(zip, entries) {
|
|
77
|
+
const top = commonTopFolder(entries.map((e) => e.fileName));
|
|
78
|
+
const skipped = [];
|
|
79
|
+
const notes = [];
|
|
80
|
+
let declared = 0;
|
|
81
|
+
for (const entry of entries) {
|
|
82
|
+
const path = top === void 0 ? entry.fileName : entry.fileName.slice(top.length + 1);
|
|
83
|
+
const cleaned = cleanVaultPath(path);
|
|
84
|
+
if ("reason" in cleaned) {
|
|
85
|
+
if (cleaned.reason !== "hidden") skipped.push({ path, reason: cleaned.reason });
|
|
134
86
|
continue;
|
|
135
87
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
else if (inFallback === 0 && (token.name === "br" || token.name === "p" && token.closing)) out += "\n";
|
|
140
|
-
}
|
|
141
|
-
return out;
|
|
142
|
-
}
|
|
143
|
-
var attribute = (tag, name) => new RegExp(`\\s${name.source}\\s*=\\s*["']([^"']*)["']`).exec(tag)?.[1];
|
|
144
|
-
function slideOrder(presentationXml, relsXml) {
|
|
145
|
-
const targets = /* @__PURE__ */ new Map();
|
|
146
|
-
for (const token of xmlTokens(relsXml)) {
|
|
147
|
-
if ("tag" in token && token.name === "Relationship" && !token.closing) {
|
|
148
|
-
const id = attribute(token.tag, /Id/);
|
|
149
|
-
const target = attribute(token.tag, /Target/);
|
|
150
|
-
if (id && target) targets.set(id, target);
|
|
88
|
+
if (isSymlink(entry)) {
|
|
89
|
+
skipped.push({ path, reason: "symlink" });
|
|
90
|
+
continue;
|
|
151
91
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if ("tag" in token && token.name === "sldId" && !token.closing) {
|
|
156
|
-
const target = targets.get(attribute(token.tag, /[\w.-]+:id/) ?? "");
|
|
157
|
-
const part = target && (target.startsWith("/") ? posix.normalize(target).slice(1) : posix.join("ppt", target));
|
|
158
|
-
slides.push(part && /^ppt\/slides\/[^/]+\.xml$/.test(part) ? part : void 0);
|
|
92
|
+
if (entry.uncompressedSize > MAX_NOTE_BYTES) {
|
|
93
|
+
skipped.push({ path, reason: "too_long" });
|
|
94
|
+
continue;
|
|
159
95
|
}
|
|
96
|
+
if (notes.length >= MAX_VAULT_FILES) throw new DocumentError("too_complex", `This zip has more than ${MAX_VAULT_FILES.toLocaleString("en")} notes, more than one import can take.`);
|
|
97
|
+
declared += entry.uncompressedSize;
|
|
98
|
+
if (declared > MAX_VAULT_BYTES) throw new DocumentError("too_large", TOO_BIG);
|
|
99
|
+
notes.push({ path: cleaned.path, entry });
|
|
160
100
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const types = decodeXml(await zip.read("[Content_Types].xml"));
|
|
168
|
-
if (!/officedocument\.presentationml\.(presentation|slideshow|template)\.main\+xml/i.test(types)) throw new DocumentError("wrong_type", WRONG_TYPE);
|
|
169
|
-
if (!zip.names.has("ppt/presentation.xml") || !zip.names.has("ppt/_rels/presentation.xml.rels")) throw new DocumentError("corrupt", CORRUPT);
|
|
170
|
-
const slides = slideOrder(decodeXml(await zip.read("ppt/presentation.xml")), decodeXml(await zip.read("ppt/_rels/presentation.xml.rels")));
|
|
171
|
-
if (slides.length > MAX_PAGES) throw new DocumentError("too_complex", `This file has more than ${MAX_PAGES} slides.`);
|
|
172
|
-
const pages = [];
|
|
173
|
-
let chars = 0;
|
|
174
|
-
for (const [index, part] of slides.entries()) {
|
|
175
|
-
if (!part || !zip.names.has(part)) continue;
|
|
176
|
-
const text = slideText(decodeXml(await zip.read(part)));
|
|
177
|
-
chars += text.length;
|
|
178
|
-
if (chars > MAX_TEXT_CHARS) throw new DocumentError("too_complex", TOO_MUCH_TEXT);
|
|
179
|
-
pages.push({ page: index + 1, text });
|
|
180
|
-
}
|
|
181
|
-
return finish("pptx", slides.length, pages);
|
|
182
|
-
} finally {
|
|
183
|
-
zip.close();
|
|
101
|
+
const decoder = new TextDecoder("utf-8");
|
|
102
|
+
const files = [];
|
|
103
|
+
for (const { path, entry } of notes) {
|
|
104
|
+
const text = decoder.decode(await read(zip, entry));
|
|
105
|
+
if (text.length > MAX_NOTE_CHARS) skipped.push({ path, reason: "too_long" });
|
|
106
|
+
else files.push({ path, text });
|
|
184
107
|
}
|
|
108
|
+
return { files, skipped };
|
|
185
109
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
110
|
+
function read(zip, entry) {
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
zip.openReadStream(entry, (error, stream) => {
|
|
113
|
+
if (error || !stream) return reject(error instanceof Error ? zipError(error) : new DocumentError("corrupt", CORRUPT));
|
|
114
|
+
const chunks = [];
|
|
115
|
+
let size = 0;
|
|
116
|
+
stream.on("data", (chunk) => {
|
|
117
|
+
size += chunk.length;
|
|
118
|
+
if (size > entry.uncompressedSize) stream.destroy(new Error("too much data"));
|
|
119
|
+
else chunks.push(chunk);
|
|
120
|
+
});
|
|
121
|
+
stream.on("error", () => reject(new DocumentError("corrupt", CORRUPT)));
|
|
122
|
+
stream.on("end", () => resolve(Buffer.concat(chunks)));
|
|
123
|
+
});
|
|
124
|
+
});
|
|
193
125
|
}
|
|
194
126
|
|
|
195
127
|
// ../server/src/documents/extract-child.ts
|
|
@@ -199,7 +131,9 @@ process.once("message", async (message) => {
|
|
|
199
131
|
if (message?.reportRss === true) setInterval(() => process.send({ rss: process.memoryUsage.rss() }), 100).unref();
|
|
200
132
|
try {
|
|
201
133
|
if (!(message?.bytes instanceof Uint8Array)) throw new DocumentError("failed", "Couldn't read this file.");
|
|
202
|
-
send({ ok: true,
|
|
134
|
+
if (message.task === "vault-zip") send({ ok: true, value: await unzipVault(message.bytes) });
|
|
135
|
+
else if (message.task === "document") send({ ok: true, value: await extractDocument(message.bytes) });
|
|
136
|
+
else throw new DocumentError("failed", "Couldn't read this file.");
|
|
203
137
|
} catch (error) {
|
|
204
138
|
send(
|
|
205
139
|
error instanceof DocumentError ? { ok: false, code: error.code, message: error.message } : { ok: false, code: "corrupt", message: "This file looks damaged and can't be read." }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../server/src/
|
|
4
|
-
"sourcesContent": ["import { posix } from \"node:path\";\nimport { getResolvedPDFJS } from \"unpdf\";\nimport yauzl from \"yauzl\";\n\n/**\n * Text extraction for untrusted PDF and PPTX files (ADR-010). This runs inside a subprocess (see\n * extract-in-child.ts), which supplies the timeout and memory limits this code can't enforce itself.\n */\n\nexport type DocumentErrorCode = \"too_large\" | \"wrong_type\" | \"no_text\" | \"encrypted\" | \"corrupt\" | \"too_complex\" | \"timeout\" | \"failed\";\n\n/** A failure whose message is safe and useful to show the learner. */\nexport class DocumentError extends Error {\n constructor(\n readonly code: DocumentErrorCode,\n message: string,\n ) {\n super(message);\n }\n}\n\nexport interface ExtractedPage {\n /** 1-based page or slide number. */\n page: number;\n text: string;\n}\n\nexport interface ExtractedDocument {\n kind: \"pdf\" | \"pptx\";\n pageCount: number;\n /** Only the pages that have text. */\n pages: ExtractedPage[];\n}\n\nconst MAX_PAGES = 5000;\nconst MAX_TEXT_CHARS = 10_000_000;\n/** Below this across the whole file there is nothing useful to read: it's images, or at most a stray page number. */\nconst MIN_TEXT_CHARS = 20;\n\nconst MAX_ZIP_ENTRIES = 20_000;\n/** What all entries claim to unpack to, including media that is never unpacked. */\nconst MAX_ZIP_DECLARED_BYTES = 1024 * 1024 * 1024;\n/** What may actually be unpacked: only XML parts are read. */\nconst MAX_XML_PART_BYTES = 32 * 1024 * 1024;\nconst MAX_XML_TOTAL_BYTES = 256 * 1024 * 1024;\n\nconst WRONG_TYPE = \"Only PDF and PowerPoint (.pptx) files can be attached.\";\nconst CORRUPT = \"This file looks damaged and can't be read.\";\nconst ENCRYPTED = \"This file is password-protected. Remove the password and upload it again.\";\nconst TOO_MUCH_TEXT = \"This file has too much text to attach. Try uploading the part you need.\";\n\n/**\n * Keeps text that can be read and searched. Invisible formatting characters go too, since they can\n * hide text from the learner while the model still reads it. Ligatures and maths letters (\uD835\uDC65) become\n * plain ones so a search finds them, while the rest of Unicode, such as \u00B2, is left alone.\n */\nexport function cleanText(text: string): string {\n return text\n .replace(/[^\\P{C}\\n\\t]/gu, \"\")\n .replace(/[\uFB00-\uFB06\\u{1D400}-\\u{1D7FF}]/gu, (c: string) => c.normalize(\"NFKC\"))\n .replace(/[ \\t]+/g, \" \")\n .replace(/ ?\\n ?/g, \"\\n\")\n .replace(/\\n{3,}/g, \"\\n\\n\")\n .trim();\n}\n\nfunction finish(kind: ExtractedDocument[\"kind\"], pageCount: number, raw: ExtractedPage[]): ExtractedDocument {\n const pages = raw.map(({ page, text }) => ({ page, text: cleanText(text) })).filter((page) => page.text);\n if (pages.reduce((sum, page) => sum + page.text.replace(/\\s/g, \"\").length, 0) < MIN_TEXT_CHARS) {\n throw new DocumentError(\n \"no_text\",\n kind === \"pdf\"\n ? \"This PDF has no readable text; it's probably scanned. Mivra can't read images yet, so try a PDF with selectable text.\"\n : \"These slides have no readable text; they're probably images. Mivra can't read images yet.\",\n );\n }\n return { kind, pageCount, pages };\n}\n\nasync function extractPdf(bytes: Uint8Array): Promise<ExtractedDocument> {\n const { getDocument } = await getResolvedPDFJS();\n // This pdf.js build has no eval path for fonts (the CVE-2024-4367 route); text extraction never renders. It only warns on recoverable damage.\n // pdf.js refuses a Buffer, and takes ownership of what it's given.\n const task = getDocument({ data: new Uint8Array(bytes), useSystemFonts: false, disableFontFace: true, verbosity: 0 });\n try {\n const pdf = await task.promise.catch((error: unknown) => {\n throw (error as Error)?.name === \"PasswordException\" ? new DocumentError(\"encrypted\", ENCRYPTED) : new DocumentError(\"corrupt\", CORRUPT);\n });\n if (pdf.numPages > MAX_PAGES) throw new DocumentError(\"too_complex\", `This PDF has more than ${MAX_PAGES} pages.`);\n const pages: ExtractedPage[] = [];\n let chars = 0;\n for (let page = 1; page <= pdf.numPages; page++) {\n // One bad page shouldn't lose the rest; it counts as a page without text.\n const text = await pdf\n .getPage(page)\n .then(async (handle) => {\n const content = await handle.getTextContent();\n handle.cleanup();\n // Reading order is the file's own, which is usually right for columns but isn't guaranteed.\n return content.items.map((item) => (\"str\" in item ? item.str + (item.hasEOL ? \"\\n\" : \"\") : \"\")).join(\"\");\n })\n .catch(() => \"\");\n chars += text.length;\n if (chars > MAX_TEXT_CHARS) throw new DocumentError(\"too_complex\", TOO_MUCH_TEXT);\n pages.push({ page, text });\n }\n return finish(\"pdf\", pdf.numPages, pages);\n } finally {\n await task.destroy().catch(() => {});\n }\n}\n\n/** The zip's entries by name, with a reader for each that enforces the unpacked-size limits. */\nfunction openZip(bytes: Uint8Array): Promise<{ names: Set<string>; read: (name: string) => Promise<Buffer>; close: () => void }> {\n const buffer = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n return new Promise((resolve, reject) => {\n // yauzl rejects absolute paths, \"..\" and backslashes in names, and checks entries against their declared sizes.\n yauzl.fromBuffer(buffer, { lazyEntries: true, strictFileNames: true, validateEntrySizes: true }, (openError, zip) => {\n if (openError) return reject(new DocumentError(\"corrupt\", CORRUPT));\n if (zip.entryCount > MAX_ZIP_ENTRIES) return reject(new DocumentError(\"too_complex\", \"This file contains too many parts to read safely.\"));\n const entries = new Map<string, yauzl.Entry>();\n let declared = 0;\n let unpacked = 0;\n zip.on(\"error\", () => reject(new DocumentError(\"corrupt\", CORRUPT)));\n zip.on(\"entry\", (entry: yauzl.Entry) => {\n if (entry.isEncrypted()) return reject(new DocumentError(\"encrypted\", ENCRYPTED));\n declared += entry.uncompressedSize;\n if (declared > MAX_ZIP_DECLARED_BYTES) return reject(new DocumentError(\"too_complex\", \"This file unpacks to too much data to read safely.\"));\n // Two entries with one name could show different content to different readers.\n if (entries.has(entry.fileName)) return reject(new DocumentError(\"corrupt\", CORRUPT));\n entries.set(entry.fileName, entry);\n zip.readEntry();\n });\n const read = (name: string) =>\n new Promise<Buffer>((done, fail) => {\n const entry = entries.get(name);\n if (!entry) return fail(new DocumentError(\"corrupt\", CORRUPT));\n const tooMuch = new DocumentError(\"too_complex\", \"This file unpacks to too much data to read safely.\");\n if (entry.uncompressedSize > MAX_XML_PART_BYTES) return fail(tooMuch);\n zip.openReadStream(entry, (streamError, stream) => {\n if (streamError) return fail(new DocumentError(\"corrupt\", CORRUPT));\n const chunks: Buffer[] = [];\n stream.on(\"data\", (chunk: Buffer) => {\n unpacked += chunk.length;\n if (unpacked > MAX_XML_TOTAL_BYTES) stream.destroy(tooMuch);\n else chunks.push(chunk);\n });\n stream.on(\"error\", (error) => fail(error instanceof DocumentError ? error : new DocumentError(\"corrupt\", CORRUPT)));\n stream.on(\"end\", () => done(Buffer.concat(chunks)));\n });\n });\n zip.on(\"end\", () => resolve({ names: new Set(entries.keys()), read, close: () => zip.close() }));\n zip.readEntry();\n });\n });\n}\n\n/** Office XML is UTF-8 or UTF-16. Any other declared encoding reads as damaged text, not as a risk. */\nfunction decodeXml(bytes: Buffer): string {\n const [a, b] = bytes;\n const encoding = (a === 0xff && b === 0xfe) || (a === 0x3c && b === 0) ? \"utf-16le\" : (a === 0xfe && b === 0xff) || (a === 0 && b === 0x3c) ? \"utf-16be\" : \"utf-8\";\n const xml = new TextDecoder(encoding).decode(bytes);\n // Office never writes a DTD, so one means a crafted file. Nothing here expands entities anyway: see xmlTokens.\n if (/<!(DOCTYPE|ENTITY)/i.test(xml)) throw new DocumentError(\"corrupt\", \"This file contains unsafe XML and can't be read.\");\n return xml;\n}\n\nconst NAMED_ENTITIES: Record<string, string> = { amp: \"&\", lt: \"<\", gt: \">\", quot: '\"', apos: \"'\" };\n\n/** The five predefined entities and character references. Any other entity stays as literal text. */\nfunction decodeEntities(text: string): string {\n return text.replace(/&(?:#(\\d{1,7})|#x([\\da-f]{1,6})|(amp|lt|gt|quot|apos));/gi, (whole, dec?: string, hex?: string, name?: string) => {\n if (name) return NAMED_ENTITIES[name.toLowerCase()] ?? whole;\n const code = dec ? Number(dec) : parseInt(hex!, 16);\n return code <= 0x10ffff ? String.fromCodePoint(code) : whole;\n });\n}\n\n/** Splits XML into tags and text without interpreting it, which is all these few element types need. */\nfunction* xmlTokens(xml: string) {\n for (const [token] of xml.matchAll(/<!--[\\s\\S]*?-->|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>|<[^>]*>|[^<]+/g)) {\n if (token.startsWith(\"<!--\") || token.startsWith(\"<?\")) continue;\n if (token.startsWith(\"<![CDATA[\")) yield { text: token.slice(9, -3) };\n else if (token.startsWith(\"<\")) {\n const name = /^<\\/?(?:[\\w.-]+:)?([\\w.-]+)/.exec(token)?.[1] ?? \"\";\n yield { tag: token, name, closing: token.startsWith(\"</\"), selfClosing: token.endsWith(\"/>\") };\n } else yield { text: decodeEntities(token) };\n }\n}\n\n/** Slide text: `a:t` runs and `m:t` equation runs, without `mc:Fallback`, which repeats content for old readers. */\nfunction slideText(xml: string): string {\n let out = \"\";\n let inText = 0;\n let inFallback = 0;\n for (const token of xmlTokens(xml)) {\n if (\"text\" in token) {\n if (inText > 0 && inFallback === 0) out += token.text;\n continue;\n }\n const delta = token.selfClosing ? 0 : token.closing ? -1 : 1;\n if (token.name === \"Fallback\") inFallback = Math.max(0, inFallback + delta);\n else if (token.name === \"t\") inText = Math.max(0, inText + delta);\n else if (inFallback === 0 && (token.name === \"br\" || (token.name === \"p\" && token.closing))) out += \"\\n\";\n }\n return out;\n}\n\nconst attribute = (tag: string, name: RegExp) => new RegExp(`\\\\s${name.source}\\\\s*=\\\\s*[\"']([^\"']*)[\"']`).exec(tag)?.[1];\n\n/** The presentation's slide parts in the order it shows them, which needn't match their file names. */\nfunction slideOrder(presentationXml: string, relsXml: string): (string | undefined)[] {\n const targets = new Map<string, string>();\n for (const token of xmlTokens(relsXml)) {\n if (\"tag\" in token && token.name === \"Relationship\" && !token.closing) {\n const id = attribute(token.tag, /Id/);\n const target = attribute(token.tag, /Target/);\n if (id && target) targets.set(id, target);\n }\n }\n const slides: (string | undefined)[] = [];\n for (const token of xmlTokens(presentationXml)) {\n if (\"tag\" in token && token.name === \"sldId\" && !token.closing) {\n const target = targets.get(attribute(token.tag, /[\\w.-]+:id/) ?? \"\");\n // Relationship targets come from the file, so only a part directly under ppt/slides is ever opened.\n const part = target && (target.startsWith(\"/\") ? posix.normalize(target).slice(1) : posix.join(\"ppt\", target));\n slides.push(part && /^ppt\\/slides\\/[^/]+\\.xml$/.test(part) ? part : undefined);\n }\n }\n return slides;\n}\n\nasync function extractPptx(bytes: Uint8Array): Promise<ExtractedDocument> {\n const zip = await openZip(bytes);\n try {\n if (!zip.names.has(\"[Content_Types].xml\")) throw new DocumentError(\"wrong_type\", WRONG_TYPE);\n const types = decodeXml(await zip.read(\"[Content_Types].xml\"));\n if (!/officedocument\\.presentationml\\.(presentation|slideshow|template)\\.main\\+xml/i.test(types)) throw new DocumentError(\"wrong_type\", WRONG_TYPE);\n if (!zip.names.has(\"ppt/presentation.xml\") || !zip.names.has(\"ppt/_rels/presentation.xml.rels\")) throw new DocumentError(\"corrupt\", CORRUPT);\n\n const slides = slideOrder(decodeXml(await zip.read(\"ppt/presentation.xml\")), decodeXml(await zip.read(\"ppt/_rels/presentation.xml.rels\")));\n if (slides.length > MAX_PAGES) throw new DocumentError(\"too_complex\", `This file has more than ${MAX_PAGES} slides.`);\n const pages: ExtractedPage[] = [];\n let chars = 0;\n for (const [index, part] of slides.entries()) {\n if (!part || !zip.names.has(part)) continue;\n const text = slideText(decodeXml(await zip.read(part)));\n chars += text.length;\n if (chars > MAX_TEXT_CHARS) throw new DocumentError(\"too_complex\", TOO_MUCH_TEXT);\n pages.push({ page: index + 1, text });\n }\n return finish(\"pptx\", slides.length, pages);\n } finally {\n zip.close();\n }\n}\n\nconst startsWith = (bytes: Uint8Array, magic: number[]) => magic.every((byte, i) => bytes[i] === byte);\n\n/** Dispatches on what the file contains, whatever it is called. */\nexport async function extractDocument(bytes: Uint8Array): Promise<ExtractedDocument> {\n const buffer = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n // The PDF spec lets a header sit a little way into the file.\n if (buffer.subarray(0, 1024).includes(\"%PDF-\")) return extractPdf(bytes);\n if (startsWith(bytes, [0x50, 0x4b, 0x03, 0x04])) return extractPptx(bytes);\n // Office stores a password-protected .pptx in the same container as an old .ppt.\n if (startsWith(bytes, [0xd0, 0xcf, 0x11, 0xe0]) && buffer.includes(Buffer.from(\"EncryptedPackage\", \"utf16le\"))) throw new DocumentError(\"encrypted\", ENCRYPTED);\n throw new DocumentError(\"wrong_type\", WRONG_TYPE);\n}\n", "import { DocumentError, extractDocument } from \"./extract.js\";\n\n/**\n * The entry of an extraction subprocess (see extract-in-child.ts): reads one file sent over IPC, reports\n * its text or a DocumentError, and exits. The parent enforces the memory limits and kills this process if\n * it runs too long, so nothing here needs to clean up.\n */\nconst send = (message: unknown) => process.send!(message, () => process.exit(0));\n\n// The parent is gone, so nobody is waiting for the result.\nprocess.once(\"disconnect\", () => process.exit(0));\nprocess.once(\"message\", async (message: { bytes?: unknown; reportRss?: unknown }) => {\n // Where the parent can't read this process's memory from /proc, it relies on these reports.\n if (message?.reportRss === true) setInterval(() => process.send!({ rss: process.memoryUsage.rss() }), 100).unref();\n try {\n if (!(message?.bytes instanceof Uint8Array)) throw new DocumentError(\"failed\", \"Couldn't read this file.\");\n send({ ok: true, document: await extractDocument(message.bytes) });\n } catch (error) {\n send(\n error instanceof DocumentError\n ? { ok: false, code: error.code, message: error.message }\n : { ok: false, code: \"corrupt\", message: \"This file looks damaged and can't be read.\" },\n );\n }\n});\n"],
|
|
5
|
-
"mappings": "
|
|
3
|
+
"sources": ["../../server/src/notes/vault-zip.ts", "../../server/src/documents/extract-child.ts"],
|
|
4
|
+
"sourcesContent": ["import { MAX_NOTE_CHARS, MAX_VAULT_BYTES, MAX_VAULT_FILES, type VaultFile } from \"@mivra/protocol\";\nimport yauzl from \"yauzl\";\nimport { DocumentError } from \"../documents/extract.js\";\nimport { cleanVaultPath, type SkippedFile } from \"./vault-path.js\";\n\n/**\n * Unpacks a zipped Obsidian vault's notes (ADR-014). The zip is hostile (ADR-010), so this runs in the extraction\n * subprocess (see extract-in-child.ts), which adds a timeout and memory limits. Entries are only ever read into\n * memory, never written to disk under their stored names, and only `.md` entries are unpacked at all.\n */\n\n/** Every entry, including attachments and folders, which are listed but never unpacked. */\nexport const MAX_VAULT_ZIP_ENTRIES = 50_000;\n/** A UTF-8 note has at least as many bytes as characters, so one over four times the limit can't fit. */\nconst MAX_NOTE_BYTES = MAX_NOTE_CHARS * 4;\n\nexport interface UnzippedVault {\n files: VaultFile[];\n /** Entries left out before importing: attachments, symbolic links and notes that are too long. */\n skipped: SkippedFile[];\n}\n\nconst NOT_A_ZIP = \"This isn't a .zip file.\";\nconst CORRUPT = \"This zip looks damaged and can't be read.\";\nconst TOO_BIG = `The vault's notes come to more than ${MAX_VAULT_BYTES / (1024 * 1024)} MB unpacked, more than one import can take.`;\nconst UNSAFE_NAME = \"This zip has an entry whose name starts with / or contains .., so it was refused.\";\n\n/** Unix file type bits, kept in the top half of an entry's external attributes. */\nconst S_IFMT = 0o170000;\nconst S_IFLNK = 0o120000;\nconst isSymlink = (entry: yauzl.Entry) => ((entry.externalFileAttributes >>> 16) & S_IFMT) === S_IFLNK;\n\n/**\n * A zip of a vault usually holds the vault's own folder, so when every entry sits under one top folder, that folder\n * is dropped from the paths. macOS adds `__MACOSX/` beside it, which is ignored entirely.\n */\nexport function commonTopFolder(names: string[]): string | undefined {\n let top: string | undefined;\n for (const name of names) {\n const slash = name.indexOf(\"/\");\n // A file at the top level means there's no wrapper folder.\n if (slash <= 0) return undefined;\n const first = name.slice(0, slash);\n if (top === undefined) top = first;\n else if (top !== first) return undefined;\n }\n return top;\n}\n\nconst isMacMetadata = (name: string) => name === \"__MACOSX\" || name.startsWith(\"__MACOSX/\");\n\nfunction zipError(error: Error): DocumentError {\n if (/^(absolute path|invalid relative path|invalid characters)/.test(error.message)) return new DocumentError(\"corrupt\", UNSAFE_NAME);\n if (/end of central directory record signature not found/i.test(error.message)) return new DocumentError(\"wrong_type\", NOT_A_ZIP);\n return new DocumentError(\"corrupt\", CORRUPT);\n}\n\nexport function unzipVault(bytes: Uint8Array): Promise<UnzippedVault> {\n return new Promise((resolve, reject) => {\n const buffer = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n // yauzl refuses absolute names and \"..\" for us; strictFileNames: false turns Windows backslashes into slashes\n // first. validateEntrySizes stops an entry that unpacks to more than it claims, so the size checks hold.\n yauzl.fromBuffer(buffer, { lazyEntries: true, strictFileNames: false, validateEntrySizes: true }, (openError, zip) => {\n if (openError || !zip) return reject(zipError(openError ?? new Error()));\n let settled = false;\n const fail = (error: DocumentError) => {\n if (settled) return;\n settled = true;\n zip.close();\n reject(error);\n };\n if (zip.entryCount > MAX_VAULT_ZIP_ENTRIES) return fail(new DocumentError(\"too_complex\", `This zip has more than ${MAX_VAULT_ZIP_ENTRIES.toLocaleString(\"en\")} entries, more than one import can take.`));\n\n const entries: yauzl.Entry[] = [];\n zip.on(\"error\", (error: Error) => fail(zipError(error)));\n zip.on(\"entry\", (entry: yauzl.Entry) => {\n if (entry.isEncrypted()) return fail(new DocumentError(\"encrypted\", \"This zip is password-protected. Zip the vault again without a password.\"));\n if (!entry.fileName.endsWith(\"/\") && !isMacMetadata(entry.fileName)) entries.push(entry);\n zip.readEntry();\n });\n zip.on(\"end\", () => {\n void unpack(zip, entries).then(\n (vault) => {\n if (settled) return;\n settled = true;\n zip.close();\n resolve(vault);\n },\n (error: unknown) => fail(error instanceof DocumentError ? error : new DocumentError(\"corrupt\", CORRUPT)),\n );\n });\n zip.readEntry();\n });\n });\n}\n\n/** Picks the notes from the listed entries, checks the limits against their declared sizes, then unpacks only those. */\nasync function unpack(zip: yauzl.ZipFile, entries: yauzl.Entry[]): Promise<UnzippedVault> {\n const top = commonTopFolder(entries.map((e) => e.fileName));\n const skipped: SkippedFile[] = [];\n const notes: { path: string; entry: yauzl.Entry }[] = [];\n let declared = 0;\n for (const entry of entries) {\n const path = top === undefined ? entry.fileName : entry.fileName.slice(top.length + 1);\n const cleaned = cleanVaultPath(path);\n if (\"reason\" in cleaned) {\n // Hidden folders hold Obsidian's settings and trash: leaving them out isn't news, as with the folder picker.\n if (cleaned.reason !== \"hidden\") skipped.push({ path, reason: cleaned.reason });\n continue;\n }\n if (isSymlink(entry)) {\n skipped.push({ path, reason: \"symlink\" });\n continue;\n }\n if (entry.uncompressedSize > MAX_NOTE_BYTES) {\n skipped.push({ path, reason: \"too_long\" });\n continue;\n }\n if (notes.length >= MAX_VAULT_FILES) throw new DocumentError(\"too_complex\", `This zip has more than ${MAX_VAULT_FILES.toLocaleString(\"en\")} notes, more than one import can take.`);\n declared += entry.uncompressedSize;\n if (declared > MAX_VAULT_BYTES) throw new DocumentError(\"too_large\", TOO_BIG);\n notes.push({ path: cleaned.path, entry });\n }\n\n const decoder = new TextDecoder(\"utf-8\");\n const files: VaultFile[] = [];\n for (const { path, entry } of notes) {\n const text = decoder.decode(await read(zip, entry));\n if (text.length > MAX_NOTE_CHARS) skipped.push({ path, reason: \"too_long\" });\n else files.push({ path, text });\n }\n return { files, skipped };\n}\n\n/** One entry's bytes, stopping at its declared size whatever the stream does. */\nfunction read(zip: yauzl.ZipFile, entry: yauzl.Entry): Promise<Buffer> {\n return new Promise((resolve, reject) => {\n zip.openReadStream(entry, (error, stream) => {\n if (error || !stream) return reject(error instanceof Error ? zipError(error) : new DocumentError(\"corrupt\", CORRUPT));\n const chunks: Buffer[] = [];\n let size = 0;\n stream.on(\"data\", (chunk: Buffer) => {\n size += chunk.length;\n if (size > entry.uncompressedSize) stream.destroy(new Error(\"too much data\"));\n else chunks.push(chunk);\n });\n stream.on(\"error\", () => reject(new DocumentError(\"corrupt\", CORRUPT)));\n stream.on(\"end\", () => resolve(Buffer.concat(chunks)));\n });\n });\n}\n", "import { unzipVault } from \"../notes/vault-zip.js\";\nimport { DocumentError, extractDocument } from \"./extract.js\";\n\n/**\n * The entry of an extraction subprocess (see extract-in-child.ts): reads one file sent over IPC, reports\n * its text (a document's, or a zipped vault's notes) or a DocumentError, and exits. The parent enforces the memory limits and kills this process if\n * it runs too long, so nothing here needs to clean up.\n */\nconst send = (message: unknown) => process.send!(message, () => process.exit(0));\n\n// The parent is gone, so nobody is waiting for the result.\nprocess.once(\"disconnect\", () => process.exit(0));\nprocess.once(\"message\", async (message: { task?: unknown; bytes?: unknown; reportRss?: unknown }) => {\n // Where the parent can't read this process's memory from /proc, it relies on these reports.\n if (message?.reportRss === true) setInterval(() => process.send!({ rss: process.memoryUsage.rss() }), 100).unref();\n try {\n if (!(message?.bytes instanceof Uint8Array)) throw new DocumentError(\"failed\", \"Couldn't read this file.\");\n if (message.task === \"vault-zip\") send({ ok: true, value: await unzipVault(message.bytes) });\n else if (message.task === \"document\") send({ ok: true, value: await extractDocument(message.bytes) });\n else throw new DocumentError(\"failed\", \"Couldn't read this file.\");\n } catch (error) {\n send(\n error instanceof DocumentError\n ? { ok: false, code: error.code, message: error.message }\n : { ok: false, code: \"corrupt\", message: \"This file looks damaged and can't be read.\" },\n );\n }\n});\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;AACA,OAAO,WAAW;AAWX,IAAM,wBAAwB;AAErC,IAAM,iBAAiB,iBAAiB;AAQxC,IAAM,YAAY;AAClB,IAAM,UAAU;AAChB,IAAM,UAAU,uCAAuC,mBAAmB,OAAO,KAAK;AACtF,IAAM,cAAc;AAGpB,IAAM,SAAS;AACf,IAAM,UAAU;AAChB,IAAM,YAAY,CAAC,WAAyB,MAAM,2BAA2B,KAAM,YAAY;AAMxF,SAAS,gBAAgB,OAAqC;AACnE,MAAI;AACJ,aAAW,QAAQ,OAAO;AACxB,UAAM,QAAQ,KAAK,QAAQ,GAAG;AAE9B,QAAI,SAAS,EAAG,QAAO;AACvB,UAAM,QAAQ,KAAK,MAAM,GAAG,KAAK;AACjC,QAAI,QAAQ,OAAW,OAAM;AAAA,aACpB,QAAQ,MAAO,QAAO;AAAA,EACjC;AACA,SAAO;AACT;AAEA,IAAM,gBAAgB,CAAC,SAAiB,SAAS,cAAc,KA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