feat: add aihubmix oauth

This commit is contained in:
kangfenmao
2025-02-07 22:27:28 +08:00
parent bf15207a2e
commit f62caba4e9
12 changed files with 56 additions and 21 deletions
+8
View File
@@ -18,6 +18,8 @@ import { registerShortcuts, unregisterAllShortcuts } from './services/ShortcutSe
import { TrayService } from './services/TrayService'
import { windowService } from './services/WindowService'
import { getResourcePath } from './utils'
import { decrypt } from './utils/aes'
import { encrypt } from './utils/aes'
import { compress, decompress } from './utils/zip'
const fileManager = new FileStorage()
@@ -199,4 +201,10 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
ipcMain.handle('miniwindow:hide', () => windowService.hideMiniWindow())
ipcMain.handle('miniwindow:close', () => windowService.closeMiniWindow())
ipcMain.handle('miniwindow:toggle', () => windowService.toggleMiniWindow())
// aes
ipcMain.handle('aes:encrypt', (_, text: string, secretKey: string, iv: string) => encrypt(text, secretKey, iv))
ipcMain.handle('aes:decrypt', (_, encryptedData: string, iv: string, secretKey: string) =>
decrypt(encryptedData, iv, secretKey)
)
}
+1 -1
View File
@@ -163,7 +163,7 @@ export class WindowService {
mainWindow.webContents.setWindowOpenHandler((details) => {
const { url } = details
const oauthProviderUrls = ['https://account.siliconflow.cn/oauth']
const oauthProviderUrls = ['https://account.siliconflow.cn/oauth', 'https://aihubmix.com/oauth']
if (oauthProviderUrls.some((link) => url.startsWith(link))) {
return {
+5 -8
View File
@@ -1,22 +1,19 @@
import * as crypto from 'crypto'
// 定义密钥和初始化向量(IV
const secretKey = 'kDQvWz5slot3syfucoo53X6KKsEUJoeFikpiUWRJTLIo3zcUPpFvEa009kK13KCr'
const iv = Buffer.from('Cherry Studio', 'hex')
// 加密函数
export function encrypt(text: string): { iv: string; encryptedData: string } {
const cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(secretKey), iv)
export function encrypt(text: string, secretKey: string, iv: string): { iv: string; encryptedData: string } {
const _iv = Buffer.from(iv, 'hex')
const cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(secretKey), _iv)
let encrypted = cipher.update(text, 'utf8', 'hex')
encrypted += cipher.final('hex')
return {
iv: iv.toString('hex'),
iv: _iv.toString('hex'),
encryptedData: encrypted
}
}
// 解密函数
export function decrypt(encryptedData: string, iv: string): string {
export function decrypt(encryptedData: string, iv: string, secretKey: string): string {
const decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(secretKey), Buffer.from(iv, 'hex'))
let decrypted = decipher.update(encryptedData, 'hex', 'utf8')
decrypted += decipher.final('utf8')