(userId: string, path: string, name: string)
| 709 | } |
| 710 | |
| 711 | async function deleteDirectoryOrFile(userId: string, path: string, name: string): Promise<boolean> { |
| 712 | await ensureUserPathIsValidAndSecurelyAccessible(userId, join(path, name)); |
| 713 | |
| 714 | const rootPath = join(await AppConfig.getFilesRootPath(), userId, path); |
| 715 | |
| 716 | const fileShares = (await AppConfig.isPublicFileSharingAllowed()) |
| 717 | ? await FileShareModel.getByParentFilePath(userId, path) |
| 718 | : []; |
| 719 | |
| 720 | const fileSharesForPath = fileShares.filter((fileShare) => |
| 721 | fileShare.file_path === `${join(path, name)}/` || fileShare.file_path === join(path, name) |
| 722 | ); |
| 723 | |
| 724 | try { |
| 725 | if (path.startsWith(TRASH_PATH)) { |
| 726 | await Deno.remove(join(rootPath, name), { recursive: true }); |
| 727 | } else { |
| 728 | const trashPath = join(await AppConfig.getFilesRootPath(), userId, TRASH_PATH); |
| 729 | await Deno.rename(join(rootPath, name), join(trashPath, name)); |
| 730 | } |
| 731 | |
| 732 | // Delete all file shares for this path |
| 733 | for (const fileShare of fileSharesForPath) { |
| 734 | await FileShareModel.delete(fileShare.id); |
| 735 | } |
| 736 | } catch (error) { |
| 737 | console.error(error); |
| 738 | return false; |
| 739 | } |
| 740 | |
| 741 | return true; |
| 742 | } |
| 743 | |
| 744 | export async function searchFilesAndDirectories( |
| 745 | userId: string, |
no test coverage detected