MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / installPlugin

Function installPlugin

frontend/packages/common/src/hooks/pluginLoader.ts:455–511  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

453 }
454
455 const installPlugin = () => {
456 return new Promise((resolve, reject) => {
457 // fetchData('system/plugins',{method:'GET'}).then((resp) => {
458 // if (resp.code === 0){
459 const resp = { data: mockData }
460 dispatch({ type: 'UPDATE_VERSION', version: resp.data.version })
461 dispatch({ type: 'UPDATE_DATE', updateDate: resp.data.buildAt })
462 dispatch({ type: 'UPDATE_POWER', powered: resp.data.powered })
463 const driverMethod = { apipark: apipark }
464 const pluginConfigList = resp.data.plugins
465 const pluginLoader = { loadModule }
466 const pluginLifecycleGuard = {}
467 const builtInPluginLoader = loadBuiltInModule
468 pluginSlotHub.addSlot('renewMenu', () => {
469 getMenuList()
470 })
471 for (const plugin of pluginConfigList) {
472 try {
473 const driverName = plugin.driver
474 if (!driverName) {
475 console.error('no driver name')
476 continue
477 }
478 const driver = driverName
479 .split('.')
480 .reduce(
481 (driverMethod: { [x: string]: any }, driverName: string | number) => driverMethod[driverName],
482 driverMethod
483 )
484 if (driverName.split('.')[2] === 'preload') {
485 setPendingTasks((prev) => prev + 1)
486 }
487 ;(driver as Function)?.(
488 {
489 setExecuteList: (callback: ExecutePluginType[]) => {
490 setExecuteList(callback)
491 setPendingTasks((prev) => prev - 1)
492 },
493 pluginLoader,
494 pluginProvider,
495 pluginLifecycleGuard,
496 builtInPluginLoader
497 },
498 plugin
499 )
500 } catch (err) {
501 console.warn('安装插件出错:', err)
502 }
503 }
504 resolve(true)
505 // } else {
506 // messageService.error(resp.msg || '获取插件配置列表失败,请重试!');
507 // reject(new Error(resp.msg || '获取插件配置列表失败'));
508 // }
509 // });
510 })
511 }
512

Callers 1

loadPluginsFunction · 0.85

Calls 1

getMenuListFunction · 0.85

Tested by

no test coverage detected