From 02011e9954925de7eb6343467dd5b7c8f9d59b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=AB=E9=81=97=E5=BF=98=E7=9A=84=E8=AE=B0=E5=BF=86?= <32097237+YIWANG-sketch@users.noreply.github.com> Date: Sat, 10 Aug 2024 22:43:16 +0800 Subject: [PATCH] add random name --- provider.mjs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/provider.mjs b/provider.mjs index 721f6c0..441fc8e 100644 --- a/provider.mjs +++ b/provider.mjs @@ -342,23 +342,23 @@ class YouProvider { console.log("Custom mode is disabled, using default mode."); } + // 生成随机文件名 + function generateRandomFileName(length) { + const validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-'; + let result = ''; + for (let i = 0; i < length; i++) { + result += validChars.charAt(Math.floor(Math.random() * validChars.length)); + } + return result + '.docx'; + } + + // 生成随机长度(6-16)的文件名 + const randomFileName = generateRandomFileName(Math.floor(Math.random() * 11) + 6); + console.log(`Generated random file name: ${randomFileName}`); + // 试算用户消息长度 if (encodeURIComponent(JSON.stringify(userMessage)).length + encodeURIComponent(userQuery).length > 32000) { console.log("Using file upload mode"); - - // 生成随机文件名的函数 - function generateRandomFileName(length) { - const validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-'; - let result = ''; - for (let i = 0; i < length; i++) { - result += validChars.charAt(Math.floor(Math.random() * validChars.length)); - } - return result + '.docx'; - } - - // 生成随机长度(6-16)的文件名 - const randomFileName = generateRandomFileName(Math.floor(Math.random() * 11) + 6); - console.log(`Generated random file name: ${randomFileName}`); // 应用格式化逻辑 const formattedMessages = formatMessages(messages); @@ -456,7 +456,7 @@ class YouProvider { req_param.append("domain", "youchat"); req_param.append("mkt", "ja-JP"); if (uploadedFile) - req_param.append("userFiles", JSON.stringify([{ user_filename: "messages.docx", filename: uploadedFile.filename, size: messageBuffer.length }])); + req_param.append("userFiles", JSON.stringify([{ user_filename: randomFileName, filename: uploadedFile.filename, size: messageBuffer.length }])); req_param.append("chat", JSON.stringify(userMessage)); var url = "https://you.com/api/streamingSearch?" + req_param.toString(); console.log("正在发送请求");