(
userId: string,
path: string,
name: string,
contents: string | ArrayBuffer,
)
| 211 | } |
| 212 | |
| 213 | static async create( |
| 214 | userId: string, |
| 215 | path: string, |
| 216 | name: string, |
| 217 | contents: string | ArrayBuffer, |
| 218 | ): Promise<boolean> { |
| 219 | await ensureUserPathIsValidAndSecurelyAccessible(userId, join(path, name)); |
| 220 | |
| 221 | const rootPath = join(await AppConfig.getFilesRootPath(), userId, path); |
| 222 | |
| 223 | try { |
| 224 | // Ensure the directory exist, if being requested |
| 225 | try { |
| 226 | await Deno.stat(rootPath); |
| 227 | } catch (error) { |
| 228 | if ((error as Error).toString().includes('NotFound')) { |
| 229 | await Deno.mkdir(rootPath, { recursive: true }); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | if (typeof contents === 'string') { |
| 234 | await Deno.writeTextFile(join(rootPath, name), contents, { append: false, createNew: true }); |
| 235 | } else { |
| 236 | await Deno.writeFile(join(rootPath, name), new Uint8Array(contents), { append: false, createNew: true }); |
| 237 | } |
| 238 | } catch (error) { |
| 239 | console.error(error); |
| 240 | return false; |
| 241 | } |
| 242 | |
| 243 | return true; |
| 244 | } |
| 245 | |
| 246 | static async update( |
| 247 | userId: string, |
nothing calls this directly
no test coverage detected