Spaces:
Paused
Paused
| // utils.js - Utility functions | |
| export const Utils = { | |
| /** | |
| * Get or create a unique machine ID stored in localStorage | |
| * @returns {string} Machine ID | |
| */ | |
| getMachineId() { | |
| let machineId = localStorage.getItem('MachineId'); | |
| if (!machineId) { | |
| machineId = 'dev-' + crypto.randomUUID(); | |
| localStorage.setItem('MachineId', machineId); | |
| } | |
| return machineId; | |
| }, | |
| /** | |
| * Generate a unique session ID | |
| * @returns {string} Session ID | |
| */ | |
| generateSessionId() { | |
| return 'session-' + crypto.randomUUID(); | |
| }, | |
| /** | |
| * Generate a unique conversation ID | |
| * @returns {string} Conversation ID | |
| */ | |
| generateConversationId() { | |
| return 'conversation-' + crypto.randomUUID(); | |
| }, | |
| /** | |
| * Remove a file from a file input element | |
| * @param {HTMLInputElement} fileInput - The file input element | |
| * @param {File} fileToRemove - The file to remove | |
| */ | |
| removeFileFromInput(fileInput, fileToRemove) { | |
| // File inputs are read-only. We have to update them | |
| // by assigning a new value instead of filtering out | |
| // directly files we do not want anymore. | |
| const dt = new DataTransfer(); | |
| const { files } = fileInput; | |
| for (let i = 0; i < files.length; i++) { | |
| const file = files[i]; | |
| if (file !== fileToRemove) { | |
| dt.items.add(file); | |
| } | |
| } | |
| fileInput.files = dt.files; | |
| } | |
| }; |