( totalNotes: number, cacheFolder: string, type: "txt" | "pdf" | "md" | "html" | "md-frontmatter", path: string, callback: (progress?: string) => void )
| 272 | } |
| 273 | |
| 274 | async function createZip( |
| 275 | totalNotes: number, |
| 276 | cacheFolder: string, |
| 277 | type: "txt" | "pdf" | "md" | "html" | "md-frontmatter", |
| 278 | path: string, |
| 279 | callback: (progress?: string) => void |
| 280 | ) { |
| 281 | const fileName = `nn-export-${totalNotes}-${type}-${Date.now()}.zip`; |
| 282 | const dir = path; |
| 283 | try { |
| 284 | callback("Creating zip"); |
| 285 | const zipOutputPath = |
| 286 | Platform.OS === "ios" |
| 287 | ? join(path, fileName) |
| 288 | : join(RNFetchBlob.fs.dirs.CacheDir, fileName); |
| 289 | await zip(cacheFolder, zipOutputPath); |
| 290 | |
| 291 | callback("Saving zip file"); |
| 292 | if (Platform.OS === "android") { |
| 293 | const file = await ScopedStorage.createFile( |
| 294 | path, |
| 295 | fileName, |
| 296 | "application/zip" |
| 297 | ); |
| 298 | path = file.uri; |
| 299 | await copyFileAsync("file://" + zipOutputPath, path); |
| 300 | await RNFetchBlob.fs.unlink(zipOutputPath); |
| 301 | callback(); |
| 302 | } else { |
| 303 | path = zipOutputPath; |
| 304 | } |
| 305 | RNFetchBlob.fs.unlink(cacheFolder); |
| 306 | } catch (e) { |
| 307 | DatabaseLogger.error(e as Error); |
| 308 | } |
| 309 | |
| 310 | return { |
| 311 | filePath: path, |
| 312 | fileDir: dir, |
| 313 | type: "application/zip", |
| 314 | name: "zip", |
| 315 | fileName: fileName, |
| 316 | count: totalNotes |
| 317 | }; |
| 318 | } |
| 319 | |
| 320 | async function createFile( |
| 321 | noteItem: ExportableNote, |
no test coverage detected