MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / deleteDirectoryOrFile

Function deleteDirectoryOrFile

lib/models/files.ts:711–742  ·  view source on GitHub ↗
(userId: string, path: string, name: string)

Source from the content-addressed store, hash-verified

709}
710
711async 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
744export async function searchFilesAndDirectories(
745 userId: string,

Callers 2

deleteMethod · 0.85
deleteMethod · 0.85

Calls 7

getFilesRootPathMethod · 0.80
getByParentFilePathMethod · 0.80
removeMethod · 0.80
renameMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected