(
pluginName: string
)
| 691 | |
| 692 | // 从远程加载插件 README |
| 693 | private async getRemotePluginReadme( |
| 694 | pluginName: string |
| 695 | ): Promise<{ success: boolean; content?: string; error?: string }> { |
| 696 | try { |
| 697 | const baseUrl = `https://raw.githubusercontent.com/ZToolsCenter/ZTools-plugins/main/plugins/${pluginName}` |
| 698 | const readmeUrl = `${baseUrl}/README.md` |
| 699 | |
| 700 | console.log('[Plugins] 从远程加载 README:', readmeUrl) |
| 701 | |
| 702 | // 使用 httpGet 获取 README 内容(走系统代理) |
| 703 | const response = await httpGet(readmeUrl, { |
| 704 | validateStatus: (status) => status >= 200 && status < 400 |
| 705 | }) |
| 706 | if (response.status >= 300) { |
| 707 | return { success: false, error: '暂无详情' } |
| 708 | } |
| 709 | |
| 710 | let content = |
| 711 | typeof response.data === 'string' ? response.data : JSON.stringify(response.data) |
| 712 | |
| 713 | // 替换 Markdown 图片语法: |
| 714 | content = content.replace(/!\[([^\]]*)\]\((?!http)([^)]+)\)/g, (_match, alt, imgPath) => { |
| 715 | const cleanPath = imgPath.replace(/^\.\//, '') |
| 716 | return `` |
| 717 | }) |
| 718 | |
| 719 | // 替换 HTML img 标签的 src 属性 |
| 720 | content = content.replace( |
| 721 | /<img([^>]*?)src=["'](?!http)([^"']+)["']([^>]*?)>/gi, |
| 722 | (_match, before, src, after) => { |
| 723 | const cleanSrc = src.replace(/^\.\//, '') |
| 724 | return `<img${before}src="${baseUrl}/${cleanSrc}"${after}>` |
| 725 | } |
| 726 | ) |
| 727 | |
| 728 | // 替换 Markdown 链接语法(排除锚点链接 #) |
| 729 | content = content.replace(/\[([^\]]+)\]\((?!http|#)([^)]+)\)/g, (_match, text, linkPath) => { |
| 730 | const cleanPath = linkPath.replace(/^\.\//, '') |
| 731 | return `[${text}](${baseUrl}/${cleanPath})` |
| 732 | }) |
| 733 | |
| 734 | // 替换 HTML a 标签的 href 属性(排除锚点链接和外部链接) |
| 735 | content = content.replace( |
| 736 | /<a([^>]*?)href=["'](?!http|#)([^"']+)["']([^>]*?)>/gi, |
| 737 | (_match, before, href, after) => { |
| 738 | const cleanHref = href.replace(/^\.\//, '') |
| 739 | return `<a${before}href="${baseUrl}/${cleanHref}"${after}>` |
| 740 | } |
| 741 | ) |
| 742 | |
| 743 | return { success: true, content } |
| 744 | } catch (error: unknown) { |
| 745 | console.error('[Plugins] 从远程加载插件 README 失败:', error) |
| 746 | return { success: false, error: error instanceof Error ? error.message : '加载失败' } |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | // 获取插件存储的数据库数据 |
no test coverage detected