Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
df9ac99e
authored
Mar 31, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 复制和代理
parent
ef1e8aef
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
30 deletions
+26
-30
src/service/utils/tools.ts
+13
-14
src/utils/tools.ts
+13
-16
No files found.
src/service/utils/tools.ts
View file @
df9ac99e
...
@@ -7,7 +7,6 @@ import { ChatItemType } from '@/types/chat';
...
@@ -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> => {
...
@@ -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) => {
...
@@ -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
[]
=
[];
...
...
src/utils/tools.ts
View file @
df9ac99e
...
@@ -14,25 +14,22 @@ export const useCopyData = () => {
...
@@ -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
});
}
}
};
};
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment