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

Method list

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

Source from the content-addressed store, hash-verified

28
29export class DirectoryModel {
30 static async list(userId: string, path: string): Promise<Directory[]> {
31 await ensureUserPathIsValidAndSecurelyAccessible(userId, path);
32
33 const rootPath = join(await AppConfig.getFilesRootPath(), userId, path);
34
35 const directories: Directory[] = [];
36
37 const directoryEntries = (await getPathEntries(userId, path)).filter((entry) =>
38 entry.isDirectory || entry.isSymlink
39 );
40
41 const fileShares = (await AppConfig.isPublicFileSharingAllowed())
42 ? await FileShareModel.getByParentFilePath(userId, path)
43 : [];
44
45 for (const entry of directoryEntries) {
46 const stat = await Deno.stat(join(rootPath, entry.name));
47
48 const directorySize = await getDirectorySize(join(rootPath, entry.name));
49
50 const directory: Directory = {
51 user_id: userId,
52 parent_path: path,
53 directory_name: entry.name,
54 has_write_access: true,
55 size_in_bytes: directorySize || stat.size,
56 file_share_id: fileShares.find((fileShare) => fileShare.file_path === `${join(path, entry.name)}/`)?.id || null,
57 updated_at: stat.mtime || new Date(),
58 created_at: stat.birthtime || new Date(),
59 };
60
61 directories.push(directory);
62 }
63
64 directories.sort(sortDirectoriesByName);
65 return directories;
66 }
67
68 static async create(userId: string, path: string, name: string): Promise<boolean> {
69 await ensureUserPathIsValidAndSecurelyAccessible(userId, join(path, name));

Callers

nothing calls this directly

Calls 6

getPathEntriesFunction · 0.85
getDirectorySizeFunction · 0.85
getFilesRootPathMethod · 0.80
getByParentFilePathMethod · 0.80

Tested by

no test coverage detected