( noteItem: ExportableNote, type: keyof typeof FileMime, path: string, cacheFolder: string )
| 318 | } |
| 319 | |
| 320 | async function createFile( |
| 321 | noteItem: ExportableNote, |
| 322 | type: keyof typeof FileMime, |
| 323 | path: string, |
| 324 | cacheFolder: string |
| 325 | ) { |
| 326 | const exportedFile = join(cacheFolder, noteItem?.path as string); |
| 327 | let filePath: string; |
| 328 | if (Platform.OS === "android") { |
| 329 | const file = await ScopedStorage.createFile( |
| 330 | path, |
| 331 | basename(noteItem?.path as string), |
| 332 | FileMime[type] |
| 333 | ); |
| 334 | await copyFileAsync("file://" + exportedFile, file.uri); |
| 335 | filePath = file.uri; |
| 336 | } else { |
| 337 | const originalPath = join(path, basename(noteItem.path)); |
| 338 | filePath = originalPath; |
| 339 | const ext = extname(originalPath); |
| 340 | let id = 1; |
| 341 | while (await RNFetchBlob.fs.exists(filePath)) { |
| 342 | filePath = originalPath.replace(`${ext}`, "") + "_" + id + ext; |
| 343 | id++; |
| 344 | } |
| 345 | |
| 346 | await RNFetchBlob.fs.mv(exportedFile, filePath); |
| 347 | } |
| 348 | |
| 349 | return { |
| 350 | filePath: filePath, |
| 351 | fileDir: path, |
| 352 | type: FileMime[type], |
| 353 | name: type, |
| 354 | fileName: basename(noteItem?.path as string), |
| 355 | count: 1 |
| 356 | }; |
| 357 | } |
| 358 | |
| 359 | const FileMime = { |
| 360 | pdf: "application/pdf", |
no test coverage detected