( note: Note, type: "txt" | "pdf" | "md" | "html" | "md-frontmatter", callback: (progress?: string) => void )
| 221 | } |
| 222 | |
| 223 | async 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 | |
| 274 | async function createZip( |
| 275 | totalNotes: number, |
nothing calls this directly
no test coverage detected