MCPcopy Index your code
hub / github.com/ZToolsCenter/ZTools / processRedirect

Method processRedirect

src/main/api/plugin/redirect.ts:92–209  ·  view source on GitHub ↗
(label: string | [string, string], payload?: any)

Source from the content-addressed store, hash-verified

90 }
91
92 private processRedirect(label: string | [string, string], payload?: any): void {
93 console.log('[Redirect] processRedirect', label, payload)
94
95 // 检查 payload 类型:只支持字符串类型(用于 regex 或 over 类型的匹配指令)
96 if (payload !== undefined && payload !== null && typeof payload !== 'string') {
97 console.log('[Redirect] 暂不支持非字符串类型的 payload:', typeof payload, payload)
98 return
99 }
100
101 try {
102 const plugins = databaseAPI.dbGet('plugins')
103 if (!plugins || !Array.isArray(plugins)) {
104 this.showNotification('未找到插件列表')
105 return
106 }
107
108 // 合并动态 features
109 for (const plugin of plugins) {
110 const dynamicFeatures = pluginFeatureAPI.loadDynamicFeatures(plugin.name)
111 plugin.features = [...(plugin.features || []), ...dynamicFeatures]
112 }
113
114 let targetPlugin: any = null
115 let targetFeature: any = null
116 let targetCmdName = ''
117 let targetCmdType: string | undefined
118
119 if (Array.isArray(label)) {
120 // [插件名称, 指令名称]
121 const [pluginTitle, cmdName] = label
122 targetPlugin = plugins.find((p: any) => p.title === pluginTitle)
123
124 if (targetPlugin) {
125 // 查找对应的 feature 和匹配 payload 的 cmd
126 for (const feature of targetPlugin.features || []) {
127 if (feature.cmds && Array.isArray(feature.cmds)) {
128 for (const cmd of feature.cmds) {
129 const cmdLabel = typeof cmd === 'string' ? cmd : cmd.label
130 if (cmdLabel === cmdName) {
131 // 检查 cmd 是否匹配 payload
132 const matchResult = this.isCmdMatchPayload(cmd, payload)
133 if (matchResult.matched) {
134 targetFeature = feature
135 targetCmdName = cmdLabel
136 targetCmdType = matchResult.type
137 break
138 }
139 }
140 }
141 if (targetFeature) break
142 }
143 }
144 }
145
146 if (!targetPlugin || !targetFeature) {
147 console.log('[Redirect] 未找到插件或指令:', pluginTitle, cmdName)
148 this.showNotification(`未找到插件或指令: ${pluginTitle} - ${cmdName}`)
149 return

Callers 1

handleRedirectMethod · 0.95

Calls 6

showNotificationMethod · 0.95
isCmdMatchPayloadMethod · 0.95
launchPluginMethod · 0.95
redirectSearchMethod · 0.95
loadDynamicFeaturesMethod · 0.80
dbGetMethod · 0.45

Tested by

no test coverage detected