(root: string, rel: string)
| 714 | } |
| 715 | |
| 716 | export async function duplicateNote(root: string, rel: string): Promise<NoteMeta> { |
| 717 | const abs = resolveSafe(root, rel) |
| 718 | const folder = folderOf(root, abs) |
| 719 | if (!folder) throw new Error(`Note not in a known folder: ${rel}`) |
| 720 | const dir = path.dirname(abs) |
| 721 | const ext = path.extname(abs) |
| 722 | const baseTitle = path.basename(abs, ext) |
| 723 | const copyTitle = await uniqueTitle(dir, `${baseTitle} copy`) |
| 724 | const destAbs = path.join(dir, `${copyTitle}${ext}`) |
| 725 | const body = await fs.readFile(abs, 'utf8') |
| 726 | await fs.writeFile(destAbs, body, 'utf8') |
| 727 | return await readMeta(root, destAbs, folder) |
| 728 | } |
| 729 | |
| 730 | export async function deleteNote(root: string, rel: string): Promise<void> { |
| 731 | const abs = resolveSafe(root, rel) |
no test coverage detected