diff --git a/CHANGELOG.md b/CHANGELOG.md
index f6b0a3732943b..99288d94682c8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,31 @@
# Changelog
+### [Version 1.39.1](https://github.com/lobehub/lobe-chat/compare/v1.39.0...v1.39.1)
+
+Released on **2024-12-24**
+
+#### 🐛 Bug Fixes
+
+- **misc**: Fix image input on pglite.
+
+
+
+
+Improvements and Fixes
+
+#### What's fixed
+
+- **misc**: Fix image input on pglite, closes [#5167](https://github.com/lobehub/lobe-chat/issues/5167) ([5c5b37d](https://github.com/lobehub/lobe-chat/commit/5c5b37d))
+
+
+
+
+
+[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
+
+
+
## [Version 1.39.0](https://github.com/lobehub/lobe-chat/compare/v1.38.0...v1.39.0)
Released on **2024-12-23**
diff --git a/changelog/v1.json b/changelog/v1.json
index 8b0158f8f4b4c..f9bd2cbf9564a 100644
--- a/changelog/v1.json
+++ b/changelog/v1.json
@@ -1,4 +1,11 @@
[
+ {
+ "children": {
+ "fixes": ["Fix image input on pglite."]
+ },
+ "date": "2024-12-24",
+ "version": "1.39.1"
+ },
{
"children": {
"features": ["Upgrade to next15 and react19."]
diff --git a/package.json b/package.json
index 3052d63b3d2a3..538163caa2e36 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@lobehub/chat",
- "version": "1.39.0",
+ "version": "1.39.1",
"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.",
"keywords": [
"framework",
diff --git a/src/database/server/models/message.ts b/src/database/server/models/message.ts
index 543b71a742ce3..fae31617a644d 100644
--- a/src/database/server/models/message.ts
+++ b/src/database/server/models/message.ts
@@ -48,7 +48,9 @@ export class MessageModel {
// **************** Query *************** //
query = async (
{ current = 0, pageSize = 1000, sessionId, topicId }: QueryMessageParams = {},
- options: { postProcessUrl?: (path: string | null) => Promise } = {},
+ options: {
+ postProcessUrl?: (path: string | null, file: { fileType: string }) => Promise;
+ } = {},
): Promise => {
const offset = current * pageSize;
@@ -130,7 +132,9 @@ export class MessageModel {
const relatedFileList = await Promise.all(
rawRelatedFileList.map(async (file) => ({
...file,
- url: options.postProcessUrl ? await options.postProcessUrl(file.url) : (file.url as string),
+ url: options.postProcessUrl
+ ? await options.postProcessUrl(file.url, file as any)
+ : (file.url as string),
})),
);
diff --git a/src/services/message/client.ts b/src/services/message/client.ts
index f6ad84d539255..477457e02bbee 100644
--- a/src/services/message/client.ts
+++ b/src/services/message/client.ts
@@ -5,6 +5,7 @@ import { clientDB } from '@/database/client/db';
import { MessageItem } from '@/database/schemas';
import { MessageModel } from '@/database/server/models/message';
import { BaseClientService } from '@/services/baseClientService';
+import { clientS3Storage } from '@/services/file/ClientS3';
import {
ChatMessage,
ChatMessageError,
@@ -34,10 +35,20 @@ export class ClientService extends BaseClientService implements IMessageService
}
async getMessages(sessionId: string, topicId?: string) {
- const data = await this.messageModel.query({
- sessionId: this.toDbSessionId(sessionId),
- topicId,
- });
+ const data = await this.messageModel.query(
+ {
+ sessionId: this.toDbSessionId(sessionId),
+ topicId,
+ },
+ {
+ postProcessUrl: async (url, file) => {
+ const hash = (url as string).replace('client-s3://', '');
+ const base64 = await this.getBase64ByFileHash(hash);
+
+ return `data:${file.fileType};base64,${base64}`;
+ },
+ },
+ );
return data as unknown as ChatMessage[];
}
@@ -115,4 +126,11 @@ export class ClientService extends BaseClientService implements IMessageService
private toDbSessionId(sessionId: string | undefined) {
return sessionId === INBOX_SESSION_ID ? undefined : sessionId;
}
+
+ private async getBase64ByFileHash(hash: string) {
+ const fileItem = await clientS3Storage.getObject(hash);
+ if (!fileItem) throw new Error('file not found');
+
+ return Buffer.from(await fileItem.arrayBuffer()).toString('base64');
+ }
}