(
userId: string,
path: string,
name?: string,
)
| 264 | } |
| 265 | |
| 266 | static async get( |
| 267 | userId: string, |
| 268 | path: string, |
| 269 | name?: string, |
| 270 | ): Promise<{ success: boolean; contents?: Uint8Array; contentType?: string; byteSize?: number }> { |
| 271 | await ensureUserPathIsValidAndSecurelyAccessible(userId, join(path, name || '')); |
| 272 | |
| 273 | const rootPath = join(await AppConfig.getFilesRootPath(), userId, path); |
| 274 | |
| 275 | try { |
| 276 | const stat = await Deno.stat(join(rootPath, name || '')); |
| 277 | |
| 278 | if (stat) { |
| 279 | const contents = await Deno.readFile(join(rootPath, name || '')); |
| 280 | |
| 281 | const extension = (name || path).split('.').slice(-1).join('').toLowerCase(); |
| 282 | |
| 283 | const contentType = lookup(extension) || 'application/octet-stream'; |
| 284 | |
| 285 | return { |
| 286 | success: true, |
| 287 | contents, |
| 288 | contentType, |
| 289 | byteSize: stat.size, |
| 290 | }; |
| 291 | } |
| 292 | } catch (error) { |
| 293 | console.error(error); |
| 294 | } |
| 295 | |
| 296 | return { |
| 297 | success: false, |
| 298 | }; |
| 299 | } |
| 300 | |
| 301 | static async rename( |
| 302 | userId: string, |
nothing calls this directly
no test coverage detected