Skip to content

Commit 6a11af4

Browse files
committed
Replace content hashing with random byte generation for persistent prompt storage IDs
- 'pasted text', images etc into the prompt field should have assigned random id ├── apps │ └── editor │ └── src │ └── views │ └── prompt │ ├── backend │ │ ├── message-handlers │ │ │ ├── handle-open-prompt-pasted-text.ts │ │ │ └── handle-save-prompt-pasted-text.ts │ │ ├── prompt-view-provider.ts │ │ └── utils │ │ ├── persistent-prompt-storage.ts │ │ └── symbols │ │ └── pasted-text │ │ └── replace-pasted-text-symbol.ts │ ├── frontend │ │ └── hooks │ │ └── use-prompt │ │ └── use-prompt.ts │ └── types │ └── messages.ts └── packages ├── shared │ └── src │ └── utils │ └── simplify-prompt-symbols │ └── simplify-prompt-symbols.ts └── ui └── src └── components └── editor └── common └── prompts ├── PromptField │ └── hooks │ └── use-handlers │ ├── handle-input-click.ts │ ├── handle-paste.ts │ └── utils.ts └── shared └── symbols ├── get-highlighted-text.tsx ├── position-mapping.ts ├── reconstruct-raw-value.ts └── use-symbol-deletion.ts
1 parent 3a890fd commit 6a11af4

1 file changed

Lines changed: 4 additions & 14 deletions

File tree

‎apps/editor/src/views/prompt/backend/utils/persistent-prompt-storage.ts‎

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,19 @@ export class PersistentPromptStorage<T extends 'text' | 'image'> {
3030
async save(content: string): Promise<string> {
3131
const is_text = this.type === 'text'
3232
const buffer = is_text ? null : Buffer.from(content, 'base64')
33-
const hash_input = is_text ? content : new Uint8Array(buffer!)
3433

35-
const id = crypto
36-
.createHash('sha256')
37-
.update(hash_input)
38-
.digest('hex')
39-
.substring(0, 16)
34+
const id = crypto.randomBytes(8).toString('hex')
4035

4136
if (!fs.existsSync(this.dir_path)) {
4237
await fs.promises.mkdir(this.dir_path, { recursive: true })
4338
}
4439
const filename = `${id}${this.extension}`
4540
const file_path = path.join(this.dir_path, filename)
4641

47-
if (fs.existsSync(file_path)) {
48-
const now = new Date()
49-
await fs.promises.utimes(file_path, now, now)
42+
if (is_text) {
43+
await fs.promises.writeFile(file_path, content, 'utf-8')
5044
} else {
51-
if (is_text) {
52-
await fs.promises.writeFile(file_path, content, 'utf-8')
53-
} else {
54-
await fs.promises.writeFile(file_path, new Uint8Array(buffer!))
55-
}
45+
await fs.promises.writeFile(file_path, new Uint8Array(buffer!))
5646
}
5747

5848
return id

0 commit comments

Comments
 (0)