Skip to content

Commit

Permalink
Update index.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
GptForCN committed Mar 26, 2023
1 parent 4135efd commit 40af804
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SHA256 } from 'crypto-js'
import type { AxiosProgressEvent, GenericAbortSignal } from 'axios'
import { post } from '@/utils/request'
import { useSettingStore } from '@/store'
Expand Down Expand Up @@ -28,18 +29,28 @@ export function fetchChatAPIProcess<T = any>(
onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void },
) {
const settingStore = useSettingStore()

const dataParams = { prompt: params.prompt, options: params.options, systemMessage: settingStore.systemMessage }
// Sign GPTFORCN
const json = JSON.stringify(dataParams)
const timenow = Date.now()
const unSignStr = `appId=${import.meta.env.VITE_APP_API_ID}&appSecret=${import.meta.env.VITE_APP_API_SECRET}&data=${json}&timestamp=${timenow}`
return post<T>({
url: '/chat-process',
data: { prompt: params.prompt, options: params.options, systemMessage: settingStore.systemMessage },
data: dataParams,
headers: { appId: import.meta.env.VITE_APP_API_ID, timestamp: timenow, sign: SHA256(unSignStr).toString() },
signal: params.signal,
onDownloadProgress: params.onDownloadProgress,
})
}

export function fetchSession<T>() {
// Sign GPTFORCN
const timenow = Date.now()
const unSignStr = `appId=${import.meta.env.VITE_APP_API_ID}&appSecret=${import.meta.env.VITE_APP_API_SECRET}&data=&timestamp=${timenow}`

return post<T>({
url: '/session',
headers: { appId: import.meta.env.VITE_APP_API_ID, timestamp: timenow, sign: SHA256(unSignStr).toString() },
})
}

Expand Down

0 comments on commit 40af804

Please sign in to comment.