- Add permissions logic for status options in corrective actions. - Create tests for permissions functionality. - Implement queries for user authentication and actions management. - Develop Actions page to display and manage corrective actions. - Create authentication pages for login, setup, and password reset. - Add IncidentDetail page to view incident details and associated actions. - Implement Settings page for user management and password changes.
35 lines
922 B
TypeScript
35 lines
922 B
TypeScript
import { randomUUID } from 'node:crypto'
|
|
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises'
|
|
import { join } from 'node:path'
|
|
|
|
const KEY_PATTERN = /^[0-9a-f-]{36}\.[a-z]{3,4}$/
|
|
|
|
/** Stores uploaded files on local disk under random names. */
|
|
export class FileStorage {
|
|
readonly dir: string
|
|
|
|
constructor(dir: string) {
|
|
this.dir = dir
|
|
}
|
|
|
|
async save(data: Uint8Array, extension: string): Promise<string> {
|
|
await mkdir(this.dir, { recursive: true })
|
|
const key = `${randomUUID()}.${extension}`
|
|
await writeFile(this.path(key), data, { flag: 'wx' })
|
|
return key
|
|
}
|
|
|
|
read(key: string): Promise<Buffer> {
|
|
return readFile(this.path(key))
|
|
}
|
|
|
|
async remove(key: string): Promise<void> {
|
|
await rm(this.path(key), { force: true })
|
|
}
|
|
|
|
private path(key: string) {
|
|
if (!KEY_PATTERN.test(key)) throw new Error(`Invalid storage key: ${key}`)
|
|
return join(this.dir, key)
|
|
}
|
|
}
|