@lobehub/chat 1.12.5 → 1.12.6

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/.env.example CHANGED
@@ -150,7 +150,7 @@ OPENAI_API_KEY=sk-xxxxxxxxx
150
150
  #S3_ENDPOINT=https://0b33a03b5c993fd2f453379dc36558e5.r2.cloudflarestorage.com
151
151
 
152
152
  # Public access domain for the bucket
153
- #NEXT_PUBLIC_S3_DOMAIN=https://s3-for-lobechat.your-domain.com
153
+ #S3_PUBLIC_DOMAIN=https://s3-for-lobechat.your-domain.com
154
154
 
155
155
  # Bucket region, such as us-west-1, generally not needed to add
156
156
  # but some service providers may require configuration
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.12.6](https://github.com/lobehub/lobe-chat/compare/v1.12.5...v1.12.6)
6
+
7
+ <sup>Released on **2024-08-22**</sup>
8
+
9
+ #### ♻ Code Refactoring
10
+
11
+ - **misc**: Refactor s3 env and support path-style for minio.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### Code refactoring
19
+
20
+ - **misc**: Refactor s3 env and support path-style for minio, closes [#3559](https://github.com/lobehub/lobe-chat/issues/3559) ([1658403](https://github.com/lobehub/lobe-chat/commit/1658403))
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 1.12.5](https://github.com/lobehub/lobe-chat/compare/v1.12.4...v1.12.5)
6
31
 
7
32
  <sup>Released on **2024-08-22**</sup>
@@ -127,6 +127,7 @@ ENV NEXT_AUTH_SECRET="" \
127
127
 
128
128
  # S3
129
129
  ENV NEXT_PUBLIC_S3_DOMAIN="" \
130
+ S3_PUBLIC_DOMAIN="" \
130
131
  S3_ACCESS_KEY_ID="" \
131
132
  S3_BUCKET="" \
132
133
  S3_ENDPOINT="" \
@@ -48,7 +48,7 @@ S3_BUCKET=lobechat
48
48
  # Request endpoint of the bucket (note that the path in this link includes the bucket name, which must be removed, or use the link provided on the page for applying S3 API token)
49
49
  S3_ENDPOINT=https://0b33a03b5c993fd2f453379dc36558e5.r2.cloudflarestorage.com
50
50
  # Access domain of the bucket
51
- NEXT_PUBLIC_S3_DOMAIN=https://s3-for-lobechat.your-domain.com
51
+ S3_PUBLIC_DOMAIN=https://s3-for-lobechat.your-domain.com
52
52
  ```
53
53
 
54
54
  <Callout type={'warning'}>`S3_ENDPOINT` must have its path removed, otherwise uploaded files cannot be accessed.</Callout>
@@ -138,7 +138,7 @@ S3_BUCKET=lobechat
138
138
  # Bucket Request Endpoint
139
139
  S3_ENDPOINT=https://0b33a03b5c993fd2f453379dc36558e5.r2.cloudflarestorage.com
140
140
  # Public Access Domain for the Bucket
141
- NEXT_PUBLIC_S3_DOMAIN=https://s3-dev.your-domain.com
141
+ S3_PUBLIC_DOMAIN=https://s3-dev.your-domain.com
142
142
 
143
143
  # Bucket Region, such as us-west-1. Generally not required, but some service providers may need it.
144
144
  # S3_REGION=us-west-1
@@ -49,7 +49,7 @@ S3_BUCKET=lobechat
49
49
  # 存储桶的请求端点(注意此处链接的路径带存储桶名称,必须删除该路径,或使用申请 S3 API token 页面所提供的链接)
50
50
  S3_ENDPOINT=https://0b33a03b5c993fd2f453379dc36558e5.r2.cloudflarestorage.com
51
51
  # 存储桶对外的访问域名
52
- NEXT_PUBLIC_S3_DOMAIN=https://s3-for-lobechat.your-domain.com
52
+ S3_PUBLIC_DOMAIN=https://s3-for-lobechat.your-domain.com
53
53
  ```
54
54
 
55
55
  <Callout type={'warning'}>`S3_ENDPOINT`必须删除其路径,否则会无法访问所上传文件</Callout>
@@ -139,7 +139,7 @@ S3_BUCKET=lobechat
139
139
  # 存储桶的请求端点
140
140
  S3_ENDPOINT=https://0b33a03b5c993fd2f453379dc36558e5.r2.cloudflarestorage.com
141
141
  # 存储桶对外的访问域名
142
- NEXT_PUBLIC_S3_DOMAIN=https://s3-dev.your-domain.com
142
+ S3_PUBLIC_DOMAIN=https://s3-dev.your-domain.com
143
143
 
144
144
  # 桶的区域,如 us-west-1,一般来说不需要添加,但某些服务商则需要配置
145
145
  # S3_REGION=us-west-1
@@ -45,7 +45,7 @@ In this documentation, S3 refers to a compatible S3 storage solution, which supp
45
45
 
46
46
  Whether to set the ACL to `public-read` when uploading files. This option is enabled by default. If the service provider does not support setting individual ACLs for files (i.e., all files inherit the ACL of the storage bucket), enabling this option may cause request errors. Set `S3_SET_ACL` to `0` to disable it.
47
47
 
48
- ### `NEXT_PUBLIC_S3_DOMAIN`
48
+ ### `S3_PUBLIC_DOMAIN`
49
49
 
50
50
  The public access domain of the storage bucket, used to access files in the storage bucket. This address needs to be **publicly readable**. The reason is that when OpenAI's gpt-4o and other vision models recognize images, OpenAI will try to download this image link on their servers. Therefore, this link must be publicly accessible. If it is a private link, OpenAI will not be able to access the image and thus will not be able to recognize the image content properly.
51
51
 
@@ -46,7 +46,7 @@ S3_ENDPOINT=https://0b33a03b5c993fd2f453379dc36558e5.r2.cloudflarestorage.com
46
46
 
47
47
  是否在上传文件时设置 ACL 为 `public-read`。该选项默认启用。如果服务商不支持为文件设置单独的 ACL(即所有文件继承存储桶的 ACL),启用此选项可能会导致请求错误,将 `S3_SET_ACL` 设置为 `0` 即可关闭。
48
48
 
49
- ### `NEXT_PUBLIC_S3_DOMAIN`
49
+ ### `S3_PUBLIC_DOMAIN`
50
50
 
51
51
  存储桶对外的访问域名,用于访问存储桶中的文件,这个地址需要**允许互联网可读**。 原因是 OpenAI 的 gpt-4o 等视觉模型识别图片时,OpenAI 会尝试在他们的服务器中下载这个图片链接,因此这个链接必须是公开可访问的,如果是私有的链接,OpenAI 将无法访问到这个图片,进而无法正常识别到图片内容。
52
52
 
@@ -73,7 +73,7 @@ S3_ACCESS_KEY_ID=xxxxxxxxxx
73
73
  S3_SECRET_ACCESS_KEY=xxxxxxxxxx
74
74
  S3_ENDPOINT=https://xxxxxxxxxx.r2.cloudflarestorage.com
75
75
  S3_BUCKET=lobechat
76
- NEXT_PUBLIC_S3_DOMAIN=https://s3-for-lobechat.your-domain.com
76
+ S3_PUBLIC_DOMAIN=https://s3-for-lobechat.your-domain.com
77
77
  ```
78
78
 
79
79
  ### Start the lobe-chat-database Docker image
@@ -125,7 +125,7 @@ $ docker run -it -d --name lobe-chat-database -p 3210:3210 \
125
125
  -e S3_SECRET_ACCESS_KEY=xxxxxxxxxx \
126
126
  -e S3_ENDPOINT=https://xxxxxxxxxx.r2.cloudflarestorage.com \
127
127
  -e S3_BUCKET=lobechat \
128
- -e NEXT_PUBLIC_S3_DOMAIN=https://s3-for-lobechat.your-domain.com \
128
+ -e S3_PUBLIC_DOMAIN=https://s3-for-lobechat.your-domain.com \
129
129
  lobehub/lobe-chat-database
130
130
  ```
131
131
 
@@ -75,7 +75,7 @@ S3_ACCESS_KEY_ID=xxxxxxxxxx
75
75
  S3_SECRET_ACCESS_KEY=xxxxxxxxxx
76
76
  S3_ENDPOINT=https://xxxxxxxxxx.r2.cloudflarestorage.com
77
77
  S3_BUCKET=lobechat
78
- NEXT_PUBLIC_S3_DOMAIN=https://s3-for-lobechat.your-domain.com
78
+ S3_PUBLIC_DOMAIN=https://s3-for-lobechat.your-domain.com
79
79
  ```
80
80
 
81
81
  ### 启动 lobe-chat-database docker 镜像
@@ -130,7 +130,7 @@ $ docker run -it -d --name lobe-chat-database -p 3210:3210 \
130
130
  -e S3_SECRET_ACCESS_KEY=xxxxxxxxxx \
131
131
  -e S3_ENDPOINT=https://xxxxxxxxxx.r2.cloudflarestorage.com \
132
132
  -e S3_BUCKET=lobechat \
133
- -e NEXT_PUBLIC_S3_DOMAIN=https://s3-for-lobechat.your-domain.com \
133
+ -e S3_PUBLIC_DOMAIN=https://s3-for-lobechat.your-domain.com \
134
134
  lobehub/lobe-chat-database
135
135
  ```
136
136
 
@@ -250,7 +250,7 @@ S3_BUCKET=lobechat
250
250
  # Storage bucket request endpoint (note that the path in this link includes the bucket name, which must be removed, or use the link provided on the S3 API token application page)
251
251
  S3_ENDPOINT=https://0b33a03b5c993fd2f453379dc36558e5.r2.cloudflarestorage.com
252
252
  # Public access domain for the storage bucket
253
- NEXT_PUBLIC_S3_DOMAIN=https://s3-for-lobechat.your-domain.com
253
+ S3_PUBLIC_DOMAIN=https://s3-for-lobechat.your-domain.com
254
254
  ```
255
255
 
256
256
  <Callout type={'warning'}>
@@ -312,7 +312,7 @@ S3_BUCKET=lobechat
312
312
  # Bucket request endpoint
313
313
  S3_ENDPOINT=https://0b33a03b5c993fd2f453379dc36558e5.r2.cloudflarestorage.com
314
314
  # Public domain for bucket access
315
- NEXT_PUBLIC_S3_DOMAIN=https://s3-dev.your-domain.com
315
+ S3_PUBLIC_DOMAIN=https://s3-dev.your-domain.com
316
316
 
317
317
  # Bucket region, such as us-west-1, generally not required, but some providers may need to configure
318
318
  # S3_REGION=us-west-1
@@ -384,7 +384,7 @@ src={'https://github.com/lobehub/lobe-chat/assets/28616219/da84edc3-46f7-4e2b-a0
384
384
  <Image
385
385
  alt={'Login successful state'}
386
386
  src={'https://github.com/lobehub/lobe-chat/assets/28616219/9cb5150d-6e1e-4c59-9a18-4e418dce1a5d'}/>
387
-
387
+
388
388
  </Steps>
389
389
 
390
390
  ## Appendix
@@ -416,7 +416,7 @@ S3_BUCKET=lobechat
416
416
  # Bucket request endpoint
417
417
  S3_ENDPOINT=https://0b33a03b5c993fd2f453379dc36558e5.r2.cloudflarestorage.com
418
418
  # Public access domain for the bucket
419
- NEXT_PUBLIC_S3_DOMAIN=https://s3-for-lobechat.your-domain.com
419
+ S3_PUBLIC_DOMAIN=https://s3-for-lobechat.your-domain.com
420
420
  # Bucket region, such as us-west-1, generally not needed to add, but some service providers may require configuration
421
421
  # S3_REGION=us-west-1
422
422
  ```
@@ -18,8 +18,8 @@ tags:
18
18
 
19
19
  <Callout type={'warning'}>
20
20
  进行后续操作前,请务必确认以下事项:
21
- - 导出所有数据,部署服务端数据库后,原有用户数据无法自动迁移,只能提前备份后进行手动导入!
22
- - 环境变量中的`ACCESS_CODE`未设置或已清除!
21
+ - 导出所有数据,部署服务端数据库后,原有用户数据无法自动迁移,只能提前备份后进行手动导入!
22
+ - 环境变量中的`ACCESS_CODE`未设置或已清除!
23
23
  - 配置服务端数据库所需要的环境变量时,需全部填入后再进行部署,否则可能遭遇数据库迁移问题!
24
24
  </Callout>
25
25
 
@@ -46,7 +46,7 @@ tags:
46
46
 
47
47
  <Callout type={'warning'}>
48
48
  请确认您的供应商所提供的 `Postgres` 类型,若为 `Node Postgres`,请切换到 `Node Postgres` Tab 。
49
-
49
+
50
50
  </Callout>
51
51
 
52
52
  Serverless Postgres 需要填写的变量如下:
@@ -233,7 +233,7 @@ S3_BUCKET=lobechat
233
233
  # 存储桶的请求端点(注意此处链接的路径带存储桶名称,必须删除该路径,或使用申请 S3 API token 页面所提供的链接)
234
234
  S3_ENDPOINT=https://0b33a03b5c993fd2f453379dc36558e5.r2.cloudflarestorage.com
235
235
  # 存储桶对外的访问域名
236
- NEXT_PUBLIC_S3_DOMAIN=https://s3-for-lobechat.your-domain.com
236
+ S3_PUBLIC_DOMAIN=https://s3-for-lobechat.your-domain.com
237
237
  ```
238
238
 
239
239
  <Callout type={'warning'}>`S3_ENDPOINT`必须删除其路径,否则会无法访问所上传文件</Callout>
@@ -291,7 +291,7 @@ S3_BUCKET=lobechat
291
291
  # 存储桶的请求端点
292
292
  S3_ENDPOINT=https://0b33a03b5c993fd2f453379dc36558e5.r2.cloudflarestorage.com
293
293
  # 存储桶对外的访问域名
294
- NEXT_PUBLIC_S3_DOMAIN=https://s3-dev.your-domain.com
294
+ S3_PUBLIC_DOMAIN=https://s3-dev.your-domain.com
295
295
 
296
296
  # 桶的区域,如 us-west-1,一般来说不需要添加,但某些服务商则需要配置
297
297
  # S3_REGION=us-west-1
@@ -397,7 +397,7 @@ S3_BUCKET=lobechat
397
397
  # 存储桶的请求端点
398
398
  S3_ENDPOINT=https://0b33a03b5c993fd2f453379dc36558e5.r2.cloudflarestorage.com
399
399
  # 存储桶对外的访问域名
400
- NEXT_PUBLIC_S3_DOMAIN=https://s3-for-lobechat.your-domain.com
400
+ S3_PUBLIC_DOMAIN=https://s3-for-lobechat.your-domain.com
401
401
  # 桶的区域,如 us-west-1,一般来说不需要添加,但某些服务商则需要配置
402
402
  # S3_REGION=us-west-1
403
403
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.12.5",
3
+ "version": "1.12.6",
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",
@@ -4,8 +4,19 @@ import { z } from 'zod';
4
4
  const DEFAULT_S3_FILE_PATH = 'files';
5
5
 
6
6
  export const getFileConfig = () => {
7
+ if (!!process.env.NEXT_PUBLIC_S3_DOMAIN) {
8
+ console.warn(
9
+ '⚠️ `NEXT_PUBLIC_S3_DOMAIN` will be de deprecated in the next major version, please replace it with `S3_PUBLIC_DOMAIN` in your env',
10
+ );
11
+ }
12
+
13
+ const S3_PUBLIC_DOMAIN = process.env.S3_PUBLIC_DOMAIN || process.env.NEXT_PUBLIC_S3_DOMAIN;
14
+
7
15
  return createEnv({
8
16
  client: {
17
+ /**
18
+ * @deprecated
19
+ */
9
20
  NEXT_PUBLIC_S3_DOMAIN: z.string().url().optional(),
10
21
  NEXT_PUBLIC_S3_FILE_PATH: z.string().optional(),
11
22
  },
@@ -18,7 +29,9 @@ export const getFileConfig = () => {
18
29
 
19
30
  S3_ACCESS_KEY_ID: process.env.S3_ACCESS_KEY_ID,
20
31
  S3_BUCKET: process.env.S3_BUCKET,
32
+ S3_ENABLE_PATH_STYLE: process.env.S3_ENABLE_PATH_STYLE === '1',
21
33
  S3_ENDPOINT: process.env.S3_ENDPOINT,
34
+ S3_PUBLIC_DOMAIN,
22
35
  S3_REGION: process.env.S3_REGION,
23
36
  S3_SECRET_ACCESS_KEY: process.env.S3_SECRET_ACCESS_KEY,
24
37
  S3_SET_ACL: process.env.S3_SET_ACL !== '0',
@@ -30,8 +43,10 @@ export const getFileConfig = () => {
30
43
  // S3
31
44
  S3_ACCESS_KEY_ID: z.string().optional(),
32
45
  S3_BUCKET: z.string().optional(),
33
- S3_ENDPOINT: z.string().url().optional(),
46
+ S3_ENABLE_PATH_STYLE: z.boolean(),
34
47
 
48
+ S3_ENDPOINT: z.string().url().optional(),
49
+ S3_PUBLIC_DOMAIN: z.string().url().optional(),
35
50
  S3_REGION: z.string().optional(),
36
51
  S3_SECRET_ACCESS_KEY: z.string().optional(),
37
52
  S3_SET_ACL: z.boolean(),
@@ -42,6 +42,7 @@ export class S3 {
42
42
  secretAccessKey: fileEnv.S3_SECRET_ACCESS_KEY,
43
43
  },
44
44
  endpoint: fileEnv.S3_ENDPOINT,
45
+ forcePathStyle: fileEnv.S3_ENABLE_PATH_STYLE,
45
46
  region: fileEnv.S3_REGION || DEFAULT_S3_REGION,
46
47
  });
47
48
  }
@@ -1,8 +1,6 @@
1
1
  import { TRPCError } from '@trpc/server';
2
- import urlJoin from 'url-join';
3
2
  import { z } from 'zod';
4
3
 
5
- import { fileEnv } from '@/config/file';
6
4
  import { AsyncTaskModel } from '@/database/server/models/asyncTask';
7
5
  import { ChunkModel } from '@/database/server/models/chunk';
8
6
  import { FileModel } from '@/database/server/models/file';
@@ -137,7 +135,7 @@ export const fileRouter = router({
137
135
  embeddingError: embeddingTask?.error ?? null,
138
136
  embeddingStatus: embeddingTask?.status as AsyncTaskStatus,
139
137
  finishEmbedding: embeddingTask?.status === AsyncTaskStatus.Success,
140
- url: urlJoin(fileEnv.NEXT_PUBLIC_S3_DOMAIN!, item.url!),
138
+ url: getFullFileUrl(item.url!),
141
139
  };
142
140
  });
143
141
  }),
@@ -5,5 +5,5 @@ import { fileEnv } from '@/config/file';
5
5
  export const getFullFileUrl = (url?: string | null) => {
6
6
  if (!url) return '';
7
7
 
8
- return urlJoin(fileEnv.NEXT_PUBLIC_S3_DOMAIN!, url);
8
+ return urlJoin(fileEnv.S3_PUBLIC_DOMAIN!, url);
9
9
  };
@@ -21,6 +21,10 @@ export class ServerService implements IFileService {
21
21
  return lambdaClient.file.createFile.mutate({ ...params, knowledgeBaseId } as CreateFileParams);
22
22
  }
23
23
 
24
+ /**
25
+ * @deprecated
26
+ * @param id
27
+ */
24
28
  async getFile(id: string): Promise<FilePreview> {
25
29
  if (!fileEnv.NEXT_PUBLIC_S3_DOMAIN) {
26
30
  throw new Error('fileEnv.NEXT_PUBLIC_S3_DOMAIN is not set while enable server upload');