mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-02 20:58:12 +00:00
4.8.5 test fix (#1835)
* faq * perf: navbar name and fix dataset selector * feat: app tag * perf: icon * fix: update workflow bug * perf: dataset ui * perf: menu * fix: ts * fix: auth file and app list ui * app list * app list * perf: init api * update per * log level
This commit is contained in:
@@ -6,6 +6,7 @@ import { NextAPI } from '@/service/middleware/entry';
|
||||
import { PluginTypeEnum } from '@fastgpt/global/core/plugin/constants';
|
||||
import { mongoSessionRun } from '@fastgpt/service/common/mongo/sessionRun';
|
||||
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
|
||||
import { MongoAppVersion } from '@fastgpt/service/core/app/version/schema';
|
||||
|
||||
/*
|
||||
1. 先读取 HTTP plugin 内容,并找到所有的子plugin,然后事务批量创建,最后修改 inited
|
||||
@@ -16,19 +17,22 @@ let success = 0;
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
await authCert({ req, authRoot: true });
|
||||
|
||||
const { teamId } = req.body as { teamId?: string };
|
||||
|
||||
const total = await MongoPlugin.countDocuments({
|
||||
inited: { $ne: true }
|
||||
});
|
||||
|
||||
console.log('Total plugin', total);
|
||||
|
||||
await initHttp();
|
||||
await initPlugin();
|
||||
await initHttp(teamId);
|
||||
await initPlugin(teamId);
|
||||
}
|
||||
|
||||
async function initHttp(): Promise<any> {
|
||||
async function initHttp(teamId?: string): Promise<any> {
|
||||
/* 读取http插件和他的children */
|
||||
const plugin = await MongoPlugin.findOne({
|
||||
...(teamId && { teamId }),
|
||||
type: PluginTypeEnum.folder,
|
||||
inited: { $ne: true }
|
||||
}).lean();
|
||||
@@ -52,7 +56,7 @@ async function initHttp(): Promise<any> {
|
||||
avatar: plugin.avatar,
|
||||
intro: plugin.intro,
|
||||
metadata: plugin.metadata,
|
||||
version: 'v2',
|
||||
version: plugin.version,
|
||||
pluginData: {
|
||||
apiSchemaStr: plugin.metadata?.apiSchemaStr,
|
||||
customHeaders: plugin.metadata?.customHeaders
|
||||
@@ -64,9 +68,10 @@ async function initHttp(): Promise<any> {
|
||||
|
||||
/* 批量创建子插件 */
|
||||
for await (const item of children) {
|
||||
await MongoApp.create(
|
||||
const [{ _id: newPluginId }] = await MongoApp.create(
|
||||
[
|
||||
{
|
||||
_id: item._id,
|
||||
parentId: _id,
|
||||
teamId: item.teamId,
|
||||
tmbId: item.tmbId,
|
||||
@@ -74,7 +79,7 @@ async function initHttp(): Promise<any> {
|
||||
name: item.name,
|
||||
avatar: item.avatar,
|
||||
intro: item.intro,
|
||||
version: 'v2',
|
||||
version: plugin.version,
|
||||
modules: item.modules,
|
||||
edges: item.edges,
|
||||
pluginData: {
|
||||
@@ -85,6 +90,18 @@ async function initHttp(): Promise<any> {
|
||||
],
|
||||
{ session }
|
||||
);
|
||||
if (item.version === 'v2') {
|
||||
await MongoAppVersion.create(
|
||||
[
|
||||
{
|
||||
appId: newPluginId,
|
||||
nodes: item.modules,
|
||||
edges: item.edges
|
||||
}
|
||||
],
|
||||
{ session }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/* 更新插件信息 */
|
||||
@@ -115,24 +132,26 @@ async function initHttp(): Promise<any> {
|
||||
return initHttp();
|
||||
}
|
||||
|
||||
async function initPlugin(): Promise<any> {
|
||||
async function initPlugin(teamId?: string): Promise<any> {
|
||||
const plugin = await MongoPlugin.findOne({
|
||||
...(teamId && { teamId }),
|
||||
type: PluginTypeEnum.custom,
|
||||
inited: { $ne: true }
|
||||
}).lean();
|
||||
if (!plugin) return;
|
||||
|
||||
await mongoSessionRun(async (session) => {
|
||||
await MongoApp.create(
|
||||
const [{ _id: newPluginId }] = await MongoApp.create(
|
||||
[
|
||||
{
|
||||
_id: plugin._id,
|
||||
teamId: plugin.teamId,
|
||||
tmbId: plugin.tmbId,
|
||||
type: AppTypeEnum.plugin,
|
||||
name: plugin.name,
|
||||
avatar: plugin.avatar,
|
||||
intro: plugin.intro,
|
||||
version: 'v2',
|
||||
version: plugin.version,
|
||||
modules: plugin.modules,
|
||||
edges: plugin.edges,
|
||||
pluginData: {
|
||||
@@ -143,6 +162,19 @@ async function initPlugin(): Promise<any> {
|
||||
{ session }
|
||||
);
|
||||
|
||||
if (plugin.version === 'v2') {
|
||||
await MongoAppVersion.create(
|
||||
[
|
||||
{
|
||||
appId: newPluginId,
|
||||
nodes: plugin.modules,
|
||||
edges: plugin.edges
|
||||
}
|
||||
],
|
||||
{ session }
|
||||
);
|
||||
}
|
||||
|
||||
await MongoPlugin.findOneAndUpdate(
|
||||
{
|
||||
_id: plugin._id
|
||||
|
@@ -9,6 +9,7 @@ import { DatasetSourceReadTypeEnum } from '@fastgpt/global/core/dataset/constant
|
||||
import { readDatasetSourceRawText } from '@fastgpt/service/core/dataset/read';
|
||||
import { ApiRequestProps } from '@fastgpt/service/type/next';
|
||||
import { authCert } from '@fastgpt/service/support/permission/auth/common';
|
||||
import { OwnerPermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
|
||||
export type PreviewContextProps = {
|
||||
type: DatasetSourceReadTypeEnum;
|
||||
@@ -26,7 +27,13 @@ async function handler(req: ApiRequestProps<PreviewContextProps>, res: NextApiRe
|
||||
|
||||
const { teamId } = await (async () => {
|
||||
if (type === DatasetSourceReadTypeEnum.fileLocal) {
|
||||
return authFile({ req, authToken: true, authApiKey: true, fileId: sourceId });
|
||||
return authFile({
|
||||
req,
|
||||
authToken: true,
|
||||
authApiKey: true,
|
||||
fileId: sourceId,
|
||||
per: OwnerPermissionVal
|
||||
});
|
||||
}
|
||||
return authCert({ req, authApiKey: true, authToken: true });
|
||||
})();
|
||||
|
@@ -69,7 +69,10 @@ async function handler(
|
||||
|
||||
/* temp: get all apps and per */
|
||||
const [myApps, rpList] = await Promise.all([
|
||||
MongoApp.find(findAppsQuery, '_id avatar type name intro tmbId pluginData defaultPermission')
|
||||
MongoApp.find(
|
||||
findAppsQuery,
|
||||
'_id avatar type name intro tmbId updateTime pluginData defaultPermission'
|
||||
)
|
||||
.sort({
|
||||
updateTime: -1
|
||||
})
|
||||
@@ -101,10 +104,12 @@ async function handler(
|
||||
|
||||
return sliceApps.map((app) => ({
|
||||
_id: app._id,
|
||||
tmbId: app.tmbId,
|
||||
avatar: app.avatar,
|
||||
type: app.type,
|
||||
name: app.name,
|
||||
intro: app.intro,
|
||||
updateTime: app.updateTime,
|
||||
permission: app.permission,
|
||||
defaultPermission: app.defaultPermission || AppDefaultPermissionVal,
|
||||
pluginData: app.pluginData
|
||||
|
@@ -48,7 +48,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
|
||||
...(type && { type }),
|
||||
...(avatar && { avatar }),
|
||||
...(intro !== undefined && { intro }),
|
||||
...(defaultPermission && { defaultPermission }),
|
||||
...(defaultPermission !== undefined && { defaultPermission }),
|
||||
...(teamTags && { teamTags }),
|
||||
...(formatNodes && {
|
||||
modules: formatNodes
|
||||
|
@@ -1,14 +0,0 @@
|
||||
import type { NextApiRequest } from 'next';
|
||||
import { authDatasetFile } from '@fastgpt/service/support/permission/dataset/auth';
|
||||
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
import { NextAPI } from '@/service/middleware/entry';
|
||||
|
||||
async function handler(req: NextApiRequest) {
|
||||
const { fileId } = req.query as { fileId: string };
|
||||
// 凭证校验
|
||||
const { file } = await authDatasetFile({ req, authToken: true, fileId, per: ReadPermissionVal });
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
export default NextAPI(handler);
|
@@ -1,10 +1,10 @@
|
||||
import { authDatasetFile } from '@fastgpt/service/support/permission/dataset/auth';
|
||||
import { DatasetSourceReadTypeEnum } from '@fastgpt/global/core/dataset/constants';
|
||||
import { rawText2Chunks, readDatasetSourceRawText } from '@fastgpt/service/core/dataset/read';
|
||||
import { authCert } from '@fastgpt/service/support/permission/auth/common';
|
||||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { ApiRequestProps } from '@fastgpt/service/type/next';
|
||||
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
import { OwnerPermissionVal, ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
import { authFile } from '@fastgpt/service/support/permission/auth/file';
|
||||
|
||||
export type PostPreviewFilesChunksProps = {
|
||||
type: DatasetSourceReadTypeEnum;
|
||||
@@ -35,12 +35,12 @@ async function handler(
|
||||
|
||||
const { teamId } = await (async () => {
|
||||
if (type === DatasetSourceReadTypeEnum.fileLocal) {
|
||||
return authDatasetFile({
|
||||
return authFile({
|
||||
req,
|
||||
authToken: true,
|
||||
authApiKey: true,
|
||||
fileId: sourceId,
|
||||
per: ReadPermissionVal
|
||||
per: OwnerPermissionVal
|
||||
});
|
||||
}
|
||||
return authCert({ req, authApiKey: true, authToken: true });
|
||||
|
@@ -11,12 +11,14 @@ import {
|
||||
ReadPermissionVal
|
||||
} from '@fastgpt/global/support/permission/constant';
|
||||
import { MongoResourcePermission } from '@fastgpt/service/support/permission/schema';
|
||||
import { DatasetDefaultPermission } from '@fastgpt/global/support/permission/dataset/constant';
|
||||
import { DatasetDefaultPermissionVal } from '@fastgpt/global/support/permission/dataset/constant';
|
||||
import { ParentIdType } from '@fastgpt/global/common/parentFolder/type';
|
||||
import { parseParentIdInMongo } from '@fastgpt/global/common/parentFolder/utils';
|
||||
|
||||
export type GetDatasetListBody = { parentId: ParentIdType; type?: DatasetTypeEnum };
|
||||
|
||||
async function handler(req: NextApiRequest) {
|
||||
const { parentId, type } = req.body as { parentId: ParentIdType; type?: DatasetTypeEnum };
|
||||
const { parentId, type } = req.body as GetDatasetListBody;
|
||||
// 凭证校验
|
||||
const {
|
||||
teamId,
|
||||
@@ -28,18 +30,6 @@ async function handler(req: NextApiRequest) {
|
||||
authApiKey: true,
|
||||
per: ReadPermissionVal
|
||||
});
|
||||
console.log(
|
||||
'parentId',
|
||||
parentId,
|
||||
'type',
|
||||
type,
|
||||
'teamId',
|
||||
teamId,
|
||||
'tmbId',
|
||||
tmbId,
|
||||
'tmbPer',
|
||||
tmbPer
|
||||
);
|
||||
|
||||
const [myDatasets, rpList] = await Promise.all([
|
||||
MongoDataset.find({
|
||||
@@ -85,7 +75,7 @@ async function handler(req: NextApiRequest) {
|
||||
type: item.type,
|
||||
permission: item.permission,
|
||||
vectorModel: getVectorModel(item.vectorModel),
|
||||
defaultPermission: item.defaultPermission ?? DatasetDefaultPermission
|
||||
defaultPermission: item.defaultPermission ?? DatasetDefaultPermissionVal
|
||||
}))
|
||||
);
|
||||
|
||||
|
@@ -48,7 +48,7 @@ async function handler(req: NextApiRequest) {
|
||||
...(status && { status }),
|
||||
...(intro && { intro }),
|
||||
...(externalReadUrl && { externalReadUrl }),
|
||||
defaultPermission
|
||||
...(defaultPermission !== undefined && { defaultPermission })
|
||||
}
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user