Skip to content

Commit

Permalink
fix: img compress (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu authored Dec 3, 2023
1 parent 7fc05af commit 9c77dfb
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions docSite/content/docs/installation/upgrading/463.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ curl --location --request POST 'https://{{host}}/api/admin/initv463' \
4. 优化 - 流读取文件,防止内存溢出
5. 优化 - 4v模型自动将 url 转 base64,本地也可调试
6. 优化 - 图片压缩等级
7. 修复 - 图片压缩失败报错,防止文件读取过程卡死。
11 changes: 7 additions & 4 deletions projects/app/src/pages/api/core/chat/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)

await authChat({ req, authToken: true, chatId });

await MongoChat.findOneAndUpdate({ chatId }, {
...(customTitle && { customTitle }),
...(top && { top })
});
await MongoChat.findOneAndUpdate(
{ chatId },
{
...(customTitle !== undefined && { customTitle }),
...(top !== undefined && { top })
}
);
jsonRes(res);
} catch (err) {
jsonRes(res, {
Expand Down
2 changes: 1 addition & 1 deletion projects/app/src/pages/chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ const Chat = ({ appId, chatId }: { appId: string; chatId: string }) => {
}}
onSetCustomTitle={async (e) => {
try {
await putChatHistory({
putChatHistory({
chatId: e.chatId,
customTitle: e.title
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ const ImportData = ({
title={<Box {...TitleStyle}>{t('dataset.data.File import')}</Box>}
isOpen
isCentered
maxW={['90vw', '85vw']}
w={['90vw', '85vw']}
maxW={['90vw', 'min(1440px,85vw)']}
w={['90vw', 'min(1440px,85vw)']}
h={'90vh'}
>
<ModalCloseButton onClick={onClose} />
Expand Down
1 change: 1 addition & 0 deletions projects/app/src/web/common/file/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const compressBase64ImgAndUpload = ({
reject(error);
}
};
img.onerror = reject;
});
};
export const compressImgFileAndUpload = async ({
Expand Down
2 changes: 2 additions & 0 deletions projects/app/src/web/common/file/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,15 @@ export const formatMarkdown = async (rawText: string = '') => {
maxH: 4329,
maxSize: 1024 * 1024 * 5
});

rawText = rawText.replace(base64, str);
} catch (error) {
rawText = rawText.replace(base64, '');
rawText = rawText.replace(/!\[.*\]\(\)/g, '');
}
})
);

// Remove white space on both sides of the picture
const trimReg = /\s*(!\[.*\]\(.*\))\s*/g;
if (trimReg.test(rawText)) {
Expand Down

0 comments on commit 9c77dfb

Please sign in to comment.