🔄Update: 删除加密逻辑
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"crypto-js": "^4.2.0",
|
||||
"vue": "^3.5.22"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -50,7 +50,6 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { decrypt } from '../utils/encryption'
|
||||
|
||||
// 响应式数据
|
||||
const userInput = ref('')
|
||||
@@ -143,7 +142,13 @@ const sendMessage = async () => {
|
||||
const callAIPlatform = async (platformId, apiKey, endpoint, message) => {
|
||||
try {
|
||||
// 发送请求到后端API
|
||||
const response = await fetch('/api/chat', {
|
||||
// console.log(JSON.stringify({
|
||||
// platformId,
|
||||
// apiKey,
|
||||
// endpoint,
|
||||
// message
|
||||
// }))
|
||||
const response = await fetch('http://localhost:8080/api/chat', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
@@ -154,7 +159,8 @@ const callAIPlatform = async (platformId, apiKey, endpoint, message) => {
|
||||
endpoint,
|
||||
message
|
||||
})
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`)
|
||||
|
||||
@@ -61,7 +61,6 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { encrypt } from '../utils/encryption'
|
||||
|
||||
// 厂商配置预设
|
||||
const platforms = [
|
||||
@@ -151,13 +150,10 @@ const saveConfig = () => {
|
||||
return
|
||||
}
|
||||
|
||||
// 加密密钥
|
||||
const encryptedKey = encrypt(apiKey.value)
|
||||
|
||||
// 构造配置对象
|
||||
const config = {
|
||||
id: selectedPlatform.value,
|
||||
apiKey: encryptedKey,
|
||||
apiKey: apiKey.value,
|
||||
endpoint: endpoint.value
|
||||
}
|
||||
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
// AES-256 加密/解密工具
|
||||
// 注意:这是一个简化版本,实际生产环境应使用更安全的加密库
|
||||
|
||||
import CryptoJS from 'crypto-js'
|
||||
|
||||
// 密钥(在实际应用中应使用更安全的方式管理)
|
||||
const SECRET_KEY = 'ai-api-tool-secret-key-2025'
|
||||
|
||||
/**
|
||||
* 加密函数
|
||||
* @param {string} text - 要加密的文本
|
||||
* @returns {string} - 加密后的文本
|
||||
*/
|
||||
export function encrypt(text) {
|
||||
try {
|
||||
return CryptoJS.AES.encrypt(text, SECRET_KEY).toString()
|
||||
} catch (error) {
|
||||
console.error('加密失败:', error)
|
||||
throw new Error('加密失败')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密函数
|
||||
* @param {string} encryptedText - 要解密的文本
|
||||
* @returns {string} - 解密后的文本
|
||||
*/
|
||||
export function decrypt(encryptedText) {
|
||||
try {
|
||||
const bytes = CryptoJS.AES.decrypt(encryptedText, SECRET_KEY)
|
||||
return bytes.toString(CryptoJS.enc.Utf8)
|
||||
} catch (error) {
|
||||
console.error('解密失败:', error)
|
||||
throw new Error('解密失败')
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user