(userId: string, path: string)
| 648 | } |
| 649 | |
| 650 | async function getPathEntries(userId: string, path: string): Promise<Deno.DirEntry[]> { |
| 651 | await ensureUserPathIsValidAndSecurelyAccessible(userId, path); |
| 652 | |
| 653 | const rootPath = join(await AppConfig.getFilesRootPath(), userId, path); |
| 654 | |
| 655 | // Ensure the user directory exists |
| 656 | if (path === '/') { |
| 657 | try { |
| 658 | await Deno.stat(rootPath); |
| 659 | } catch (error) { |
| 660 | if ((error as Error).toString().includes('NotFound')) { |
| 661 | await Deno.mkdir(join(rootPath, TRASH_PATH), { recursive: true }); |
| 662 | } |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | // Ensure the Notes or Photos directories exist, if being requested |
| 667 | if (path === '/Notes/' || path === '/Photos/') { |
| 668 | try { |
| 669 | await Deno.stat(rootPath); |
| 670 | } catch (error) { |
| 671 | if ((error as Error).toString().includes('NotFound')) { |
| 672 | await Deno.mkdir(rootPath, { recursive: true }); |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | const entries: Deno.DirEntry[] = []; |
| 678 | |
| 679 | for await (const dirEntry of Deno.readDir(rootPath)) { |
| 680 | entries.push(dirEntry); |
| 681 | } |
| 682 | |
| 683 | entries.sort(sortEntriesByName); |
| 684 | |
| 685 | return entries; |
| 686 | } |
| 687 | |
| 688 | async function renameDirectoryOrFile( |
| 689 | userId: string, |
no test coverage detected