mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-21 11:43:56 +00:00

* node versions add keep the latest option (#4899) * node versions add keep the latest option * i18n * perf: version code * fix: ts * hide system version * hide system version * hide system version * fix: ts * fix: ts --------- Co-authored-by: heheer <heheer@sealos.io>
85 lines
1.8 KiB
TypeScript
85 lines
1.8 KiB
TypeScript
import { type AppSchema } from '@fastgpt/global/core/app/type';
|
|
import { MongoAppVersion } from './schema';
|
|
import { Types } from '../../../common/mongo';
|
|
|
|
export const getAppLatestVersion = async (appId: string, app?: AppSchema) => {
|
|
const version = await MongoAppVersion.findOne({
|
|
appId,
|
|
isPublish: true
|
|
})
|
|
.sort({
|
|
time: -1
|
|
})
|
|
.lean();
|
|
|
|
if (version) {
|
|
return {
|
|
versionId: version._id,
|
|
versionName: version.versionName,
|
|
nodes: version.nodes,
|
|
edges: version.edges,
|
|
chatConfig: version.chatConfig || app?.chatConfig || {}
|
|
};
|
|
}
|
|
return {
|
|
versionId: app?.pluginData?.nodeVersion,
|
|
versionName: app?.name,
|
|
nodes: app?.modules || [],
|
|
edges: app?.edges || [],
|
|
chatConfig: app?.chatConfig || {}
|
|
};
|
|
};
|
|
|
|
export const getAppVersionById = async ({
|
|
appId,
|
|
versionId,
|
|
app
|
|
}: {
|
|
appId: string;
|
|
versionId?: string;
|
|
app?: AppSchema;
|
|
}) => {
|
|
// 检查 versionId 是否符合 ObjectId 格式
|
|
if (versionId && Types.ObjectId.isValid(versionId)) {
|
|
const version = await MongoAppVersion.findOne({
|
|
_id: versionId,
|
|
appId
|
|
}).lean();
|
|
|
|
if (version) {
|
|
return {
|
|
versionId: version._id,
|
|
versionName: version.versionName,
|
|
nodes: version.nodes,
|
|
edges: version.edges,
|
|
chatConfig: version.chatConfig || app?.chatConfig || {}
|
|
};
|
|
}
|
|
}
|
|
|
|
// If the version does not exist, the latest version is returned
|
|
return getAppLatestVersion(appId, app);
|
|
};
|
|
|
|
export const checkIsLatestVersion = async ({
|
|
appId,
|
|
versionId
|
|
}: {
|
|
appId: string;
|
|
versionId: string;
|
|
}) => {
|
|
if (!Types.ObjectId.isValid(versionId)) {
|
|
return false;
|
|
}
|
|
const version = await MongoAppVersion.findOne(
|
|
{
|
|
appId,
|
|
isPublish: true,
|
|
_id: { $gt: versionId }
|
|
},
|
|
'_id'
|
|
).lean();
|
|
|
|
return !version;
|
|
};
|