(userId: string, path: string)
| 177 | |
| 178 | export class FileModel { |
| 179 | static async list(userId: string, path: string): Promise<DirectoryFile[]> { |
| 180 | await ensureUserPathIsValidAndSecurelyAccessible(userId, path); |
| 181 | |
| 182 | const rootPath = join(await AppConfig.getFilesRootPath(), userId, path); |
| 183 | |
| 184 | const files: DirectoryFile[] = []; |
| 185 | |
| 186 | const fileEntries = (await getPathEntries(userId, path)).filter((entry) => entry.isFile); |
| 187 | |
| 188 | const fileShares = (await AppConfig.isPublicFileSharingAllowed()) |
| 189 | ? await FileShareModel.getByParentFilePath(userId, path) |
| 190 | : []; |
| 191 | |
| 192 | for (const entry of fileEntries) { |
| 193 | const stat = await Deno.stat(join(rootPath, entry.name)); |
| 194 | |
| 195 | const file: DirectoryFile = { |
| 196 | user_id: userId, |
| 197 | parent_path: path, |
| 198 | file_name: entry.name, |
| 199 | has_write_access: true, |
| 200 | size_in_bytes: stat.size, |
| 201 | file_share_id: fileShares.find((fileShare) => fileShare.file_path === join(path, entry.name))?.id || null, |
| 202 | updated_at: stat.mtime || new Date(), |
| 203 | created_at: stat.birthtime || new Date(), |
| 204 | }; |
| 205 | |
| 206 | files.push(file); |
| 207 | } |
| 208 | |
| 209 | files.sort(sortFilesByName); |
| 210 | return files; |
| 211 | } |
| 212 | |
| 213 | static async create( |
| 214 | userId: string, |
nothing calls this directly
no test coverage detected