* feat: add feishu & yuque dataset (#3379) * feat: add feishu & yuque dataset * fix ts * fix ts * move type position * fix * fix: merge interface * fix * feat: dingtalk sso support (#3408) * fix: optional sso state * feat: dingtalk bot * feat: dingtalk sso login * chore: move i18n to user namespace * feat: dingtalk bot integration (#3415) * feat: dingtalk bot integration * docs: config dingtalk bot * feat:sear XNG服务 (#3413) * feat:sear XNG服务 * 补充了courseUrl * 添加了官方文档 * 错误时返回情况修正了一下 * Tracks (#3420) * feat: node intro * feat: add domain track * dingding sso login * perf: api dataset code and add doc * feat: tracks * feat: searXNG plugins * fix: ts * feat: delete node tracks (#3423) * fix: dingtalk bot GET verification (#3424) * 4.8.16 test: fix: plugin inputs render;fix: ui offset (#3426) * fix: ui offset * perf: dingding talk * fix: plugin inputs render * feat: menu all folder (#3429) * fix: recall code --------- Co-authored-by: heheer <heheer@sealos.io> Co-authored-by: a.e. <49438478+I-Info@users.noreply.github.com> Co-authored-by: Jiangween <145003935+Jiangween@users.noreply.github.com>
79 lines
2.1 KiB
TypeScript
79 lines
2.1 KiB
TypeScript
/*
|
|
Read db file content and response 3000 words
|
|
*/
|
|
import type { NextApiResponse } from 'next';
|
|
import { authCollectionFile } from '@fastgpt/service/support/permission/auth/file';
|
|
import { NextAPI } from '@/service/middleware/entry';
|
|
import { DatasetSourceReadTypeEnum } from '@fastgpt/global/core/dataset/constants';
|
|
import { readDatasetSourceRawText } from '@fastgpt/service/core/dataset/read';
|
|
import { ApiRequestProps } from '@fastgpt/service/type/next';
|
|
import {
|
|
OwnerPermissionVal,
|
|
WritePermissionVal
|
|
} from '@fastgpt/global/support/permission/constant';
|
|
import { authDataset } from '@fastgpt/service/support/permission/dataset/auth';
|
|
|
|
export type PreviewContextProps = {
|
|
datasetId: string;
|
|
type: DatasetSourceReadTypeEnum;
|
|
sourceId: string;
|
|
isQAImport?: boolean;
|
|
selector?: string;
|
|
externalFileId?: string;
|
|
};
|
|
|
|
async function handler(req: ApiRequestProps<PreviewContextProps>, res: NextApiResponse<any>) {
|
|
const { type, sourceId, isQAImport, selector, datasetId, externalFileId } = req.body;
|
|
|
|
if (!sourceId) {
|
|
throw new Error('fileId is empty');
|
|
}
|
|
|
|
const { teamId, apiServer, feishuServer, yuqueServer } = await (async () => {
|
|
if (type === DatasetSourceReadTypeEnum.fileLocal) {
|
|
const res = await authCollectionFile({
|
|
req,
|
|
authToken: true,
|
|
authApiKey: true,
|
|
fileId: sourceId,
|
|
per: OwnerPermissionVal
|
|
});
|
|
return {
|
|
teamId: res.teamId
|
|
};
|
|
}
|
|
const { dataset } = await authDataset({
|
|
req,
|
|
authApiKey: true,
|
|
authToken: true,
|
|
datasetId,
|
|
per: WritePermissionVal
|
|
});
|
|
return {
|
|
teamId: dataset.teamId,
|
|
apiServer: dataset.apiServer,
|
|
feishuServer: dataset.feishuServer,
|
|
yuqueServer: dataset.yuqueServer
|
|
};
|
|
})();
|
|
|
|
const rawText = await readDatasetSourceRawText({
|
|
teamId,
|
|
type,
|
|
sourceId,
|
|
isQAImport,
|
|
selector,
|
|
apiServer,
|
|
feishuServer,
|
|
yuqueServer,
|
|
externalFileId
|
|
});
|
|
|
|
return {
|
|
previewContent: rawText.slice(0, 3000),
|
|
totalLength: rawText.length
|
|
};
|
|
}
|
|
|
|
export default NextAPI(handler);
|