chore: 初始化仓库(零源工具箱 0.1.0 基线)
- Go 主进程 cmd/zerorigin(托盘常驻 + 触发器/规则/动作引擎) - Wails v3 设置进程 cmd/settings(独立 module) - 监督进程 cmd/watchdog(-supervise 异常重启) - 构建脚本 build.bat / NSIS 安装包 deploy/、便携版 portable/ - 架构与 MVP 计划文档 docs/、阶段 0-4 验收记录 deploy/acceptance-0-4.md
This commit is contained in:
commit
0a1c1e82ea
188 files changed
+19926
No files matched your search
@@ -0,0 +1,48 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
pwin "zerorigin/internal/platform/windows"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Register("open_url", func() Action { return &openURLAction{} })
|
||||
}
|
||||
|
||||
// openURLAction 用系统默认浏览器打开 URL。
|
||||
type openURLAction struct{}
|
||||
|
||||
func (a *openURLAction) ID() string { return "open_url" }
|
||||
func (a *openURLAction) Name() string { return "打开链接" }
|
||||
|
||||
func (a *openURLAction) Schema() ActionSchema {
|
||||
return ActionSchema{Params: []ParamSpec{
|
||||
{Name: "url", Type: "string", Required: true},
|
||||
}}
|
||||
}
|
||||
|
||||
func (a *openURLAction) Validate(params map[string]any) error {
|
||||
raw := GetString(params, "url")
|
||||
if raw == "" {
|
||||
return fmt.Errorf("open_url: missing param \"url\"")
|
||||
}
|
||||
u, err := url.Parse(raw)
|
||||
if err != nil {
|
||||
return fmt.Errorf("open_url: invalid url: %v", err)
|
||||
}
|
||||
// 仅允许 http/https,避免被用作本地文件/协议注入。
|
||||
switch strings.ToLower(u.Scheme) {
|
||||
case "http", "https":
|
||||
default:
|
||||
return fmt.Errorf("open_url: unsupported scheme %q (want http/https)", u.Scheme)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *openURLAction) Execute(ctx context.Context, params map[string]any) error {
|
||||
return pwin.OpenPath(GetString(params, "url"))
|
||||
}
|
||||
Reference in new issue
Block a user