( hash: string, content: string, )
| 35 | * can use it immediately without waiting for the async disk write. |
| 36 | */ |
| 37 | export async function storePastedText( |
| 38 | hash: string, |
| 39 | content: string, |
| 40 | ): Promise<void> { |
| 41 | try { |
| 42 | const dir = getPasteStoreDir() |
| 43 | await mkdir(dir, { recursive: true }) |
| 44 | |
| 45 | const pastePath = getPastePath(hash) |
| 46 | |
| 47 | // Content-addressable: same hash = same content, so overwriting is safe |
| 48 | await writeFile(pastePath, content, { encoding: 'utf8', mode: 0o600 }) |
| 49 | logForDebugging(`Stored paste ${hash} to ${pastePath}`) |
| 50 | } catch (error) { |
| 51 | logForDebugging(`Failed to store paste: ${error}`) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Retrieve pasted text content by its hash. |
no test coverage detected