@lobehub/chat 0.113.1 → 0.114.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ## [Version 0.114.0](https://github.com/lobehub/lobe-chat/compare/v0.113.1...v0.114.0)
6
+
7
+ <sup>Released on **2023-12-16**</sup>
8
+
9
+ #### ✨ Features
10
+
11
+ - **misc**: Supports setting multiple access code.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's improved
19
+
20
+ - **misc**: Supports setting multiple access code, closes [#647](https://github.com/lobehub/lobe-chat/issues/647) ([7db0430](https://github.com/lobehub/lobe-chat/commit/7db0430))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
5
30
  ### [Version 0.113.1](https://github.com/lobehub/lobe-chat/compare/v0.113.0...v0.113.1)
6
31
 
7
32
  <sup>Released on **2023-12-16**</sup>
package/README.md CHANGED
@@ -395,7 +395,7 @@ This project provides some additional configuration items set with environment v
395
395
  | `OPENAI_API_KEY` | Yes | This is the API key you apply on the OpenAI account page | `sk-xxxxxx...xxxxxx` |
396
396
  | `OPENAI_PROXY_URL` | No | If you manually configure the OpenAI interface proxy, you can use this configuration item to override the default OpenAI API request base URL | `https://api.chatanywhere.cn/v1`<br/>The default value is<br/>`https://api.openai.com/v1` |
397
397
  | `OPENAI_FUNCTION_REGIONS` | No | When you deploy Lobe-Chat using Vercel and need to specify the region for the Edge Function that handles requests to the OpenAI API, you can use this configuration. The value should be a comma-separated array of strings. | `iad1,sfo1` |
398
- | `ACCESS_CODE` | No | Add a password to access this service; you can set a long password to avoid leaking | `awCTe)re_r74` or `rtrt_ewee3@09!` |
398
+ | `ACCESS_CODE` | No | Add a password to access this service; you can set a long password to avoid leaking. If this value contains a comma, it is a password array. | `awCTe)re_r74` or `rtrt_ewee3@09!` or `code1,code2,code3` |
399
399
 
400
400
  > \[!NOTE]
401
401
  >
package/README.zh-CN.md CHANGED
@@ -367,7 +367,7 @@ $ docker run -d -p 3210:3210 \
367
367
  | `OPENAI_API_KEY` | 必选 | 这是你在 OpenAI 账户页面申请的 API 密钥 | `sk-xxxxxx...xxxxxx` |
368
368
  | `OPENAI_PROXY_URL` | 可选 | 如果你手动配置了 OpenAI 接口代理,可以使用此配置项来覆盖默认的 OpenAI API 请求基础 URL | `https://api.chatanywhere.cn/v1`<br/>默认值:<br/>`https://api.openai.com/v1` |
369
369
  | `OPENAI_FUNCTION_REGIONS` | 可选 | 当你使用 Vercel 部署 Lobe-Chat,而且有需求指定响应调用 OpenAI 接口的请求的 Edge Function 的 Region 时,可以使用该配置进行配置,该值的类型为逗号分隔的字符串数组 | `iad1,sfo1` |
370
- | `ACCESS_CODE` | 可选 | 添加访问此服务的密码,你可以设置一个长密码以防被爆破 | `awCTe)re_r74` or `rtrt_ewee3@09!` |
370
+ | `ACCESS_CODE` | 可选 | 添加访问此服务的密码,你可以设置一个长密码以防被爆破,该值用逗号分隔时为密码数组 | `awCTe)re_r74` or `rtrt_ewee3@09!` or `code1,code2,code3` |
371
371
 
372
372
  > \[!NOTE]
373
373
  >
@@ -37,13 +37,13 @@ After completing the above field configuration, click on "Check". If the prompt
37
37
 
38
38
  If you want the deployed version to be directly configured with Azure OpenAI for end users to use immediately, you need to configure the following environment variables at deployment:
39
39
 
40
- | Environment Variable | Required | Description | Default Value | Example |
41
- | -------------------- | -------- | --------------------------------------------------------------------------------- | ------------------ | -------------------------------------------------------------- |
42
- | `USE_AZURE_OPENAI` | Yes | Set this value to `1` to enable Azure OpenAI configuration | - | `1` |
43
- | `AZURE_API_KEY` | Yes | This is the API key you applied for on the Azure OpenAI account page | - | `c55168be3874490ef0565d9779ecd5a6` |
44
- | `OPENAI_PROXY_URL` | Yes | Azure API address, can be found in the "Keys and Endpoints" section | - | `https://docs-test-001.openai.azure.com` |
45
- | `AZURE_API_VERSION` | No | Azure's API version, follows the YYYY-MM-DD format | 2023-08-01-preview | `2023-05-15`, refer to [latest version][azure-api-version-url] |
46
- | `ACCESS_CODE` | No | Add a password to access this service, the password should be 6 digits or letters | - | `awCT74` or `e3@09!` |
40
+ | Environment Variable | Required | Description | Default Value | Example |
41
+ | -------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | -------------------------------------------------------------- |
42
+ | `USE_AZURE_OPENAI` | Yes | Set this value to `1` to enable Azure OpenAI configuration | - | `1` |
43
+ | `AZURE_API_KEY` | Yes | This is the API key you applied for on the Azure OpenAI account page | - | `c55168be3874490ef0565d9779ecd5a6` |
44
+ | `OPENAI_PROXY_URL` | Yes | Azure API address, can be found in the "Keys and Endpoints" section | - | `https://docs-test-001.openai.azure.com` |
45
+ | `AZURE_API_VERSION` | No | Azure's API version, follows the YYYY-MM-DD format | 2023-08-01-preview | `2023-05-15`, refer to [latest version][azure-api-version-url] |
46
+ | `ACCESS_CODE` | No | Add a password to access this service; you can set a long password to avoid leaking. If this value contains a comma, it is a password array. | - | `awCT74` or `e3@09!` or `code1,code2,code3` |
47
47
 
48
48
  > \[!NOTE]
49
49
  >
@@ -37,13 +37,13 @@ LobeChat 支持使用 [Azure OpenAI][azure-openai-url] 作为 OpenAI 的模型
37
37
 
38
38
  如果你希望部署的版本直接配置好 Azure OpenAI,让终端用户直接使用,那么你需要在部署时配置以下环境变量:
39
39
 
40
- | 环境变量 | 类型 | 描述 | 默认值 | 示例 |
41
- | ------------------- | ---- | --------------------------------------------------------------------------- | ------------------ | -------------------------------------------------- |
42
- | `USE_AZURE_OPENAI` | 必选 | 设置改值为 `1` 开启 Azure OpenAI 配置 | - | `1` |
43
- | `AZURE_API_KEY` | 必选 | 这是你在 Azure OpenAI 账户页面申请的 API 密钥 | - | `c55168be3874490ef0565d9779ecd5a6` |
44
- | `OPENAI_PROXY_URL` | 必选 | Azure API 地址,从 Azure 门户检查资源时,可在 “密钥和终结点” 部分中找到此值 | - | `https://docs-test-001.openai.azure.com` |
45
- | `AZURE_API_VERSION` | 可选 | Azure 的 API 版本,遵循 YYYY-MM-DD 格式 | 2023-08-01-preview | `2023-05-15`,查阅[最新版本][azure-api-verion-url] |
46
- | `ACCESS_CODE` | 可选 | 添加访问此服务的密码,密码应为 6 位数字或字母 | - | `awCT74` 或 `e3@09!` |
40
+ | 环境变量 | 类型 | 描述 | 默认值 | 示例 |
41
+ | ------------------- | ---- | -------------------------------------------------------------------------------- | ------------------ | -------------------------------------------------- |
42
+ | `USE_AZURE_OPENAI` | 必选 | 设置改值为 `1` 开启 Azure OpenAI 配置 | - | `1` |
43
+ | `AZURE_API_KEY` | 必选 | 这是你在 Azure OpenAI 账户页面申请的 API 密钥 | - | `c55168be3874490ef0565d9779ecd5a6` |
44
+ | `OPENAI_PROXY_URL` | 必选 | Azure API 地址,从 Azure 门户检查资源时,可在 “密钥和终结点” 部分中找到此值 | - | `https://docs-test-001.openai.azure.com` |
45
+ | `AZURE_API_VERSION` | 可选 | Azure 的 API 版本,遵循 YYYY-MM-DD 格式 | 2023-08-01-preview | `2023-05-15`,查阅[最新版本][azure-api-verion-url] |
46
+ | `ACCESS_CODE` | 可选 | 添加访问此服务的密码,你可以设置一个长密码以防被爆破,该值用逗号分隔时为密码数组 | - | `awCT74` 或 `e3@09!` or `code1,code2,code3` |
47
47
 
48
48
  > \[!NOTE]
49
49
  >
@@ -27,9 +27,9 @@ LobeChat provides additional configuration options during deployment, which can
27
27
  ### `ACCESS_CODE`
28
28
 
29
29
  - Type: Optional
30
- - Description: Add a password to access the LobeChat service, ; you can set a long password to avoid leaking.
30
+ - Description: Add a password to access the LobeChat service, ; you can set a long password to avoid leaking. If this value contains a comma, it is a password array.
31
31
  - Default: `-`
32
- - Example: `awCTe)re_r74` or `rtrt_ewee3@09!`
32
+ - Example: `awCTe)re_r74` or `rtrt_ewee3@09!` or `code1,code2,code3`
33
33
 
34
34
  ### `NEXT_PUBLIC_CUSTOM_MODELS`
35
35
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.113.1",
3
+ "version": "0.114.0",
4
4
  "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
5
5
  "keywords": [
6
6
  "framework",
@@ -7,7 +7,7 @@ interface AuthConfig {
7
7
  }
8
8
 
9
9
  export const checkAuth = ({ apiKey, accessCode }: AuthConfig) => {
10
- const { ACCESS_CODE } = getServerConfig();
10
+ const { ACCESS_CODES } = getServerConfig();
11
11
 
12
12
  // if apiKey exist
13
13
  if (apiKey) {
@@ -15,9 +15,9 @@ export const checkAuth = ({ apiKey, accessCode }: AuthConfig) => {
15
15
  }
16
16
 
17
17
  // if accessCode doesn't exist
18
- if (!ACCESS_CODE) return { auth: true };
18
+ if (!ACCESS_CODES.length) return { auth: true };
19
19
 
20
- if (accessCode !== ACCESS_CODE) {
20
+ if (!accessCode || !ACCESS_CODES.includes(accessCode)) {
21
21
  return { auth: false, error: ChatErrorType.InvalidAccessCode };
22
22
  }
23
23
 
@@ -1,5 +1,6 @@
1
1
  import { describe, expect, it, vi } from 'vitest';
2
2
 
3
+ import { checkAuth } from './auth';
3
4
  import { getPreferredRegion } from './config';
4
5
 
5
6
  // Stub the global process object to safely mock environment variables
@@ -40,3 +41,53 @@ describe('getPreferredRegion', () => {
40
41
  expect(preferredRegion).toStrictEqual(['ida1', 'sfo1']);
41
42
  });
42
43
  });
44
+
45
+ describe('ACCESS_CODE', () => {
46
+ let auth = false;
47
+
48
+ beforeEach(() => {
49
+ auth = false;
50
+ process.env.ACCESS_CODE = undefined;
51
+ // Reset environment variables before each test case
52
+ vi.restoreAllMocks();
53
+ });
54
+
55
+ it('set multiple access codes', () => {
56
+ process.env.ACCESS_CODE = ',code1,code2,code3';
57
+ ({ auth } = checkAuth({ accessCode: 'code1' }));
58
+ expect(auth).toBe(true);
59
+ ({ auth } = checkAuth({ accessCode: 'code2' }));
60
+ expect(auth).toBe(true);
61
+ ({ auth } = checkAuth({ accessCode: 'code1,code2' }));
62
+ expect(auth).toBe(false);
63
+ });
64
+
65
+ it('set individual access code', () => {
66
+ process.env.ACCESS_CODE = 'code1';
67
+ ({ auth } = checkAuth({ accessCode: 'code1' }));
68
+ expect(auth).toBe(true);
69
+ ({ auth } = checkAuth({ accessCode: 'code2' }));
70
+ expect(auth).toBe(false);
71
+ });
72
+
73
+ it('no access code', () => {
74
+ ({ auth } = checkAuth({ accessCode: 'code1' }));
75
+ expect(auth).toBe(true);
76
+ ({ auth } = checkAuth({}));
77
+ expect(auth).toBe(true);
78
+ });
79
+
80
+ it('empty access code', () => {
81
+ process.env.ACCESS_CODE = '';
82
+ ({ auth } = checkAuth({ accessCode: 'code1' }));
83
+ expect(auth).toBe(true);
84
+ ({ auth } = checkAuth({}));
85
+ expect(auth).toBe(true);
86
+
87
+ process.env.ACCESS_CODE = ',,';
88
+ ({ auth } = checkAuth({ accessCode: 'code1' }));
89
+ expect(auth).toBe(true);
90
+ ({ auth } = checkAuth({}));
91
+ expect(auth).toBe(true);
92
+ });
93
+ });
@@ -33,12 +33,12 @@ export const getServerConfig = () => {
33
33
  regions = process.env.OPENAI_FUNCTION_REGIONS.split(',');
34
34
  }
35
35
 
36
- const ACCESS_CODE = process.env.ACCESS_CODE;
36
+ const ACCESS_CODES = process.env.ACCESS_CODE?.split(',').filter(Boolean) || [];
37
37
 
38
38
  return {
39
- ACCESS_CODE,
39
+ ACCESS_CODES,
40
40
 
41
- SHOW_ACCESS_CODE_CONFIG: !!ACCESS_CODE,
41
+ SHOW_ACCESS_CODE_CONFIG: !!ACCESS_CODES.length,
42
42
 
43
43
  OPENAI_API_KEY: process.env.OPENAI_API_KEY,
44
44
  OPENAI_PROXY_URL: process.env.OPENAI_PROXY_URL,