( root: string, noteRelPath: string, sourcePaths: string[] )
| 3705 | } |
| 3706 | |
| 3707 | export 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 | |
| 3743 | export async function importPastedImage( |
| 3744 | root: string, |
no test coverage detected