From 85f2be55a62d0cf05bac57fda6a3ee8eb38bfe91 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E6=9C=B1?=
<10714957+xiao-zhu245@user.noreply.gitee.com>
Date: Sat, 12 Jul 2025 09:50:32 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=8F=92=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
client/src/pages/PluginsPage.tsx | 129 +++++++-
.../data/plugins/example-plugin/gsm3-api.js | 307 ++++++++++++++++++
server/data/plugins/example-plugin/index.html | 146 +++++++++
server/src/index.ts | 5 +
server/src/routes/pluginApi.ts | 283 ++++++++++++++++
server/src/routes/plugins.ts | 35 +-
6 files changed, 899 insertions(+), 6 deletions(-)
create mode 100644 server/data/plugins/example-plugin/gsm3-api.js
create mode 100644 server/src/routes/pluginApi.ts
diff --git a/client/src/pages/PluginsPage.tsx b/client/src/pages/PluginsPage.tsx
index 7bb9f7a..11af702 100644
--- a/client/src/pages/PluginsPage.tsx
+++ b/client/src/pages/PluginsPage.tsx
@@ -62,6 +62,25 @@ const PluginsPage: React.FC = () => {
const { addNotification } = useNotificationStore()
const apiClient = new ApiClient()
+ // 监听来自插件的消息
+ useEffect(() => {
+ const handleMessage = (event: MessageEvent) => {
+ if (event.data && event.data.type === 'gsm3-notification') {
+ const { type, message } = event.data.data
+ addNotification({
+ type: type as 'info' | 'success' | 'warning' | 'error',
+ title: '插件消息',
+ message
+ })
+ } else if (event.data && event.data.type === 'gsm3-plugin-loaded') {
+ console.log('插件加载完成:', event.data.data)
+ }
+ }
+
+ window.addEventListener('message', handleMessage)
+ return () => window.removeEventListener('message', handleMessage)
+ }, [addNotification])
+
const categories = [
'工具',
'游戏',
@@ -215,9 +234,117 @@ const PluginsPage: React.FC = () => {
}
if (content && content.trim()) {
- setCurrentPluginContent(content)
+ // 修复gsm3-api.js的引用路径并注入token
+ const token = apiClient.getToken()
+ let injectedContent = content
+
+ // 替换相对路径的gsm3-api.js引用为正确的API路径
+ injectedContent = injectedContent.replace(
+ /src="gsm3-api\.js"/g,
+ `src="/api/plugins/${plugin.name}/files/gsm3-api.js"`
+ )
+
+ // 确保gsm3-api.js脚本标签有正确的type属性
+ injectedContent = injectedContent.replace(
+ /`
+ )
+
+ // 注入token设置脚本
+ injectedContent = injectedContent.replace(
+ '',
+ `
+ `
+ )
+
+ // 在body结束前注入token设置脚本,确保在gsm3-api.js完全初始化后执行
+ injectedContent = injectedContent.replace(
+ '