4.8.5 test (#1805)

* perf: revert tip

* feat: create copy app

* perf: file stream read

* perf: read directory over 100 files

* perf: index

* fix: team chat api error

* lock

* fix: i18n file
This commit is contained in:
Archer
2024-06-21 10:09:00 +08:00
committed by GitHub
parent 980b4d3db5
commit 5cc01b8509
57 changed files with 8660 additions and 10755 deletions

View File

@@ -4,6 +4,7 @@ import { connectToDatabase } from '@/service/mongo';
import { authFileToken } from '@fastgpt/service/support/permission/controller';
import { getDownloadStream, getFileById } from '@fastgpt/service/common/file/gridfs/controller';
import { CommonErrEnum } from '@fastgpt/global/common/error/code/common';
import { stream2Encoding } from '@fastgpt/service/common/file/gridfs/utils';
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
try {
@@ -17,7 +18,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
throw new Error('fileId is empty');
}
const [file, { fileStream, encoding }] = await Promise.all([
const [file, fileStream] = await Promise.all([
getFileById({ bucketName, fileId }),
getDownloadStream({ bucketName, fileId })
]);
@@ -26,16 +27,26 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
return Promise.reject(CommonErrEnum.fileNotFound);
}
const { stream, encoding } = await (async () => {
if (file.metadata?.encoding) {
return {
stream: fileStream,
encoding: file.metadata.encoding
};
}
return stream2Encoding(fileStream);
})();
res.setHeader('Content-Type', `${file.contentType}; charset=${encoding}`);
res.setHeader('Cache-Control', 'public, max-age=3600');
res.setHeader('Content-Disposition', `inline; filename="${encodeURIComponent(file.filename)}"`);
fileStream.pipe(res);
stream.pipe(res);
fileStream.on('error', () => {
stream.on('error', () => {
res.status(500).end();
});
fileStream.on('end', () => {
stream.on('end', () => {
res.end();
});
} catch (error) {
@@ -47,6 +58,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
}
export const config = {
api: {
responseLimit: '32mb'
responseLimit: '100mb'
}
};