Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/lobehub/lobe-chat
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Dec 24, 2024
2 parents 2753699 + 13f1eb4 commit 0d8f9e8
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 7 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@

# Changelog

### [Version 1.39.1](https://github.com/lobehub/lobe-chat/compare/v1.39.0...v1.39.1)

<sup>Released on **2024-12-24**</sup>

#### 🐛 Bug Fixes

- **misc**: Fix image input on pglite.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### 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))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>

## [Version 1.39.0](https://github.com/lobehub/lobe-chat/compare/v1.38.0...v1.39.0)

<sup>Released on **2024-12-23**</sup>
Expand Down
7 changes: 7 additions & 0 deletions changelog/v1.json
Original file line number Diff line number Diff line change
@@ -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."]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 6 additions & 2 deletions src/database/server/models/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export class MessageModel {
// **************** Query *************** //
query = async (
{ current = 0, pageSize = 1000, sessionId, topicId }: QueryMessageParams = {},
options: { postProcessUrl?: (path: string | null) => Promise<string> } = {},
options: {
postProcessUrl?: (path: string | null, file: { fileType: string }) => Promise<string>;
} = {},
): Promise<MessageItem[]> => {
const offset = current * pageSize;

Expand Down Expand Up @@ -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),
})),
);

Expand Down
26 changes: 22 additions & 4 deletions src/services/message/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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[];
}
Expand Down Expand Up @@ -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');
}
}

0 comments on commit 0d8f9e8

Please sign in to comment.