fix: 复制和代理

This commit is contained in:
archer
2023-03-31 12:17:08 +08:00
parent ef1e8aef5c
commit df9ac99ef2
2 changed files with 26 additions and 30 deletions

View File

@@ -7,7 +7,6 @@ import { ChatItemType } from '@/types/chat';
import { encode } from 'gpt-token-utils';
import { getOpenAIApi } from '@/service/utils/chat';
import axios from 'axios';
import { UserModelSchema } from '@/types/mongoSchema';
/* 密码加密 */
export const hashPassword = (psw: string) => {
@@ -46,14 +45,25 @@ export const authToken = (token?: string): Promise<string> => {
});
};
/* 代理 */
export const httpsAgent =
process.env.AXIOS_PROXY_HOST && process.env.AXIOS_PROXY_PORT
? tunnel.httpsOverHttp({
proxy: {
host: process.env.AXIOS_PROXY_HOST,
port: +process.env.AXIOS_PROXY_PORT
}
})
: undefined;
/* 判断 apikey 是否还有余额 */
export const checkKeyGrant = async (apiKey: string) => {
const grant = await axios.get('https://api.openai.com/dashboard/billing/credit_grants', {
headers: {
Authorization: `Bearer ${apiKey}`
}
},
httpsAgent
});
console.log(grant.data?.total_available);
if (grant.data?.total_available <= 0.2) {
return false;
}
@@ -128,17 +138,6 @@ export const getOpenApiKey = async (userId: string) => {
};
};
/* 代理 */
export const httpsAgent =
process.env.AXIOS_PROXY_HOST && process.env.AXIOS_PROXY_PORT
? tunnel.httpsOverHttp({
proxy: {
host: process.env.AXIOS_PROXY_HOST,
port: +process.env.AXIOS_PROXY_PORT
}
})
: undefined;
/* tokens 截断 */
export const openaiChatFilter = (prompts: ChatItemType[], maxTokens: number) => {
let res: ChatItemType[] = [];

View File

@@ -14,25 +14,22 @@ export const useCopyData = () => {
if (navigator.clipboard) {
await navigator.clipboard.writeText(data);
} else {
const textarea = document.createElement('textarea');
textarea.value = data;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
throw new Error('');
}
toast({
title,
status: 'success',
duration: 1000
});
} catch (error) {
console.log('error->', error);
toast({
title: '复制失败',
status: 'error'
});
const textarea = document.createElement('textarea');
textarea.value = data;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
}
toast({
title,
status: 'success',
duration: 1000
});
}
};
};