mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-25 06:14:06 +00:00
Add mongo forward read. Fix markdown code block. (#2174)
* perf: read from mongo forward node * fix: code block ui * perf: markdown code css
This commit is contained in:
@@ -3,6 +3,7 @@ import { imageBaseUrl } from '@fastgpt/global/common/file/image/constants';
|
||||
import { MongoImage } from './schema';
|
||||
import { ClientSession } from '../../../common/mongo';
|
||||
import { guessBase64ImageType } from '../utils';
|
||||
import { readFromSecondary } from '../../mongo/utils';
|
||||
|
||||
export function getMongoImgUrl(id: string, extension: string) {
|
||||
return `${imageBaseUrl}${id}.${extension}`;
|
||||
@@ -44,10 +45,13 @@ export async function uploadMongoImg({
|
||||
export async function readMongoImg({ id }: { id: string }) {
|
||||
const formatId = id.replace(/\.[^/.]+$/, '');
|
||||
|
||||
const data = await MongoImage.findById(formatId);
|
||||
const data = await MongoImage.findById(formatId, undefined, {
|
||||
...readFromSecondary
|
||||
});
|
||||
if (!data) {
|
||||
return Promise.reject('Image not found');
|
||||
}
|
||||
|
||||
return {
|
||||
binary: data.binary,
|
||||
mime: data.metadata?.mime ?? guessBase64ImageType(data.binary.toString('base64'))
|
||||
|
@@ -1,4 +1,6 @@
|
||||
import { ReadPreference } from './index';
|
||||
|
||||
export const readFromSecondary = {
|
||||
readPreference: 'secondaryPreferred',
|
||||
readConcern: 'local'
|
||||
readPreference: ReadPreference.SECONDARY_PREFERRED, // primary | primaryPreferred | secondary | secondaryPreferred | nearest
|
||||
readConcern: 'local' as any // local | majority | linearizable | available
|
||||
};
|
||||
|
Reference in New Issue
Block a user