@@ -11,6 +11,8 @@ import { SystemPluginTemplateItemType } from '@fastgpt/global/core/workflow/type
11
11
import { getSystemPluginTemplates } from '../../../../plugins/register' ;
12
12
import { getAppLatestVersion , getAppVersionById } from '../version/controller' ;
13
13
import { PluginRuntimeType } from '@fastgpt/global/core/plugin/type' ;
14
+ import { MongoSystemPlugin } from './systemPluginSchema' ;
15
+ import { PluginErrEnum } from '@fastgpt/global/common/error/code/plugin' ;
14
16
15
17
/*
16
18
plugin id rule:
@@ -37,29 +39,41 @@ export async function splitCombinePluginId(id: string) {
37
39
38
40
type ChildAppType = SystemPluginTemplateItemType & { teamId ?: string } ;
39
41
const getSystemPluginTemplateById = async (
40
- pluginId : string
42
+ pluginId : string ,
43
+ versionId ?: string
41
44
) : Promise < SystemPluginTemplateItemType > => {
42
45
const item = getSystemPluginTemplates ( ) . find ( ( plugin ) => plugin . id === pluginId ) ;
43
- if ( ! item ) return Promise . reject ( 'plugin not found' ) ;
46
+ if ( ! item ) return Promise . reject ( PluginErrEnum . unAuth ) ;
44
47
45
48
const plugin = cloneDeep ( item ) ;
46
49
47
50
if ( plugin . associatedPluginId ) {
48
- // TODO: check is system plugin
51
+ // The verification plugin is set as a system plugin
52
+ const systemPlugin = await MongoSystemPlugin . findOne (
53
+ { pluginId : plugin . id , 'customConfig.associatedPluginId' : plugin . associatedPluginId } ,
54
+ 'associatedPluginId'
55
+ ) . lean ( ) ;
56
+ if ( ! systemPlugin ) return Promise . reject ( PluginErrEnum . unAuth ) ;
49
57
50
58
const app = await MongoApp . findById ( plugin . associatedPluginId ) . lean ( ) ;
51
- if ( ! app ) return Promise . reject ( 'plugin not found' ) ;
52
-
53
- const version = await getAppLatestVersion ( plugin . associatedPluginId , app ) ;
59
+ if ( ! app ) return Promise . reject ( PluginErrEnum . unAuth ) ;
60
+
61
+ const version = versionId
62
+ ? await getAppVersionById ( {
63
+ appId : plugin . associatedPluginId ,
64
+ versionId,
65
+ app
66
+ } )
67
+ : await getAppLatestVersion ( plugin . associatedPluginId , app ) ;
54
68
if ( ! version . versionId ) return Promise . reject ( 'App version not found' ) ;
55
69
56
70
plugin . workflow = {
57
71
nodes : version . nodes ,
58
72
edges : version . edges ,
59
73
chatConfig : version . chatConfig
60
74
} ;
75
+ plugin . version = versionId || String ( version . versionId ) ;
61
76
}
62
-
63
77
return plugin ;
64
78
} ;
65
79
@@ -172,7 +186,7 @@ export async function getChildAppRuntimeById(
172
186
pluginOrder : 0
173
187
} ;
174
188
} else {
175
- return getSystemPluginTemplateById ( pluginId ) ;
189
+ return getSystemPluginTemplateById ( pluginId , versionId ) ;
176
190
}
177
191
} ) ( ) ;
178
192
0 commit comments