Files
scriptforge/backend/internal/config/runtime.go
zhilv e6e4357a28 feat: 脚本创作+发布+市场体系
- 数据模型新增: title(必填), description(可选), status(draft/published)
- 新增 API: POST /scripts/:id/publish, GET /api/market (搜索+分页+runtime过滤)
- 前端首页重构: 选语言 → CodeMirror 编辑器(8种语言语法高亮) → 标题/描述 → 草稿/发布
- 新增 /market 页面: 浏览已发布脚本, 搜索+过滤+分页
- 详情页新增: 发布按钮(草稿→市场), title/description 展示
- Shell 类运行时显示 source 命令(继承环境变量)
- backend GetSourceCommand 支持 bash/zsh/sh/fish 四种 shell 格式

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-29 14:04:15 +08:00

59 lines
1.4 KiB
Go

package config
type RuntimeConfig struct {
Name string
Extension string
MIMEType string
}
var Runtimes = []RuntimeConfig{
{Name: "bash", Extension: ".sh", MIMEType: "text/x-shellscript"},
{Name: "zsh", Extension: ".zsh", MIMEType: "text/x-shellscript"},
{Name: "sh", Extension: ".sh", MIMEType: "text/x-shellscript"},
{Name: "fish", Extension: ".fish", MIMEType: "text/x-shellscript"},
{Name: "python3", Extension: ".py", MIMEType: "text/x-python"},
{Name: "node", Extension: ".js", MIMEType: "text/javascript"},
{Name: "ruby", Extension: ".rb", MIMEType: "text/x-ruby"},
{Name: "php", Extension: ".php", MIMEType: "text/x-php"},
}
var RuntimeMap map[string]RuntimeConfig
func init() {
RuntimeMap = make(map[string]RuntimeConfig, len(Runtimes))
for _, rt := range Runtimes {
RuntimeMap[rt.Name] = rt
}
}
func IsValidRuntime(name string) bool {
_, ok := RuntimeMap[name]
return ok
}
func GetRuntime(name string) (RuntimeConfig, bool) {
rt, ok := RuntimeMap[name]
return rt, ok
}
func IsShellRuntime(name string) bool {
switch name {
case "bash", "zsh", "sh", "fish":
return true
}
return false
}
func GetSourceCommand(url, runtime string) string {
switch runtime {
case "bash", "zsh":
return "source <(curl " + url + ")"
case "sh":
return ". <(curl " + url + ")"
case "fish":
return "curl " + url + " | source"
default:
return ""
}
}