MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / importFiles

Function importFiles

apps/desktop/src/main/vault.ts:3707–3741  ·  view source on GitHub ↗
(
  root: string,
  noteRelPath: string,
  sourcePaths: string[]
)

Source from the content-addressed store, hash-verified

3705}
3706
3707export async function importFiles(
3708 root: string,
3709 noteRelPath: string,
3710 sourcePaths: string[]
3711): Promise<ImportedAsset[]> {
3712 await fs.mkdir(root, { recursive: true })
3713
3714 const noteDir = path.posix.dirname(toPosix(noteRelPath))
3715 const imported: ImportedAsset[] = []
3716
3717 for (const sourcePath of sourcePaths) {
3718 const sourceAbs = path.resolve(sourcePath)
3719 const stat = await fs.stat(sourceAbs)
3720 if (!stat.isFile()) continue
3721
3722 const finalName = await uniqueFilename(root, path.basename(sourceAbs))
3723 const destAbs = path.join(root, finalName)
3724 await fs.copyFile(sourceAbs, destAbs)
3725
3726 const vaultRelPath = toPosix(path.relative(root, destAbs))
3727 const relativeFromNote = path.posix.relative(
3728 noteDir === '.' ? '' : noteDir,
3729 vaultRelPath
3730 )
3731 const kind = classifyImportedAsset(finalName)
3732 imported.push({
3733 name: finalName,
3734 path: vaultRelPath,
3735 markdown: markdownForImportedAsset(relativeFromNote, finalName, kind),
3736 kind
3737 })
3738 }
3739
3740 return imported
3741}
3742
3743export async function importPastedImage(
3744 root: string,

Callers 1

registerIpcFunction · 0.90

Calls 4

uniqueFilenameFunction · 0.85
classifyImportedAssetFunction · 0.85
markdownForImportedAssetFunction · 0.85
toPosixFunction · 0.70

Tested by

no test coverage detected