feat(plugin): support local plugin sources

This commit is contained in:
InfinityPacer
2026-04-18 03:01:16 +08:00
parent 46fe257585
commit 1120055eed
2 changed files with 18 additions and 8 deletions
+3
View File
@@ -118,6 +118,9 @@ const iconPath: Ref<string> = computed(() => {
function visitPluginPage() { function visitPluginPage() {
// 将raw.githubusercontent.com转换为项目地址 // 将raw.githubusercontent.com转换为项目地址
let repoUrl = props.plugin?.repo_url let repoUrl = props.plugin?.repo_url
if (repoUrl?.startsWith('local://')) {
repoUrl = props.plugin?.author_url
}
if (repoUrl) { if (repoUrl) {
if (repoUrl.includes('raw.githubusercontent.com')) { if (repoUrl.includes('raw.githubusercontent.com')) {
if (!repoUrl.endsWith('/')) repoUrl += '/' if (!repoUrl.endsWith('/')) repoUrl += '/'
+15 -8
View File
@@ -610,15 +610,18 @@ async function saveFolderPluginOrder() {
// 初始化过滤选项 // 初始化过滤选项
function initOptions(item: Plugin) { function initOptions(item: Plugin) {
const LOCAL_REPO_LABEL = '本地'
const optionValue = (options: Array<string>, value: string | undefined) => { const optionValue = (options: Array<string>, value: string | undefined) => {
value && !options.includes(value) && options.push(value) if (!value || options.includes(value)) return
if (value === LOCAL_REPO_LABEL) options.unshift(value)
else options.push(value)
} }
const optionMutipleValue = (options: Array<string>, value: string | undefined) => { const optionMutipleValue = (options: Array<string>, value: string | undefined) => {
value && value.split(',').forEach(v => !options.includes(v) && options.push(v)) value && value.split(',').forEach(v => !options.includes(v) && options.push(v))
} }
optionValue(authorFilterOptions.value, item.plugin_author) optionValue(authorFilterOptions.value, item.plugin_author)
optionMutipleValue(labelFilterOptions.value, item.plugin_label) optionMutipleValue(labelFilterOptions.value, item.plugin_label)
optionValue(repoFilterOptions.value, handleRepoUrl(item.repo_url)) optionValue(repoFilterOptions.value, handleRepoUrl(item))
} }
// 关闭插件市场窗口 // 关闭插件市场窗口
@@ -650,7 +653,7 @@ async function installPlugin(item: Plugin) {
enabledFilter.value = false enabledFilter.value = false
installedFilter.value = null installedFilter.value = null
// 刷新 // 刷新
refreshData() await refreshData()
} else { } else {
$toast.error(t('plugin.installFailed', { name: item?.plugin_name, message: result.message })) $toast.error(t('plugin.installFailed', { name: item?.plugin_name, message: result.message }))
} }
@@ -750,6 +753,7 @@ async function fetchUninstalledPlugins(force: boolean = false) {
// 排除已安装且有更新的,上面的问题在于"本地存在未安装的旧版本插件且云端有更新时"不会在插件市场展示 // 排除已安装且有更新的,上面的问题在于"本地存在未安装的旧版本插件且云端有更新时"不会在插件市场展示
marketList.value = uninstalledList.value.filter(item => !(item.has_update && item.installed)) marketList.value = uninstalledList.value.filter(item => !(item.has_update && item.installed))
// 初始化过滤选项 // 初始化过滤选项
repoFilterOptions.value = []
marketList.value.forEach(initOptions) marketList.value.forEach(initOptions)
// 设置APP市场加载完成 // 设置APP市场加载完成
isAppMarketLoaded.value = true isAppMarketLoaded.value = true
@@ -770,7 +774,7 @@ async function getPluginStatistics() {
// 加载所有数据 // 加载所有数据
async function refreshData() { async function refreshData() {
await fetchInstalledPlugins() await fetchInstalledPlugins()
fetchUninstalledPlugins() await fetchUninstalledPlugins()
// 重新加载文件夹配置,确保分身插件能正确显示在文件夹中 // 重新加载文件夹配置,确保分身插件能正确显示在文件夹中
await loadPluginFolders() await loadPluginFolders()
} }
@@ -794,7 +798,7 @@ watch([marketList, filterForm, activeSort], () => {
filterText(filterForm.name, `${value.plugin_name} ${value.plugin_desc}`) && filterText(filterForm.name, `${value.plugin_name} ${value.plugin_desc}`) &&
match(filterForm.author, value.plugin_author) && match(filterForm.author, value.plugin_author) &&
matchMultiple(filterForm.label, value.plugin_label) && matchMultiple(filterForm.label, value.plugin_label) &&
match(filterForm.repo, handleRepoUrl(value.repo_url)) match(filterForm.repo, handleRepoUrl(value))
) { ) {
sortedUninstalledList.value.push(value) sortedUninstalledList.value.push(value)
} }
@@ -825,9 +829,9 @@ function pluginLabels(label: string | undefined) {
} }
// 新安装了插件 // 新安装了插件
function pluginInstalled() { async function pluginInstalled() {
pluginDialogClose() pluginDialogClose()
refreshData() await refreshData()
} }
// 插件市场设置完成 // 插件市场设置完成
@@ -851,8 +855,11 @@ async function refreshMarket() {
} }
// 处理掉github地址的前缀 // 处理掉github地址的前缀
function handleRepoUrl(url: string | undefined) { function handleRepoUrl(item: Plugin | string | undefined) {
const url = typeof item === 'string' ? item : item?.repo_url
if (typeof item !== 'string' && item?.is_local) return '本地'
if (!url) return '' if (!url) return ''
if (url.startsWith('local://')) return '本地'
return url.replace('https://github.com/', '').replace('https://raw.githubusercontent.com/', '') return url.replace('https://github.com/', '').replace('https://raw.githubusercontent.com/', '')
} }