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

Function createFile

apps/mobile/app/services/exporter.ts:320–357  ·  view source on GitHub ↗
(
  noteItem: ExportableNote,
  type: keyof typeof FileMime,
  path: string,
  cacheFolder: string
)

Source from the content-addressed store, hash-verified

318}
319
320async 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
359const FileMime = {
360 pdf: "application/pdf",

Callers 1

exportNoteFunction · 0.85

Calls 4

copyFileAsyncFunction · 0.70
createFileMethod · 0.65
existsMethod · 0.65
replaceMethod · 0.45

Tested by

no test coverage detected