fix: 复制和代理
This commit is contained in:
parent
ef1e8aef5c
commit
df9ac99ef2
@ -7,7 +7,6 @@ import { ChatItemType } from '@/types/chat';
|
|||||||
import { encode } from 'gpt-token-utils';
|
import { encode } from 'gpt-token-utils';
|
||||||
import { getOpenAIApi } from '@/service/utils/chat';
|
import { getOpenAIApi } from '@/service/utils/chat';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { UserModelSchema } from '@/types/mongoSchema';
|
|
||||||
|
|
||||||
/* 密码加密 */
|
/* 密码加密 */
|
||||||
export const hashPassword = (psw: string) => {
|
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 是否还有余额 */
|
/* 判断 apikey 是否还有余额 */
|
||||||
export const checkKeyGrant = async (apiKey: string) => {
|
export const checkKeyGrant = async (apiKey: string) => {
|
||||||
const grant = await axios.get('https://api.openai.com/dashboard/billing/credit_grants', {
|
const grant = await axios.get('https://api.openai.com/dashboard/billing/credit_grants', {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${apiKey}`
|
Authorization: `Bearer ${apiKey}`
|
||||||
}
|
},
|
||||||
|
httpsAgent
|
||||||
});
|
});
|
||||||
console.log(grant.data?.total_available);
|
|
||||||
if (grant.data?.total_available <= 0.2) {
|
if (grant.data?.total_available <= 0.2) {
|
||||||
return false;
|
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 截断 */
|
/* tokens 截断 */
|
||||||
export const openaiChatFilter = (prompts: ChatItemType[], maxTokens: number) => {
|
export const openaiChatFilter = (prompts: ChatItemType[], maxTokens: number) => {
|
||||||
let res: ChatItemType[] = [];
|
let res: ChatItemType[] = [];
|
||||||
|
|||||||
@ -14,25 +14,22 @@ export const useCopyData = () => {
|
|||||||
if (navigator.clipboard) {
|
if (navigator.clipboard) {
|
||||||
await navigator.clipboard.writeText(data);
|
await navigator.clipboard.writeText(data);
|
||||||
} else {
|
} else {
|
||||||
const textarea = document.createElement('textarea');
|
throw new Error('');
|
||||||
textarea.value = data;
|
|
||||||
document.body.appendChild(textarea);
|
|
||||||
textarea.select();
|
|
||||||
document.execCommand('copy');
|
|
||||||
document.body.removeChild(textarea);
|
|
||||||
}
|
}
|
||||||
toast({
|
|
||||||
title,
|
|
||||||
status: 'success',
|
|
||||||
duration: 1000
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error->', error);
|
const textarea = document.createElement('textarea');
|
||||||
toast({
|
textarea.value = data;
|
||||||
title: '复制失败',
|
document.body.appendChild(textarea);
|
||||||
status: 'error'
|
textarea.select();
|
||||||
});
|
document.execCommand('copy');
|
||||||
|
document.body.removeChild(textarea);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title,
|
||||||
|
status: 'success',
|
||||||
|
duration: 1000
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user