主要成果:
- 新增独立插件 SDK:[PluginContracts.cs (line 11)](E:/jiaowu/src/Jiaowu.Plugin.Abstractions/PluginContracts.cs:11)
- 支持 RSA-PSS/SHA-256 签名插件包、Host API 兼容性和 ZIP 安全检查:[PluginPackageValidator.cs (line 14)](E:/jiaowu/src/Jiaowu.Api/Infrastructure/Plugins/PluginPackageValidator.cs:14)
- 支持暂存、待激活、重启装载、失败记录、版本回滚:[PluginPackageService.cs (line 32)](E:/jiaowu/src/Jiaowu.Api/Infrastructure/Plugins/PluginPackageService.cs:32)
- 插件可注册控制器、服务、数据库迁移、后台任务和事件处理器
- 外部插件 API 统一使用 /api/plugin-extensions/{pluginId},并受启用状态中间件控制
- 插件中心新增 ZIP/SIG 上传、状态展示、激活、回滚和删除功能:[PluginsView.vue (line 212)](E:/jiaowu/web/src/views/PluginsView.vue:212)
- 提供可运行示例插件:[SamplePlugin.cs (line 10)](E:/jiaowu/samples/Jiaowu.SamplePlugin/SamplePlugin.cs:10)
- 提供打包签名脚本:[package-plugin.ps1](E:/jiaowu/scripts/package-plugin.ps1)
- 完整开发文档:[plugin-sdk.md (line 1)](E:/jiaowu/docs/plugin-sdk.md:1)
- 系统版本已调整为 3.0.0-beta1
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import { computed, ref } from 'vue'
|
|
import { defineStore } from 'pinia'
|
|
import http from '../api/http'
|
|
|
|
export interface PluginRuntimeItem {
|
|
id: string
|
|
name: string
|
|
description: string
|
|
version: string
|
|
category: string
|
|
isEnabled: boolean
|
|
navigationPaths: string[]
|
|
capabilities: string[]
|
|
stateChangedAt?: string
|
|
source: 'built-in' | 'package'
|
|
status: string
|
|
requiresRestart: boolean
|
|
}
|
|
|
|
export const usePluginStore = defineStore('plugins', () => {
|
|
const items = ref<PluginRuntimeItem[]>([])
|
|
const loaded = ref(false)
|
|
let loadingPromise: Promise<void> | undefined
|
|
|
|
const byId = computed(() => new Map(items.value.map((item) => [item.id, item])))
|
|
|
|
function isEnabled(pluginId?: string) {
|
|
if (!pluginId || !loaded.value) return true
|
|
return byId.value.get(pluginId)?.isEnabled ?? false
|
|
}
|
|
|
|
async function load(force = false) {
|
|
if (loaded.value && !force) return
|
|
if (loadingPromise && !force) return loadingPromise
|
|
loadingPromise = http.get<PluginRuntimeItem[]>('/plugins/runtime')
|
|
.then(({ data }) => {
|
|
items.value = data
|
|
loaded.value = true
|
|
})
|
|
.finally(() => {
|
|
loadingPromise = undefined
|
|
})
|
|
return loadingPromise
|
|
}
|
|
|
|
function update(item: PluginRuntimeItem) {
|
|
const index = items.value.findIndex((candidate) => candidate.id === item.id)
|
|
if (index >= 0) items.value[index] = item
|
|
else items.value.push(item)
|
|
loaded.value = true
|
|
}
|
|
|
|
function reset() {
|
|
items.value = []
|
|
loaded.value = false
|
|
loadingPromise = undefined
|
|
}
|
|
|
|
return { items, loaded, isEnabled, load, update, reset }
|
|
})
|