From 734c40bbde796fffe02d10f6302864b7aa69e444 Mon Sep 17 00:00:00 2001 From: binary-husky Date: Sun, 22 Dec 2024 14:01:22 +0800 Subject: [PATCH] fix non-localhost javascript error --- themes/common.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/themes/common.js b/themes/common.js index 65af2cdf..b14275c3 100644 --- a/themes/common.js +++ b/themes/common.js @@ -938,10 +938,27 @@ function gpt_academic_gradio_saveload( } } +function generateUUID() { + // Generate a random number and convert it to a hexadecimal string + function randomHexDigit() { + return Math.floor((1 + Math.random()) * 0x10000).toString(16).slice(1); + } + + // Construct the UUID using the randomHexDigit function + return ( + randomHexDigit() + randomHexDigit() + '-' + + randomHexDigit() + '-' + + '4' + randomHexDigit().slice(0, 3) + '-' + // Version 4 UUID + ((Math.floor(Math.random() * 4) + 8).toString(16)) + randomHexDigit().slice(0, 3) + '-' + + randomHexDigit() + randomHexDigit() + randomHexDigit() + ); +} + function update_conversation_metadata() { // Create a conversation UUID and timestamp try { - const conversationId = crypto.randomUUID(); + const conversationId = generateUUID(); + console.log('Create conversation ID:', conversationId); const timestamp = new Date().toISOString(); const conversationData = { id: conversationId,