Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07cac12dac | ||
|
|
4f3bfd1d4a | ||
|
|
451a456f58 | ||
|
|
5fe1e20e4a | ||
|
|
54381ed2e2 | ||
|
|
ffd4da91cf | ||
|
|
a2ffa3cb3a | ||
|
|
ecc2afd164 | ||
|
|
45cbfbf002 | ||
|
|
a689406b28 | ||
|
|
2ff82b1249 | ||
|
|
8e1b4edc91 |
41
CHANGELOG.md
41
CHANGELOG.md
@@ -1,3 +1,44 @@
|
|||||||
|
## v2.10.0
|
||||||
|
|
||||||
|
`2023-03-07`
|
||||||
|
|
||||||
|
- 老规矩,手动部署的同学需要删除 `node_modules` 安装包重新安装降低出错概率,其他部署不受影响,但是可能会有缓存问题。
|
||||||
|
- 虽然说了更新放缓,但是 `issues` 不看, `PR` 不改我睡不着,我的邮箱从每天早上`8`点到凌晨`12`永远在滴滴滴,所以求求各位,超时的`issues`自己关闭下哈,我真的需要缓冲一下。
|
||||||
|
- 演示图片请看最后
|
||||||
|
|
||||||
|
## Feature
|
||||||
|
- 添加权限功能,用法:`service/.env` 中的 `AUTH_SECRET_KEY` 变量添加密码
|
||||||
|
- 感谢 [PeterDaveHello](https://github.com/Chanzhaoyu/chatgpt-web/pull/348) 添加「繁体中文」翻译
|
||||||
|
- 感谢 [GermMC](https://github.com/Chanzhaoyu/chatgpt-web/pull/369) 添加聊天记录导入、导出、清空的功能
|
||||||
|
- 感谢 [CornerSkyless](https://github.com/Chanzhaoyu/chatgpt-web/pull/374) 添加会话保存为本地图片的功能
|
||||||
|
|
||||||
|
|
||||||
|
## Enhancement
|
||||||
|
- 感谢 [CornerSkyless](https://github.com/Chanzhaoyu/chatgpt-web/pull/363) 添加 `ctrl+enter` 发送消息
|
||||||
|
- 现在新消息只有在结束了之后才滚动到底部,而不是之前的强制性
|
||||||
|
- 优化部分代码
|
||||||
|
|
||||||
|
## BugFix
|
||||||
|
- 转义状态码前端显示,防止直接暴露 `key`(我可能需要更多的状态码补充)
|
||||||
|
|
||||||
|
## Other
|
||||||
|
- 更新依赖到最新
|
||||||
|
|
||||||
|
## 演示
|
||||||
|
> 不是界面最新效果,有美化改动
|
||||||
|
|
||||||
|
权限
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
聊天记录导出
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
保存图片到本地
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## v2.9.3
|
## v2.9.3
|
||||||
|
|
||||||
`2023-03-06`
|
`2023-03-06`
|
||||||
|
|||||||
12
README.en.md
12
README.en.md
@@ -84,6 +84,12 @@ For all parameter variables, check [here](#docker-parameter-example) or see:
|
|||||||
|
|
||||||
[✓] Formatting and beautifying code-like message types
|
[✓] Formatting and beautifying code-like message types
|
||||||
|
|
||||||
|
[✓] Access rights control
|
||||||
|
|
||||||
|
[✓] Data import and export
|
||||||
|
|
||||||
|
[✓] Save message to local image
|
||||||
|
|
||||||
[✓] Multilingual interface
|
[✓] Multilingual interface
|
||||||
|
|
||||||
[✓] Interface themes
|
[✓] Interface themes
|
||||||
@@ -163,6 +169,7 @@ pnpm dev
|
|||||||
- `OPENAI_ACCESS_TOKEN` one of two, `OPENAI_API_KEY` takes precedence when both are present
|
- `OPENAI_ACCESS_TOKEN` one of two, `OPENAI_API_KEY` takes precedence when both are present
|
||||||
- `OPENAI_API_BASE_URL` optional, available when `OPENAI_API_KEY` is set
|
- `OPENAI_API_BASE_URL` optional, available when `OPENAI_API_KEY` is set
|
||||||
- `API_REVERSE_PROXY` optional, available when `OPENAI_ACCESS_TOKEN` is set [Reference](#introduction)
|
- `API_REVERSE_PROXY` optional, available when `OPENAI_ACCESS_TOKEN` is set [Reference](#introduction)
|
||||||
|
- `AUTH_SECRET_KEY` Access Password,optional
|
||||||
- `TIMEOUT_MS` timeout, in milliseconds, optional
|
- `TIMEOUT_MS` timeout, in milliseconds, optional
|
||||||
- `SOCKS_PROXY_HOST` optional, effective with SOCKS_PROXY_PORT
|
- `SOCKS_PROXY_HOST` optional, effective with SOCKS_PROXY_PORT
|
||||||
- `SOCKS_PROXY_PORT` optional, effective with SOCKS_PROXY_HOST
|
- `SOCKS_PROXY_PORT` optional, effective with SOCKS_PROXY_HOST
|
||||||
@@ -205,6 +212,8 @@ services:
|
|||||||
OPENAI_API_BASE_URL: xxxx
|
OPENAI_API_BASE_URL: xxxx
|
||||||
# reverse proxy, optional
|
# reverse proxy, optional
|
||||||
API_REVERSE_PROXY: xxx
|
API_REVERSE_PROXY: xxx
|
||||||
|
# access password,optional
|
||||||
|
AUTH_SECRET_KEY: xxx
|
||||||
# timeout, in milliseconds, optional
|
# timeout, in milliseconds, optional
|
||||||
TIMEOUT_MS: 60000
|
TIMEOUT_MS: 60000
|
||||||
# socks proxy, optional, effective with SOCKS_PROXY_PORT
|
# socks proxy, optional, effective with SOCKS_PROXY_PORT
|
||||||
@@ -223,7 +232,8 @@ The `OPENAI_API_BASE_URL` is optional and only used when setting the `OPENAI_API
|
|||||||
| Environment Variable | Required | Description |
|
| Environment Variable | Required | Description |
|
||||||
| -------------------- | -------- | ------------------------------------------------------------------------------------------------- |
|
| -------------------- | -------- | ------------------------------------------------------------------------------------------------- |
|
||||||
| `PORT` | Required | Default: `3002` |
|
| `PORT` | Required | Default: `3002` |
|
||||||
| `TIMEOUT_MS` | Optional | Timeout in milliseconds. |
|
| `AUTH_SECRET_KEY` | Optional | access password |
|
||||||
|
| `TIMEOUT_MS` | Optional | Timeout in milliseconds |
|
||||||
| `OPENAI_API_KEY` | Optional | Required for `OpenAI API`. `apiKey` can be obtained from [here](https://platform.openai.com/overview). |
|
| `OPENAI_API_KEY` | Optional | Required for `OpenAI API`. `apiKey` can be obtained from [here](https://platform.openai.com/overview). |
|
||||||
| `OPENAI_ACCESS_TOKEN`| Optional | Required for `Web API`. `accessToken` can be obtained from [here](https://chat.openai.com/api/auth/session).|
|
| `OPENAI_ACCESS_TOKEN`| Optional | Required for `Web API`. `accessToken` can be obtained from [here](https://chat.openai.com/api/auth/session).|
|
||||||
| `OPENAI_API_BASE_URL` | Optional, only for `OpenAI API` | API endpoint. |
|
| `OPENAI_API_BASE_URL` | Optional, only for `OpenAI API` | API endpoint. |
|
||||||
|
|||||||
14
README.md
14
README.md
@@ -83,6 +83,12 @@ API_REVERSE_PROXY=
|
|||||||
|
|
||||||
[✓] 对代码等消息类型的格式化美化处理
|
[✓] 对代码等消息类型的格式化美化处理
|
||||||
|
|
||||||
|
[✓] 访问权限控制
|
||||||
|
|
||||||
|
[✓] 数据导入、导出
|
||||||
|
|
||||||
|
[✓] 保存消息到本地图片
|
||||||
|
|
||||||
[✓] 界面多语言
|
[✓] 界面多语言
|
||||||
|
|
||||||
[✓] 界面主题
|
[✓] 界面主题
|
||||||
@@ -161,6 +167,7 @@ pnpm dev
|
|||||||
- `OPENAI_ACCESS_TOKEN` 二选一,同时存在时,`OPENAI_API_KEY` 优先
|
- `OPENAI_ACCESS_TOKEN` 二选一,同时存在时,`OPENAI_API_KEY` 优先
|
||||||
- `OPENAI_API_BASE_URL` 可选,设置 `OPENAI_API_KEY` 时可用
|
- `OPENAI_API_BASE_URL` 可选,设置 `OPENAI_API_KEY` 时可用
|
||||||
- `API_REVERSE_PROXY` 可选,设置 `OPENAI_ACCESS_TOKEN` 时可用 [参考](#介绍)
|
- `API_REVERSE_PROXY` 可选,设置 `OPENAI_ACCESS_TOKEN` 时可用 [参考](#介绍)
|
||||||
|
- `AUTH_SECRET_KEY` 访问权限密钥,可选
|
||||||
- `TIMEOUT_MS` 超时,单位毫秒,可选
|
- `TIMEOUT_MS` 超时,单位毫秒,可选
|
||||||
- `SOCKS_PROXY_HOST` 可选,和 SOCKS_PROXY_PORT 一起时生效
|
- `SOCKS_PROXY_HOST` 可选,和 SOCKS_PROXY_PORT 一起时生效
|
||||||
- `SOCKS_PROXY_PORT` 可选,和 SOCKS_PROXY_HOST 一起时生效
|
- `SOCKS_PROXY_PORT` 可选,和 SOCKS_PROXY_HOST 一起时生效
|
||||||
@@ -203,6 +210,8 @@ services:
|
|||||||
OPENAI_API_BASE_URL: xxxx
|
OPENAI_API_BASE_URL: xxxx
|
||||||
# 反向代理,可选
|
# 反向代理,可选
|
||||||
API_REVERSE_PROXY: xxx
|
API_REVERSE_PROXY: xxx
|
||||||
|
# 访问权限密钥,可选
|
||||||
|
AUTH_SECRET_KEY: xxx
|
||||||
# 超时,单位毫秒,可选
|
# 超时,单位毫秒,可选
|
||||||
TIMEOUT_MS: 60000
|
TIMEOUT_MS: 60000
|
||||||
# Socks代理,可选,和 SOCKS_PROXY_PORT 一起时生效
|
# Socks代理,可选,和 SOCKS_PROXY_PORT 一起时生效
|
||||||
@@ -219,8 +228,9 @@ services:
|
|||||||
|
|
||||||
| 环境变量名称 | 必填 | 备注 |
|
| 环境变量名称 | 必填 | 备注 |
|
||||||
| --------------------- | ---------------------- | -------------------------------------------------------------------------------------------------- |
|
| --------------------- | ---------------------- | -------------------------------------------------------------------------------------------------- |
|
||||||
| `PORT` | 必填 | 默认 `3002` |
|
| `PORT` | 必填 | 默认 `3002`
|
||||||
| `TIMEOUT_MS` | 可选 | 超时时间,单位毫秒, |
|
| `AUTH_SECRET_KEY` | 可选 | 访问权限密钥 |
|
||||||
|
| `TIMEOUT_MS` | 可选 | 超时时间,单位毫秒 |
|
||||||
| `OPENAI_API_KEY` | `OpenAI API` 二选一 | 使用 `OpenAI API` 所需的 `apiKey` [(获取 apiKey)](https://platform.openai.com/overview) |
|
| `OPENAI_API_KEY` | `OpenAI API` 二选一 | 使用 `OpenAI API` 所需的 `apiKey` [(获取 apiKey)](https://platform.openai.com/overview) |
|
||||||
| `OPENAI_ACCESS_TOKEN` | `Web API` 二选一 | 使用 `Web API` 所需的 `accessToken` [(获取 accessToken)](https://chat.openai.com/api/auth/session) |
|
| `OPENAI_ACCESS_TOKEN` | `Web API` 二选一 | 使用 `Web API` 所需的 `accessToken` [(获取 accessToken)](https://chat.openai.com/api/auth/session) |
|
||||||
| `OPENAI_API_BASE_URL` | 可选,`OpenAI API` 时可用 | `API`接口地址 |
|
| `OPENAI_API_BASE_URL` | 可选,`OpenAI API` 时可用 | `API`接口地址 |
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ services:
|
|||||||
OPENAI_API_BASE_URL: xxxx
|
OPENAI_API_BASE_URL: xxxx
|
||||||
# 反向代理,可选
|
# 反向代理,可选
|
||||||
API_REVERSE_PROXY: xxx
|
API_REVERSE_PROXY: xxx
|
||||||
|
# 访问权限密钥,可选
|
||||||
|
AUTH_SECRET_KEY: xxx
|
||||||
# 超时,单位毫秒,可选
|
# 超时,单位毫秒,可选
|
||||||
TIMEOUT_MS: 60000
|
TIMEOUT_MS: 60000
|
||||||
# Socks代理,可选,和 SOCKS_PROXY_PORT 一起时生效
|
# Socks代理,可选,和 SOCKS_PROXY_PORT 一起时生效
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "chatgpt-web",
|
"name": "chatgpt-web",
|
||||||
"version": "2.9.3",
|
"version": "2.10.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "ChatGPT Web",
|
"description": "ChatGPT Web",
|
||||||
"author": "ChenZhaoYu <chenzhaoyu1994@gmail.com>",
|
"author": "ChenZhaoYu <chenzhaoyu1994@gmail.com>",
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
"@traptitech/markdown-it-katex": "^3.6.0",
|
"@traptitech/markdown-it-katex": "^3.6.0",
|
||||||
"@vueuse/core": "^9.13.0",
|
"@vueuse/core": "^9.13.0",
|
||||||
"highlight.js": "^11.7.0",
|
"highlight.js": "^11.7.0",
|
||||||
|
"html2canvas": "^1.4.1",
|
||||||
"katex": "^0.16.4",
|
"katex": "^0.16.4",
|
||||||
"markdown-it": "^13.0.1",
|
"markdown-it": "^13.0.1",
|
||||||
"naive-ui": "^2.34.3",
|
"naive-ui": "^2.34.3",
|
||||||
|
|||||||
33
pnpm-lock.yaml
generated
33
pnpm-lock.yaml
generated
@@ -17,6 +17,7 @@ specifiers:
|
|||||||
crypto-js: ^4.1.1
|
crypto-js: ^4.1.1
|
||||||
eslint: ^8.35.0
|
eslint: ^8.35.0
|
||||||
highlight.js: ^11.7.0
|
highlight.js: ^11.7.0
|
||||||
|
html2canvas: ^1.4.1
|
||||||
husky: ^8.0.3
|
husky: ^8.0.3
|
||||||
katex: ^0.16.4
|
katex: ^0.16.4
|
||||||
less: ^4.1.3
|
less: ^4.1.3
|
||||||
@@ -39,6 +40,7 @@ dependencies:
|
|||||||
'@traptitech/markdown-it-katex': 3.6.0
|
'@traptitech/markdown-it-katex': 3.6.0
|
||||||
'@vueuse/core': 9.13.0_vue@3.2.47
|
'@vueuse/core': 9.13.0_vue@3.2.47
|
||||||
highlight.js: 11.7.0
|
highlight.js: 11.7.0
|
||||||
|
html2canvas: 1.4.1
|
||||||
katex: 0.16.4
|
katex: 0.16.4
|
||||||
markdown-it: 13.0.1
|
markdown-it: 13.0.1
|
||||||
naive-ui: 2.34.3_vue@3.2.47
|
naive-ui: 2.34.3_vue@3.2.47
|
||||||
@@ -1345,6 +1347,11 @@ packages:
|
|||||||
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
|
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/base64-arraybuffer/1.0.2:
|
||||||
|
resolution: {integrity: sha512-I3yl4r9QB5ZRY3XuJVEPfc2XhZO6YweFPI+UovAzn+8/hb3oJ6lnysaFcjVpkCPfVWFUDvoZ8kmVDP7WyRtYtQ==}
|
||||||
|
engines: {node: '>= 0.6.0'}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/binary-extensions/2.2.0:
|
/binary-extensions/2.2.0:
|
||||||
resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==}
|
resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
@@ -1666,6 +1673,12 @@ packages:
|
|||||||
resolution: {integrity: sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==}
|
resolution: {integrity: sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/css-line-break/2.1.0:
|
||||||
|
resolution: {integrity: sha512-FHcKFCZcAha3LwfVBhCQbW2nCNbkZXn7KVUJcsT5/P8YmfsVja0FMPJr0B903j/E69HUphKiV9iQArX8SDYA4w==}
|
||||||
|
dependencies:
|
||||||
|
utrie: 1.0.2
|
||||||
|
dev: false
|
||||||
|
|
||||||
/css-render/0.15.12:
|
/css-render/0.15.12:
|
||||||
resolution: {integrity: sha512-eWzS66patiGkTTik+ipO9qNGZ+uNuGyTmnz6/+EJIiFg8+3yZRpnMwgFo8YdXhQRsiePzehnusrxVvugNjXzbw==}
|
resolution: {integrity: sha512-eWzS66patiGkTTik+ipO9qNGZ+uNuGyTmnz6/+EJIiFg8+3yZRpnMwgFo8YdXhQRsiePzehnusrxVvugNjXzbw==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -2757,6 +2770,14 @@ packages:
|
|||||||
lru-cache: 6.0.0
|
lru-cache: 6.0.0
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/html2canvas/1.4.1:
|
||||||
|
resolution: {integrity: sha512-fPU6BHNpsyIhr8yyMpTLLxAbkaK8ArIBcmZIRiBLiDhjeqvXolaEmDGmELFuX9I4xDcaKKcJl+TKZLqruBbmWA==}
|
||||||
|
engines: {node: '>=8.0.0'}
|
||||||
|
dependencies:
|
||||||
|
css-line-break: 2.1.0
|
||||||
|
text-segmentation: 1.0.3
|
||||||
|
dev: false
|
||||||
|
|
||||||
/htmlparser2/8.0.1:
|
/htmlparser2/8.0.1:
|
||||||
resolution: {integrity: sha512-4lVbmc1diZC7GUJQtRQ5yBAeUCL1exyMwmForWkRLnwyzWBFxN633SALPMGYaWZvKe9j1pRZJpauvmxENSp/EA==}
|
resolution: {integrity: sha512-4lVbmc1diZC7GUJQtRQ5yBAeUCL1exyMwmForWkRLnwyzWBFxN633SALPMGYaWZvKe9j1pRZJpauvmxENSp/EA==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -4488,6 +4509,12 @@ packages:
|
|||||||
engines: {node: '>=0.10'}
|
engines: {node: '>=0.10'}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/text-segmentation/1.0.3:
|
||||||
|
resolution: {integrity: sha512-iOiPUo/BGnZ6+54OsWxZidGCsdU8YbE4PSpdPinp7DeMtUJNJBoJ/ouUSTJjHkh1KntHaltHl/gDs2FC4i5+Nw==}
|
||||||
|
dependencies:
|
||||||
|
utrie: 1.0.2
|
||||||
|
dev: false
|
||||||
|
|
||||||
/text-table/0.2.0:
|
/text-table/0.2.0:
|
||||||
resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==}
|
resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==}
|
||||||
dev: true
|
dev: true
|
||||||
@@ -4670,6 +4697,12 @@ packages:
|
|||||||
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
|
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/utrie/1.0.2:
|
||||||
|
resolution: {integrity: sha512-1MLa5ouZiOmQzUbjbu9VmjLzn1QLXBhwpUa7kdLUQK+KQ5KA9I1vk5U4YHe/X2Ch7PYnJfWuWT+VbuxbGwljhw==}
|
||||||
|
dependencies:
|
||||||
|
base64-arraybuffer: 1.0.2
|
||||||
|
dev: false
|
||||||
|
|
||||||
/v8-compile-cache-lib/3.0.1:
|
/v8-compile-cache-lib/3.0.1:
|
||||||
resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==}
|
resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ API_REVERSE_PROXY=
|
|||||||
# timeout
|
# timeout
|
||||||
TIMEOUT_MS=100000
|
TIMEOUT_MS=100000
|
||||||
|
|
||||||
|
# Secret key
|
||||||
|
AUTH_SECRET_KEY=
|
||||||
|
|
||||||
# Socks Proxy Host
|
# Socks Proxy Host
|
||||||
SOCKS_PROXY_HOST=
|
SOCKS_PROXY_HOST=
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
"common:cleanup": "rimraf node_modules && rimraf pnpm-lock.yaml"
|
"common:cleanup": "rimraf node_modules && rimraf pnpm-lock.yaml"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chatgpt": "^5.0.7",
|
"chatgpt": "^5.0.8",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"esno": "^0.16.3",
|
"esno": "^0.16.3",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
|
|||||||
8
service/pnpm-lock.yaml
generated
8
service/pnpm-lock.yaml
generated
@@ -4,7 +4,7 @@ specifiers:
|
|||||||
'@antfu/eslint-config': ^0.35.3
|
'@antfu/eslint-config': ^0.35.3
|
||||||
'@types/express': ^4.17.17
|
'@types/express': ^4.17.17
|
||||||
'@types/node': ^18.14.6
|
'@types/node': ^18.14.6
|
||||||
chatgpt: ^5.0.7
|
chatgpt: ^5.0.8
|
||||||
dotenv: ^16.0.3
|
dotenv: ^16.0.3
|
||||||
eslint: ^8.35.0
|
eslint: ^8.35.0
|
||||||
esno: ^0.16.3
|
esno: ^0.16.3
|
||||||
@@ -17,7 +17,7 @@ specifiers:
|
|||||||
typescript: ^4.9.5
|
typescript: ^4.9.5
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
chatgpt: 5.0.7
|
chatgpt: 5.0.8
|
||||||
dotenv: 16.0.3
|
dotenv: 16.0.3
|
||||||
esno: 0.16.3
|
esno: 0.16.3
|
||||||
express: 4.18.2
|
express: 4.18.2
|
||||||
@@ -902,8 +902,8 @@ packages:
|
|||||||
resolution: {integrity: sha512-mKKUkUbhPpQlCOfIuZkvSEgktjPFIsZKRRbC6KWVEMvlzblj3i3asQv5ODsrwt0N3pHAEvjP8KTQPHkp0+6jOg==}
|
resolution: {integrity: sha512-mKKUkUbhPpQlCOfIuZkvSEgktjPFIsZKRRbC6KWVEMvlzblj3i3asQv5ODsrwt0N3pHAEvjP8KTQPHkp0+6jOg==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/chatgpt/5.0.7:
|
/chatgpt/5.0.8:
|
||||||
resolution: {integrity: sha512-wy69++JDNS0xKi+6rP+HDOByXBafQIVynHnlQw09apuDntGSKfwBRY902N8Q7/ZFU/XET+8NpJiio2iI69IWYw==}
|
resolution: {integrity: sha512-Bjh7Y15QIsZ+SkQvbbZGymv1PGxkZ7X1vwqAwvyqaMMhbipU4kxht/GL62VCxhoUCXPwxTfScbFeNFtNldgqaw==}
|
||||||
engines: {node: '>=14'}
|
engines: {node: '>=14'}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|||||||
@@ -7,6 +7,17 @@ import fetch from 'node-fetch'
|
|||||||
import { sendResponse } from '../utils'
|
import { sendResponse } from '../utils'
|
||||||
import type { ApiModel, ChatContext, ChatGPTUnofficialProxyAPIOptions, ModelConfig } from '../types'
|
import type { ApiModel, ChatContext, ChatGPTUnofficialProxyAPIOptions, ModelConfig } from '../types'
|
||||||
|
|
||||||
|
const ErrorCodeMessage: Record<string, string> = {
|
||||||
|
400: '[OpenAI] 模型的最大上下文长度是4096个令牌,请减少信息的长度。| This model\'s maximum context length is 4096 tokens.',
|
||||||
|
401: '[OpenAI] 提供错误的API密钥 | Incorrect API key provided',
|
||||||
|
403: '[OpenAI] 服务器拒绝访问,请稍后再试 | Server refused to access, please try again later',
|
||||||
|
429: '[OpenAI] 服务器限流,请稍后再试 | Server was limited, please try again later',
|
||||||
|
502: '[OpenAI] 错误的网关 | Bad Gateway',
|
||||||
|
503: '[OpenAI] 服务器繁忙,请稍后再试 | Server is busy, please try again later',
|
||||||
|
504: '[OpenAI] 网关超时 | Gateway Time-out',
|
||||||
|
500: '[OpenAI] 服务器繁忙,请稍后再试 | Internal Server Error',
|
||||||
|
}
|
||||||
|
|
||||||
dotenv.config()
|
dotenv.config()
|
||||||
|
|
||||||
const timeoutMs: number = !isNaN(+process.env.TIMEOUT_MS) ? +process.env.TIMEOUT_MS : 30 * 1000
|
const timeoutMs: number = !isNaN(+process.env.TIMEOUT_MS) ? +process.env.TIMEOUT_MS : 30 * 1000
|
||||||
@@ -98,8 +109,11 @@ async function chatReplyProcess(
|
|||||||
return sendResponse({ type: 'Success', data: response })
|
return sendResponse({ type: 'Success', data: response })
|
||||||
}
|
}
|
||||||
catch (error: any) {
|
catch (error: any) {
|
||||||
global.console.error(error)
|
const code = error.statusCode
|
||||||
return sendResponse({ type: 'Fail', message: error.message })
|
global.console.log(error)
|
||||||
|
if (Reflect.has(ErrorCodeMessage, code))
|
||||||
|
return sendResponse({ type: 'Fail', message: ErrorCodeMessage[code] })
|
||||||
|
return sendResponse({ type: 'Fail', message: error.message ?? 'Please check the back-end console' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import express from 'express'
|
import express from 'express'
|
||||||
import type { ChatContext, ChatMessage } from './chatgpt'
|
import type { ChatContext, ChatMessage } from './chatgpt'
|
||||||
import { chatConfig, chatReplyProcess } from './chatgpt'
|
import { chatConfig, chatReplyProcess } from './chatgpt'
|
||||||
|
import { auth } from './middleware/auth'
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
@@ -15,7 +16,7 @@ app.all('*', (_, res, next) => {
|
|||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|
||||||
router.post('/chat-process', async (req, res) => {
|
router.post('/chat-process', auth, async (req, res) => {
|
||||||
res.setHeader('Content-type', 'application/octet-stream')
|
res.setHeader('Content-type', 'application/octet-stream')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -44,6 +45,33 @@ router.post('/config', async (req, res) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
router.post('/session', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const AUTH_SECRET_KEY = process.env.AUTH_SECRET_KEY
|
||||||
|
const hasAuth = typeof AUTH_SECRET_KEY === 'string' && AUTH_SECRET_KEY.length > 0
|
||||||
|
res.send({ status: 'Success', message: '', data: { auth: hasAuth } })
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
res.send({ status: 'Fail', message: error.message, data: null })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
router.post('/verify', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { token } = req.body as { token: string }
|
||||||
|
if (!token)
|
||||||
|
throw new Error('Secret key is empty')
|
||||||
|
|
||||||
|
if (process.env.AUTH_SECRET_KEY !== token)
|
||||||
|
throw new Error('密钥无效 | Secret key is invalid')
|
||||||
|
|
||||||
|
res.send({ status: 'Success', message: 'Verify successfully', data: null })
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
res.send({ status: 'Fail', message: error.message, data: null })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
app.use('', router)
|
app.use('', router)
|
||||||
app.use('/api', router)
|
app.use('/api', router)
|
||||||
|
|
||||||
|
|||||||
19
service/src/middleware/auth.ts
Normal file
19
service/src/middleware/auth.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
const auth = async (req, res, next) => {
|
||||||
|
const AUTH_SECRET_KEY = process.env.AUTH_SECRET_KEY
|
||||||
|
if (typeof AUTH_SECRET_KEY === 'string' && AUTH_SECRET_KEY.length > 0) {
|
||||||
|
try {
|
||||||
|
const Authorization = req.header('Authorization')
|
||||||
|
if (!Authorization || Authorization.replace('Bearer ', '').trim() !== AUTH_SECRET_KEY.trim())
|
||||||
|
throw new Error('Error: 无访问权限 | No access rights')
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
res.send({ status: 'Unauthorized', message: error.message ?? 'Please authenticate.', data: null })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { auth }
|
||||||
@@ -33,3 +33,16 @@ export function fetchChatAPIProcess<T = any>(
|
|||||||
onDownloadProgress: params.onDownloadProgress,
|
onDownloadProgress: params.onDownloadProgress,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function fetchSession<T>() {
|
||||||
|
return post<T>({
|
||||||
|
url: '/session',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fetchVerify<T>(token: string) {
|
||||||
|
return post<T>({
|
||||||
|
url: '/verify',
|
||||||
|
data: { token },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,18 +1,13 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { NButton, NInput, useMessage } from 'naive-ui'
|
import { NButton, NInput, NPopconfirm, useMessage } from 'naive-ui'
|
||||||
import type { Language, Theme } from '@/store/modules/app/helper'
|
import type { Language, Theme } from '@/store/modules/app/helper'
|
||||||
import { SvgIcon } from '@/components/common'
|
import { SvgIcon } from '@/components/common'
|
||||||
import { useAppStore, useUserStore } from '@/store'
|
import { useAppStore, useUserStore } from '@/store'
|
||||||
import type { UserInfo } from '@/store/modules/user/helper'
|
import type { UserInfo } from '@/store/modules/user/helper'
|
||||||
|
import { getCurrentDate } from '@/utils/functions'
|
||||||
import { t } from '@/locales'
|
import { t } from '@/locales'
|
||||||
|
|
||||||
interface Emit {
|
|
||||||
(event: 'update'): void
|
|
||||||
}
|
|
||||||
|
|
||||||
const emit = defineEmits<Emit>()
|
|
||||||
|
|
||||||
const appStore = useAppStore()
|
const appStore = useAppStore()
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
|
|
||||||
@@ -56,7 +51,8 @@ const themeOptions: { label: string; key: Theme; icon: string }[] = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
const languageOptions: { label: string; key: Language; value: Language }[] = [
|
const languageOptions: { label: string; key: Language; value: Language }[] = [
|
||||||
{ label: '中文', key: 'zh-CN', value: 'zh-CN' },
|
{ label: '简体中文', key: 'zh-CN', value: 'zh-CN' },
|
||||||
|
{ label: '繁體中文', key: 'zh-TW', value: 'zh-TW' },
|
||||||
{ label: 'English', key: 'en-US', value: 'en-US' },
|
{ label: 'English', key: 'en-US', value: 'en-US' },
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -68,7 +64,56 @@ function updateUserInfo(options: Partial<UserInfo>) {
|
|||||||
function handleReset() {
|
function handleReset() {
|
||||||
userStore.resetUserInfo()
|
userStore.resetUserInfo()
|
||||||
ms.success(t('common.success'))
|
ms.success(t('common.success'))
|
||||||
emit('update')
|
window.location.reload()
|
||||||
|
}
|
||||||
|
|
||||||
|
function exportData(): void {
|
||||||
|
const date = getCurrentDate()
|
||||||
|
const data: string = localStorage.getItem('chatStorage') || '{}'
|
||||||
|
const jsonString: string = JSON.stringify(JSON.parse(data), null, 2)
|
||||||
|
const blob: Blob = new Blob([jsonString], { type: 'application/json' })
|
||||||
|
const url: string = URL.createObjectURL(blob)
|
||||||
|
const link: HTMLAnchorElement = document.createElement('a')
|
||||||
|
link.href = url
|
||||||
|
link.download = `chat-store_${date}.json`
|
||||||
|
document.body.appendChild(link)
|
||||||
|
link.click()
|
||||||
|
document.body.removeChild(link)
|
||||||
|
}
|
||||||
|
|
||||||
|
function importData(event: Event): void {
|
||||||
|
const target = event.target as HTMLInputElement
|
||||||
|
if (!target || !target.files)
|
||||||
|
return
|
||||||
|
|
||||||
|
const file: File = target.files[0]
|
||||||
|
if (!file)
|
||||||
|
return
|
||||||
|
|
||||||
|
const reader: FileReader = new FileReader()
|
||||||
|
reader.onload = () => {
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(reader.result as string)
|
||||||
|
localStorage.setItem('chatStorage', JSON.stringify(data))
|
||||||
|
ms.success(t('common.success'))
|
||||||
|
location.reload()
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
ms.error(t('common.invalidFileFormat'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.readAsText(file)
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearData(): void {
|
||||||
|
localStorage.removeItem('chatStorage')
|
||||||
|
location.reload()
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleImportButtonClick(): void {
|
||||||
|
const fileInput = document.getElementById('fileInput') as HTMLElement
|
||||||
|
if (fileInput)
|
||||||
|
fileInput.click()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -102,44 +147,75 @@ function handleReset() {
|
|||||||
{{ $t('common.save') }}
|
{{ $t('common.save') }}
|
||||||
</NButton>
|
</NButton>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex items-center space-x-4">
|
<div class="flex items-center space-x-4">
|
||||||
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.resetUserInfo') }}</span>
|
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.chatHistory') }}</span>
|
||||||
<NButton text type="primary" @click="handleReset">
|
|
||||||
{{ $t('common.reset') }}
|
<div class="flex flex-wrap items-center gap-4">
|
||||||
</NButton>
|
<NButton size="small" @click="exportData">
|
||||||
|
<template #icon>
|
||||||
|
<SvgIcon icon="ri:download-2-fill" />
|
||||||
|
</template>
|
||||||
|
{{ $t('common.export') }}
|
||||||
|
</NButton>
|
||||||
|
|
||||||
|
<input id="fileInput" type="file" style="display:none" @change="importData">
|
||||||
|
<NButton size="small" @click="handleImportButtonClick">
|
||||||
|
<template #icon>
|
||||||
|
<SvgIcon icon="ri:upload-2-fill" />
|
||||||
|
</template>
|
||||||
|
{{ $t('common.import') }}
|
||||||
|
</NButton>
|
||||||
|
|
||||||
|
<NPopconfirm placement="bottom" @positive-click="clearData">
|
||||||
|
<template #trigger>
|
||||||
|
<NButton size="small">
|
||||||
|
<template #icon>
|
||||||
|
<SvgIcon icon="ri:close-circle-line" />
|
||||||
|
</template>
|
||||||
|
{{ $t('common.clear') }}
|
||||||
|
</NButton>
|
||||||
|
</template>
|
||||||
|
{{ $t('chat.clearHistoryConfirm') }}
|
||||||
|
</NPopconfirm>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center space-x-4">
|
<div class="flex items-center space-x-4">
|
||||||
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.theme') }}</span>
|
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.theme') }}</span>
|
||||||
<div class="flex items-center space-x-4">
|
<div class="flex flex-wrap items-center gap-4">
|
||||||
<template v-for="item of themeOptions" :key="item.key">
|
<template v-for="item of themeOptions" :key="item.key">
|
||||||
<a
|
<NButton
|
||||||
class="flex items-center justify-center h-8 px-4 border rounded-md cursor-pointer dark:border-neutral-700"
|
size="small"
|
||||||
:class="item.key === theme && ['bg-[#4ca85e]', 'border-[#4ca85e]', 'text-white']"
|
:type="item.key === theme ? 'primary' : undefined"
|
||||||
@click="appStore.setTheme(item.key)"
|
@click="appStore.setTheme(item.key)"
|
||||||
>
|
>
|
||||||
<span class="text-xl">
|
<template #icon>
|
||||||
<SvgIcon :icon="item.icon" />
|
<SvgIcon :icon="item.icon" />
|
||||||
</span>
|
</template>
|
||||||
</a>
|
</NButton>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center space-x-4">
|
<div class="flex items-center space-x-4">
|
||||||
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.language') }}</span>
|
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.language') }}</span>
|
||||||
<div class="flex items-center space-x-4">
|
<div class="flex flex-wrap items-center gap-4">
|
||||||
<template v-for="item of languageOptions" :key="item.key">
|
<template v-for="item of languageOptions" :key="item.key">
|
||||||
<a
|
<NButton
|
||||||
class="flex items-center justify-center h-8 px-4 border rounded-md cursor-pointer dark:border-neutral-700"
|
size="small"
|
||||||
:class="item.key === language && ['bg-[#4ca85e]', 'border-[#4ca85e]', 'text-white']"
|
:type="item.key === language ? 'primary' : undefined"
|
||||||
@click="appStore.setLanguage(item.key)"
|
@click="appStore.setLanguage(item.key)"
|
||||||
>
|
>
|
||||||
<span class="text-sm">
|
{{ item.label }}
|
||||||
{{ item.label }}
|
</NButton>
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex items-center space-x-4">
|
||||||
|
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.resetUserInfo') }}</span>
|
||||||
|
<NButton size="small" @click="handleReset">
|
||||||
|
{{ $t('common.reset') }}
|
||||||
|
</NButton>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ interface Emit {
|
|||||||
|
|
||||||
const active = ref('General')
|
const active = ref('General')
|
||||||
|
|
||||||
const reload = ref(false)
|
|
||||||
|
|
||||||
const show = computed({
|
const show = computed({
|
||||||
get() {
|
get() {
|
||||||
return props.visible
|
return props.visible
|
||||||
@@ -29,18 +27,11 @@ const show = computed({
|
|||||||
emit('update:visible', visible)
|
emit('update:visible', visible)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
function handleReload() {
|
|
||||||
reload.value = true
|
|
||||||
setTimeout(() => {
|
|
||||||
reload.value = false
|
|
||||||
}, 0)
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<NModal v-model:show="show" :auto-focus="false">
|
<NModal v-model:show="show" :auto-focus="false">
|
||||||
<NCard role="dialog" aria-modal="true" :bordered="false" style="width: 100%; max-width: 640px">
|
<NCard role="dialog" aria-modal="true" :bordered="false" style="width: 95%; max-width: 640px">
|
||||||
<NTabs v-model:value="active" type="line" animated>
|
<NTabs v-model:value="active" type="line" animated>
|
||||||
<NTabPane name="General" tab="General">
|
<NTabPane name="General" tab="General">
|
||||||
<template #tab>
|
<template #tab>
|
||||||
@@ -48,7 +39,7 @@ function handleReload() {
|
|||||||
<span class="ml-2">{{ $t('setting.general') }}</span>
|
<span class="ml-2">{{ $t('setting.general') }}</span>
|
||||||
</template>
|
</template>
|
||||||
<div class="min-h-[100px]">
|
<div class="min-h-[100px]">
|
||||||
<General v-if="!reload" @update="handleReload" />
|
<General />
|
||||||
</div>
|
</div>
|
||||||
</NTabPane>
|
</NTabPane>
|
||||||
<NTabPane name="Config" tab="Config">
|
<NTabPane name="Config" tab="Config">
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import { enUS, zhCN } from 'naive-ui'
|
import { enUS, zhCN, zhTW } from 'naive-ui'
|
||||||
import { useAppStore } from '@/store'
|
import { useAppStore } from '@/store'
|
||||||
import { setLocale } from '@/locales'
|
import { setLocale } from '@/locales'
|
||||||
|
|
||||||
@@ -14,6 +14,9 @@ export function useLanguage() {
|
|||||||
case 'zh-CN':
|
case 'zh-CN':
|
||||||
setLocale('zh-CN')
|
setLocale('zh-CN')
|
||||||
return zhCN
|
return zhCN
|
||||||
|
case 'zh-TW':
|
||||||
|
setLocale('zh-TW')
|
||||||
|
return zhTW
|
||||||
default:
|
default:
|
||||||
setLocale('zh-CN')
|
setLocale('zh-CN')
|
||||||
return enUS
|
return enUS
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 19 KiB |
5
src/icons/403.vue
Normal file
5
src/icons/403.vue
Normal file
File diff suppressed because one or more lines are too long
5
src/icons/500.vue
Normal file
5
src/icons/500.vue
Normal file
File diff suppressed because one or more lines are too long
@@ -3,12 +3,17 @@ export default {
|
|||||||
delete: 'Delete',
|
delete: 'Delete',
|
||||||
save: 'Save',
|
save: 'Save',
|
||||||
reset: 'Reset',
|
reset: 'Reset',
|
||||||
|
export: 'Export',
|
||||||
|
import: 'Import',
|
||||||
|
clear: 'Clear',
|
||||||
yes: 'Yes',
|
yes: 'Yes',
|
||||||
no: 'No',
|
no: 'No',
|
||||||
noData: 'No Data',
|
noData: 'No Data',
|
||||||
wrong: 'Something went wrong, please try again later.',
|
wrong: 'Something went wrong, please try again later.',
|
||||||
success: 'Success',
|
success: 'Success',
|
||||||
failed: 'Failed',
|
failed: 'Failed',
|
||||||
|
verify: 'Verify',
|
||||||
|
unauthorizedTips: 'Unauthorized, please verify first.',
|
||||||
},
|
},
|
||||||
chat: {
|
chat: {
|
||||||
placeholder: 'Ask me anything...(Shift + Enter = line break)',
|
placeholder: 'Ask me anything...(Shift + Enter = line break)',
|
||||||
@@ -18,9 +23,14 @@ export default {
|
|||||||
copyCode: 'Copy Code',
|
copyCode: 'Copy Code',
|
||||||
clearChat: 'Clear Chat',
|
clearChat: 'Clear Chat',
|
||||||
clearChatConfirm: 'Are you sure to clear this chat?',
|
clearChatConfirm: 'Are you sure to clear this chat?',
|
||||||
|
exportImage: 'Export Image',
|
||||||
|
exportImageConfirm: 'Are you sure to export this chat to png?',
|
||||||
|
exportSuccess: 'Export Success',
|
||||||
|
exportFailed: 'Export Failed',
|
||||||
deleteMessage: 'Delete Message',
|
deleteMessage: 'Delete Message',
|
||||||
deleteMessageConfirm: 'Are you sure to delete this message?',
|
deleteMessageConfirm: 'Are you sure to delete this message?',
|
||||||
deleteHistoryConfirm: 'Are you sure to clear this history?',
|
deleteHistoryConfirm: 'Are you sure to clear this history?',
|
||||||
|
clearHistoryConfirm: 'Are you sure to clear chat history?',
|
||||||
},
|
},
|
||||||
setting: {
|
setting: {
|
||||||
setting: 'Setting',
|
setting: 'Setting',
|
||||||
@@ -30,6 +40,7 @@ export default {
|
|||||||
name: 'Name',
|
name: 'Name',
|
||||||
description: 'Description',
|
description: 'Description',
|
||||||
resetUserInfo: 'Reset UserInfo',
|
resetUserInfo: 'Reset UserInfo',
|
||||||
|
chatHistory: 'ChatHistory',
|
||||||
theme: 'Theme',
|
theme: 'Theme',
|
||||||
language: 'Language',
|
language: 'Language',
|
||||||
api: 'API',
|
api: 'API',
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import type { App } from 'vue'
|
import type { App } from 'vue'
|
||||||
import { createI18n } from 'vue-i18n'
|
import { createI18n } from 'vue-i18n'
|
||||||
import en from './en-US'
|
import enUS from './en-US'
|
||||||
import cn from './zh-CN'
|
import zhCN from './zh-CN'
|
||||||
|
import zhTW from './zh-TW'
|
||||||
import { useAppStoreWithOut } from '@/store/modules/app'
|
import { useAppStoreWithOut } from '@/store/modules/app'
|
||||||
import type { Language } from '@/store/modules/app/helper'
|
import type { Language } from '@/store/modules/app/helper'
|
||||||
|
|
||||||
@@ -14,8 +15,9 @@ const i18n = createI18n({
|
|||||||
fallbackLocale: 'en-US',
|
fallbackLocale: 'en-US',
|
||||||
allowComposition: true,
|
allowComposition: true,
|
||||||
messages: {
|
messages: {
|
||||||
'en-US': en,
|
'en-US': enUS,
|
||||||
'zh-CN': cn,
|
'zh-CN': zhCN,
|
||||||
|
'zh-TW': zhTW,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -3,24 +3,34 @@ export default {
|
|||||||
delete: '删除',
|
delete: '删除',
|
||||||
save: '保存',
|
save: '保存',
|
||||||
reset: '重置',
|
reset: '重置',
|
||||||
|
export: '导出',
|
||||||
|
import: '导入',
|
||||||
|
clear: '清空',
|
||||||
yes: '是',
|
yes: '是',
|
||||||
no: '否',
|
no: '否',
|
||||||
noData: '暂无数据',
|
noData: '暂无数据',
|
||||||
wrong: '好像出错了,请稍后再试。',
|
wrong: '好像出错了,请稍后再试。',
|
||||||
success: '操作成功',
|
success: '操作成功',
|
||||||
failed: '操作失败',
|
failed: '操作失败',
|
||||||
|
verify: '验证',
|
||||||
|
unauthorizedTips: '未经授权,请先进行验证。',
|
||||||
},
|
},
|
||||||
chat: {
|
chat: {
|
||||||
placeholder: '来说点什么...(Shift + Enter = 换行)',
|
placeholder: '来说点什么吧...(Shift + Enter = 换行)',
|
||||||
placeholderMobile: '来说点什么...',
|
placeholderMobile: '来说点什么...',
|
||||||
copy: '复制',
|
copy: '复制',
|
||||||
copied: '复制成功',
|
copied: '复制成功',
|
||||||
copyCode: '复制代码',
|
copyCode: '复制代码',
|
||||||
clearChat: '清空会话',
|
clearChat: '清空会话',
|
||||||
clearChatConfirm: '是否清空会话?',
|
clearChatConfirm: '是否清空会话?',
|
||||||
|
exportImage: '保存会话到图片',
|
||||||
|
exportImageConfirm: '是否将会话保存为图片?',
|
||||||
|
exportSuccess: '保存成功',
|
||||||
|
exportFailed: '保存失败',
|
||||||
deleteMessage: '删除消息',
|
deleteMessage: '删除消息',
|
||||||
deleteMessageConfirm: '是否删除此消息?',
|
deleteMessageConfirm: '是否删除此消息?',
|
||||||
deleteHistoryConfirm: '确定删除此记录?',
|
deleteHistoryConfirm: '确定删除此记录?',
|
||||||
|
clearHistoryConfirm: '确定清空聊天记录?',
|
||||||
},
|
},
|
||||||
setting: {
|
setting: {
|
||||||
setting: '设置',
|
setting: '设置',
|
||||||
@@ -30,6 +40,7 @@ export default {
|
|||||||
name: '名称',
|
name: '名称',
|
||||||
description: '描述',
|
description: '描述',
|
||||||
resetUserInfo: '重置用户信息',
|
resetUserInfo: '重置用户信息',
|
||||||
|
chatHistory: '聊天记录',
|
||||||
theme: '主题',
|
theme: '主题',
|
||||||
language: '语言',
|
language: '语言',
|
||||||
api: 'API',
|
api: 'API',
|
||||||
|
|||||||
50
src/locales/zh-TW.ts
Normal file
50
src/locales/zh-TW.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
export default {
|
||||||
|
common: {
|
||||||
|
delete: '刪除',
|
||||||
|
save: '儲存',
|
||||||
|
reset: '重設',
|
||||||
|
export: '匯出',
|
||||||
|
import: '匯入',
|
||||||
|
clear: '清除',
|
||||||
|
yes: '是',
|
||||||
|
no: '否',
|
||||||
|
noData: '暫無資料',
|
||||||
|
wrong: '好像出錯了,請稍後再試。',
|
||||||
|
success: '操作成功',
|
||||||
|
failed: '操作失敗',
|
||||||
|
verify: '驗證',
|
||||||
|
unauthorizedTips: '未經授權,請先進行驗證。',
|
||||||
|
},
|
||||||
|
chat: {
|
||||||
|
placeholder: '來說點什麼...(Shift + Enter = 換行)',
|
||||||
|
placeholderMobile: '來說點什麼...',
|
||||||
|
copy: '複製',
|
||||||
|
copied: '複製成功',
|
||||||
|
copyCode: '複製代碼',
|
||||||
|
clearChat: '清除對話',
|
||||||
|
clearChatConfirm: '是否清空對話?',
|
||||||
|
exportImage: '儲存對話為圖片',
|
||||||
|
exportImageConfirm: '是否將對話儲存為圖片?',
|
||||||
|
exportSuccess: '儲存成功',
|
||||||
|
exportFailed: '儲存失敗',
|
||||||
|
deleteMessage: '刪除訊息',
|
||||||
|
deleteMessageConfirm: '是否刪除此訊息?',
|
||||||
|
deleteHistoryConfirm: '確定刪除此紀錄?',
|
||||||
|
},
|
||||||
|
setting: {
|
||||||
|
setting: '設定',
|
||||||
|
general: '總覽',
|
||||||
|
config: '設定',
|
||||||
|
avatarLink: '頭貼連結',
|
||||||
|
name: '名稱',
|
||||||
|
description: '描述',
|
||||||
|
resetUserInfo: '重設使用者資訊',
|
||||||
|
chatHistory: '紀錄',
|
||||||
|
theme: '主題',
|
||||||
|
language: '語言',
|
||||||
|
api: 'API',
|
||||||
|
reverseProxy: '反向代理',
|
||||||
|
timeout: '逾時',
|
||||||
|
socks: 'Socks',
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { App } from 'vue'
|
import type { App } from 'vue'
|
||||||
import type { RouteRecordRaw } from 'vue-router'
|
import type { RouteRecordRaw } from 'vue-router'
|
||||||
import { createRouter, createWebHashHistory } from 'vue-router'
|
import { createRouter, createWebHashHistory } from 'vue-router'
|
||||||
|
import { setupPageGuard } from './permission'
|
||||||
import { ChatLayout } from '@/views/chat/layout'
|
import { ChatLayout } from '@/views/chat/layout'
|
||||||
|
|
||||||
const routes: RouteRecordRaw[] = [
|
const routes: RouteRecordRaw[] = [
|
||||||
@@ -18,18 +19,18 @@ const routes: RouteRecordRaw[] = [
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
|
||||||
path: '/403',
|
|
||||||
name: '403',
|
|
||||||
component: () => import('@/views/exception/403/index.vue'),
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
{
|
||||||
path: '/404',
|
path: '/404',
|
||||||
name: '404',
|
name: '404',
|
||||||
component: () => import('@/views/exception/404/index.vue'),
|
component: () => import('@/views/exception/404/index.vue'),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
path: '/500',
|
||||||
|
name: '500',
|
||||||
|
component: () => import('@/views/exception/500/index.vue'),
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
path: '/:pathMatch(.*)*',
|
path: '/:pathMatch(.*)*',
|
||||||
name: 'notFound',
|
name: 'notFound',
|
||||||
@@ -43,6 +44,8 @@ export const router = createRouter({
|
|||||||
scrollBehavior: () => ({ left: 0, top: 0 }),
|
scrollBehavior: () => ({ left: 0, top: 0 }),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
setupPageGuard(router)
|
||||||
|
|
||||||
export async function setupRouter(app: App) {
|
export async function setupRouter(app: App) {
|
||||||
app.use(router)
|
app.use(router)
|
||||||
await router.isReady()
|
await router.isReady()
|
||||||
|
|||||||
25
src/router/permission.ts
Normal file
25
src/router/permission.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import type { Router } from 'vue-router'
|
||||||
|
import { useAuthStoreWithout } from '@/store/modules/auth'
|
||||||
|
|
||||||
|
export function setupPageGuard(router: Router) {
|
||||||
|
router.beforeEach(async (from, to, next) => {
|
||||||
|
const authStore = useAuthStoreWithout()
|
||||||
|
if (!authStore.session) {
|
||||||
|
try {
|
||||||
|
const data = await authStore.getSession()
|
||||||
|
if (String(data.auth) === 'false' && authStore.token)
|
||||||
|
authStore.removeToken()
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
if (from.path !== '/500')
|
||||||
|
next({ name: '500' })
|
||||||
|
else
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ const LOCAL_NAME = 'appSetting'
|
|||||||
|
|
||||||
export type Theme = 'light' | 'dark' | 'auto'
|
export type Theme = 'light' | 'dark' | 'auto'
|
||||||
|
|
||||||
export type Language = 'zh-CN' | 'en-US'
|
export type Language = 'zh-CN' | 'zh-TW' | 'en-US'
|
||||||
|
|
||||||
export interface AppState {
|
export interface AppState {
|
||||||
siderCollapsed: boolean
|
siderCollapsed: boolean
|
||||||
|
|||||||
15
src/store/modules/auth/helper.ts
Normal file
15
src/store/modules/auth/helper.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { ss } from '@/utils/storage'
|
||||||
|
|
||||||
|
const LOCAL_NAME = 'SECRET_TOKEN'
|
||||||
|
|
||||||
|
export function getToken() {
|
||||||
|
return ss.get(LOCAL_NAME)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setToken(token: string) {
|
||||||
|
return ss.set(LOCAL_NAME, token)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeToken() {
|
||||||
|
return ss.remove(LOCAL_NAME)
|
||||||
|
}
|
||||||
43
src/store/modules/auth/index.ts
Normal file
43
src/store/modules/auth/index.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { getToken, removeToken, setToken } from './helper'
|
||||||
|
import { store } from '@/store'
|
||||||
|
import { fetchSession } from '@/api'
|
||||||
|
|
||||||
|
export interface AuthState {
|
||||||
|
token: string | undefined
|
||||||
|
session: { auth: boolean } | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useAuthStore = defineStore('auth-store', {
|
||||||
|
state: (): AuthState => ({
|
||||||
|
token: getToken(),
|
||||||
|
session: null,
|
||||||
|
}),
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
async getSession() {
|
||||||
|
try {
|
||||||
|
const { data } = await fetchSession<{ auth: boolean }>()
|
||||||
|
this.session = { ...data }
|
||||||
|
return Promise.resolve(data)
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
return Promise.reject(error)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
setToken(token: string) {
|
||||||
|
this.token = token
|
||||||
|
setToken(token)
|
||||||
|
},
|
||||||
|
|
||||||
|
removeToken() {
|
||||||
|
this.token = undefined
|
||||||
|
removeToken()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export function useAuthStoreWithout() {
|
||||||
|
return useAuthStore(store)
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
export * from './app'
|
export * from './app'
|
||||||
export * from './chat'
|
export * from './chat'
|
||||||
export * from './user'
|
export * from './user'
|
||||||
|
export * from './auth'
|
||||||
|
|||||||
7
src/utils/functions/index.ts
Normal file
7
src/utils/functions/index.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export function getCurrentDate() {
|
||||||
|
const date = new Date()
|
||||||
|
const day = date.getDate()
|
||||||
|
const month = date.getMonth() + 1
|
||||||
|
const year = date.getFullYear()
|
||||||
|
return `${year}-${month}-${day}`
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import axios, { type AxiosResponse } from 'axios'
|
import axios, { type AxiosResponse } from 'axios'
|
||||||
|
import { useAuthStore } from '@/store'
|
||||||
|
|
||||||
const service = axios.create({
|
const service = axios.create({
|
||||||
baseURL: import.meta.env.VITE_GLOB_API_URL,
|
baseURL: import.meta.env.VITE_GLOB_API_URL,
|
||||||
@@ -6,6 +7,9 @@ const service = axios.create({
|
|||||||
|
|
||||||
service.interceptors.request.use(
|
service.interceptors.request.use(
|
||||||
(config) => {
|
(config) => {
|
||||||
|
const token = useAuthStore().token
|
||||||
|
if (token)
|
||||||
|
config.headers.Authorization = `Bearer ${token}`
|
||||||
return config
|
return config
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { AxiosProgressEvent, AxiosResponse, GenericAbortSignal } from 'axios'
|
import type { AxiosProgressEvent, AxiosResponse, GenericAbortSignal } from 'axios'
|
||||||
import request from './axios'
|
import request from './axios'
|
||||||
|
import { useAuthStore } from '@/store'
|
||||||
|
|
||||||
export interface HttpOption {
|
export interface HttpOption {
|
||||||
url: string
|
url: string
|
||||||
@@ -22,9 +23,16 @@ function http<T = any>(
|
|||||||
{ url, data, method, headers, onDownloadProgress, signal, beforeRequest, afterRequest }: HttpOption,
|
{ url, data, method, headers, onDownloadProgress, signal, beforeRequest, afterRequest }: HttpOption,
|
||||||
) {
|
) {
|
||||||
const successHandler = (res: AxiosResponse<Response<T>>) => {
|
const successHandler = (res: AxiosResponse<Response<T>>) => {
|
||||||
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
if (res.data.status === 'Success' || typeof res.data === 'string')
|
if (res.data.status === 'Success' || typeof res.data === 'string')
|
||||||
return res.data
|
return res.data
|
||||||
|
|
||||||
|
if (res.data.status === 'Unauthorized') {
|
||||||
|
authStore.removeToken()
|
||||||
|
window.location.reload()
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.reject(res.data)
|
return Promise.reject(res.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
<script setup lang='ts'>
|
<script setup lang='ts'>
|
||||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { NButton, NInput, useDialog } from 'naive-ui'
|
import { NButton, NInput, useDialog, useMessage } from 'naive-ui'
|
||||||
|
import html2canvas from 'html2canvas'
|
||||||
import { Message } from './components'
|
import { Message } from './components'
|
||||||
import { useScroll } from './hooks/useScroll'
|
import { useScroll } from './hooks/useScroll'
|
||||||
import { useChat } from './hooks/useChat'
|
import { useChat } from './hooks/useChat'
|
||||||
@@ -16,6 +17,7 @@ let controller = new AbortController()
|
|||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const dialog = useDialog()
|
const dialog = useDialog()
|
||||||
|
const ms = useMessage()
|
||||||
|
|
||||||
const chatStore = useChatStore()
|
const chatStore = useChatStore()
|
||||||
|
|
||||||
@@ -118,6 +120,7 @@ async function onConversation() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
scrollToBottom()
|
||||||
}
|
}
|
||||||
catch (error: any) {
|
catch (error: any) {
|
||||||
const errorMessage = error?.message ?? t('common.wrong')
|
const errorMessage = error?.message ?? t('common.wrong')
|
||||||
@@ -268,6 +271,46 @@ async function onRegenerate(index: number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleExport() {
|
||||||
|
if (loading.value)
|
||||||
|
return
|
||||||
|
|
||||||
|
const d = dialog.warning({
|
||||||
|
title: t('chat.exportImage'),
|
||||||
|
content: t('chat.exportImageConfirm'),
|
||||||
|
positiveText: t('common.yes'),
|
||||||
|
negativeText: t('common.no'),
|
||||||
|
onPositiveClick: async () => {
|
||||||
|
try {
|
||||||
|
d.loading = true
|
||||||
|
const ele = document.getElementById('image-wrapper')
|
||||||
|
const canvas = await html2canvas(ele as HTMLDivElement)
|
||||||
|
const imgUrl = canvas.toDataURL('image/png')
|
||||||
|
const tempLink = document.createElement('a')
|
||||||
|
tempLink.style.display = 'none'
|
||||||
|
tempLink.href = imgUrl
|
||||||
|
tempLink.setAttribute('download', 'chat-shot.png')
|
||||||
|
if (typeof tempLink.download === 'undefined')
|
||||||
|
tempLink.setAttribute('target', '_blank')
|
||||||
|
|
||||||
|
document.body.appendChild(tempLink)
|
||||||
|
tempLink.click()
|
||||||
|
document.body.removeChild(tempLink)
|
||||||
|
window.URL.revokeObjectURL(imgUrl)
|
||||||
|
d.loading = false
|
||||||
|
ms.success(t('chat.exportSuccess'))
|
||||||
|
Promise.resolve()
|
||||||
|
}
|
||||||
|
catch (error: any) {
|
||||||
|
ms.error(t('chat.exportFailed'))
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
d.loading = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function handleDelete(index: number) {
|
function handleDelete(index: number) {
|
||||||
if (loading.value)
|
if (loading.value)
|
||||||
return
|
return
|
||||||
@@ -305,6 +348,12 @@ function handleEnter(event: KeyboardEvent) {
|
|||||||
handleSubmit()
|
handleSubmit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (event.key === 'Enter' && event.ctrlKey) {
|
||||||
|
event.preventDefault()
|
||||||
|
handleSubmit()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleStop() {
|
function handleStop() {
|
||||||
@@ -354,9 +403,8 @@ onUnmounted(() => {
|
|||||||
id="scrollRef"
|
id="scrollRef"
|
||||||
ref="scrollRef"
|
ref="scrollRef"
|
||||||
class="h-full overflow-hidden overflow-y-auto"
|
class="h-full overflow-hidden overflow-y-auto"
|
||||||
:class="[isMobile ? 'p-2' : 'p-4']"
|
|
||||||
>
|
>
|
||||||
<div class="w-full max-w-screen-xl m-auto">
|
<div id="image-wrapper" class="w-full max-w-screen-xl m-auto" :class="[isMobile ? 'p-2' : 'p-4']">
|
||||||
<template v-if="!dataSources.length">
|
<template v-if="!dataSources.length">
|
||||||
<div class="flex items-center justify-center mt-4 text-center text-neutral-300">
|
<div class="flex items-center justify-center mt-4 text-center text-neutral-300">
|
||||||
<SvgIcon icon="ri:bubble-chart-fill" class="mr-2 text-3xl" />
|
<SvgIcon icon="ri:bubble-chart-fill" class="mr-2 text-3xl" />
|
||||||
@@ -397,6 +445,11 @@ onUnmounted(() => {
|
|||||||
<SvgIcon icon="ri:delete-bin-line" />
|
<SvgIcon icon="ri:delete-bin-line" />
|
||||||
</span>
|
</span>
|
||||||
</HoverButton>
|
</HoverButton>
|
||||||
|
<HoverButton @click="handleExport">
|
||||||
|
<span class="text-xl text-[#4f555e] dark:text-white">
|
||||||
|
<SvgIcon icon="ri:download-2-line" />
|
||||||
|
</span>
|
||||||
|
</HoverButton>
|
||||||
<NInput
|
<NInput
|
||||||
v-model:value="prompt"
|
v-model:value="prompt"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
|
|||||||
@@ -4,12 +4,14 @@ import { NLayout, NLayoutContent } from 'naive-ui'
|
|||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import Sider from './sider/index.vue'
|
import Sider from './sider/index.vue'
|
||||||
import Header from './header/index.vue'
|
import Header from './header/index.vue'
|
||||||
|
import Permission from './Permission.vue'
|
||||||
import { useBasicLayout } from '@/hooks/useBasicLayout'
|
import { useBasicLayout } from '@/hooks/useBasicLayout'
|
||||||
import { useAppStore, useChatStore } from '@/store'
|
import { useAppStore, useAuthStore, useChatStore } from '@/store'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const appStore = useAppStore()
|
const appStore = useAppStore()
|
||||||
const chatStore = useChatStore()
|
const chatStore = useChatStore()
|
||||||
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
router.replace({ name: 'Chat', params: { uuid: chatStore.active } })
|
router.replace({ name: 'Chat', params: { uuid: chatStore.active } })
|
||||||
|
|
||||||
@@ -17,6 +19,8 @@ const { isMobile } = useBasicLayout()
|
|||||||
|
|
||||||
const collapsed = computed(() => appStore.siderCollapsed)
|
const collapsed = computed(() => appStore.siderCollapsed)
|
||||||
|
|
||||||
|
const needPermission = computed(() => !!authStore.session?.auth && !authStore.token)
|
||||||
|
|
||||||
const getMobileClass = computed(() => {
|
const getMobileClass = computed(() => {
|
||||||
if (isMobile.value)
|
if (isMobile.value)
|
||||||
return ['rounded-none', 'shadow-none']
|
return ['rounded-none', 'shadow-none']
|
||||||
@@ -44,5 +48,6 @@ const getContainerClass = computed(() => {
|
|||||||
</NLayoutContent>
|
</NLayoutContent>
|
||||||
</NLayout>
|
</NLayout>
|
||||||
</div>
|
</div>
|
||||||
|
<Permission :visible="needPermission" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
81
src/views/chat/layout/Permission.vue
Normal file
81
src/views/chat/layout/Permission.vue
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
<script setup lang='ts'>
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
import { NButton, NInput, NModal, useMessage } from 'naive-ui'
|
||||||
|
import { fetchVerify } from '@/api'
|
||||||
|
import { useAuthStore } from '@/store'
|
||||||
|
import Icon403 from '@/icons/403.vue'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
visible: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
defineProps<Props>()
|
||||||
|
|
||||||
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
|
const ms = useMessage()
|
||||||
|
|
||||||
|
const loading = ref(false)
|
||||||
|
const token = ref('')
|
||||||
|
|
||||||
|
const disabled = computed(() => !token.value.trim() || loading.value)
|
||||||
|
|
||||||
|
async function handleVerify() {
|
||||||
|
const secretKey = token.value.trim()
|
||||||
|
|
||||||
|
if (!secretKey)
|
||||||
|
return
|
||||||
|
|
||||||
|
try {
|
||||||
|
loading.value = true
|
||||||
|
await fetchVerify(secretKey)
|
||||||
|
authStore.setToken(secretKey)
|
||||||
|
ms.success('success')
|
||||||
|
window.location.reload()
|
||||||
|
}
|
||||||
|
catch (error: any) {
|
||||||
|
ms.error(error.message ?? 'error')
|
||||||
|
authStore.removeToken()
|
||||||
|
token.value = ''
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handlePress(event: KeyboardEvent) {
|
||||||
|
if (event.key === 'Enter' && !event.shiftKey) {
|
||||||
|
event.preventDefault()
|
||||||
|
handleVerify()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<NModal :show="visible" style="width: 90%; max-width: 640px">
|
||||||
|
<div class="p-10 bg-white rounded dark:bg-slate-800">
|
||||||
|
<div class="space-y-4">
|
||||||
|
<header class="space-y-2">
|
||||||
|
<h2 class="text-2xl font-bold text-center text-slate-800 dark:text-neutral-200">
|
||||||
|
403
|
||||||
|
</h2>
|
||||||
|
<p class="text-base text-center text-slate-500 dark:text-slate-500">
|
||||||
|
{{ $t('common.unauthorizedTips') }}
|
||||||
|
</p>
|
||||||
|
<Icon403 class="w-[200px] m-auto" />
|
||||||
|
</header>
|
||||||
|
<NInput v-model:value="token" type="text" placeholder="" @keypress="handlePress" />
|
||||||
|
|
||||||
|
<NButton
|
||||||
|
block
|
||||||
|
type="primary"
|
||||||
|
:disabled="disabled"
|
||||||
|
:loading="loading"
|
||||||
|
@click="handleVerify"
|
||||||
|
>
|
||||||
|
{{ $t('common.verify') }}
|
||||||
|
</NButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</NModal>
|
||||||
|
</template>
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
<script lang="ts" setup>
|
|
||||||
import { NButton } from 'naive-ui'
|
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
function goHome() {
|
|
||||||
router.push('/')
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="flex h-full">
|
|
||||||
<div class="px-4 m-auto space-y-4 text-center max-[400px]">
|
|
||||||
<h1 class="text-4xl text-slate-800 dark:text-neutral-200">
|
|
||||||
No permission
|
|
||||||
</h1>
|
|
||||||
<p class="text-base text-slate-500 dark:text-neutral-400">
|
|
||||||
The page you're trying access has restricted access.
|
|
||||||
Please refer to your system administrator
|
|
||||||
</p>
|
|
||||||
<div class="flex items-center justify-center text-center">
|
|
||||||
<div class="w-[300px]">
|
|
||||||
<div class="w-[300px]">
|
|
||||||
<img src="../../../icons/403.svg" alt="404">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<NButton type="primary" @click="goHome">
|
|
||||||
Go to Home
|
|
||||||
</NButton>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
32
src/views/exception/500/index.vue
Normal file
32
src/views/exception/500/index.vue
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import { NButton } from 'naive-ui'
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
|
import Icon500 from '@/icons/500.vue'
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
function goHome() {
|
||||||
|
router.push('/')
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex h-full dark:bg-neutral-800">
|
||||||
|
<div class="px-4 m-auto space-y-4 text-center max-[400px]">
|
||||||
|
<header class="space-y-2">
|
||||||
|
<h2 class="text-2xl font-bold text-center text-slate-800 dark:text-neutral-200">
|
||||||
|
500
|
||||||
|
</h2>
|
||||||
|
<p class="text-base text-center text-slate-500 dark:text-slate-500">
|
||||||
|
Server error
|
||||||
|
</p>
|
||||||
|
<div class="flex items-center justify-center text-center">
|
||||||
|
<Icon500 class="w-[300px]" />
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<NButton type="primary" @click="goHome">
|
||||||
|
Go to Home
|
||||||
|
</NButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
Reference in New Issue
Block a user