Move writeComposerPaste out of electron/main.ts into composer-paste.ts (placement gate: no new behaviour appended to the facade). Lower the conversion threshold from 10k to 3k characters so a pasted stack trace or log excerpt already becomes a chip. Trim the policy tests to two invariants (strict threshold boundary; chip size label is byte-based) and drop vendor references from code comments.
21 lines
893 B
TypeScript
21 lines
893 B
TypeScript
import crypto from 'node:crypto'
|
|
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
|
|
/**
|
|
* Persist a large plain-text paste as a `.txt` file the composer can attach
|
|
* as a chip instead of flooding the input. The renderer never chooses the
|
|
* path: the file lands in a Desktop-managed directory with a generated name,
|
|
* mirroring how `writeComposerImage` handles pasted images.
|
|
*/
|
|
export async function writeComposerPaste(userDataDir: string, text: string): Promise<string> {
|
|
const dir = path.join(userDataDir, 'composer-pastes')
|
|
await fs.promises.mkdir(dir, { recursive: true })
|
|
const stamp = new Date().toISOString().replace(/[:.]/g, '-').replace('T', '_').replace('Z', '')
|
|
const random = crypto.randomBytes(3).toString('hex')
|
|
const filePath = path.join(dir, `pasted_content_${stamp}_${random}.txt`)
|
|
await fs.promises.writeFile(filePath, text, 'utf8')
|
|
|
|
return filePath
|
|
}
|