MCPcopy
hub / github.com/streetwriters/notesnook / exportNote

Function exportNote

apps/mobile/app/services/exporter.ts:223–272  ·  view source on GitHub ↗
(
  note: Note,
  type: "txt" | "pdf" | "md" | "html" | "md-frontmatter",
  callback: (progress?: string) => void
)

Source from the content-addressed store, hash-verified

221}
222
223async function exportNote(
224 note: Note,
225 type: "txt" | "pdf" | "md" | "html" | "md-frontmatter",
226 callback: (progress?: string) => void
227) {
228 const fileFuncions = await resolveFileFunctions(type);
229
230 if (!fileFuncions) return;
231
232 const path = fileFuncions.path;
233 const { mkdir, writeFile, cacheFolder } = fileFuncions;
234
235 let currentAttachmentProgress = 0;
236 let hasAttachments = false;
237 let noteItem;
238 for await (const item of _exportNote(note, {
239 format: type,
240 unlockVault: unlockVaultForNoteExport as () => Promise<boolean>
241 })) {
242 if (item instanceof Error) {
243 DatabaseLogger.error(item);
244 continue;
245 }
246
247 if (item.type === "note") {
248 callback(`Exporting note`);
249 try {
250 noteItem = item;
251 await exportNoteToFile(item, type, mkdir, writeFile);
252 } catch (e) {
253 /* empty */
254 }
255 } else if (item.type === "attachment") {
256 currentAttachmentProgress += 1;
257 callback(`Downloading attachments (${currentAttachmentProgress})`);
258 try {
259 hasAttachments = true;
260 await exportAttachmentToFile(item, mkdir, cacheFolder);
261 } catch (e) {
262 /* empty */
263 }
264 }
265 }
266
267 if (!hasAttachments) {
268 return createFile(noteItem as ExportableNote, type, path, cacheFolder);
269 } else {
270 return createZip(1, cacheFolder, type, path, callback);
271 }
272}
273
274async function createZip(
275 totalNotes: number,

Callers

nothing calls this directly

Calls 7

resolveFileFunctionsFunction · 0.85
callbackFunction · 0.85
exportNoteToFileFunction · 0.85
exportAttachmentToFileFunction · 0.85
createFileFunction · 0.85
createZipFunction · 0.85
errorMethod · 0.45

Tested by

no test coverage detected