Files
scriptforge/backend/internal/handler/raw.go
zhilv 5414c9c865 feat: 分类/变体体系 + 用户认证 + 管理后台
- 运行时分类体系:Shell/Python/JavaScript/Ruby/PHP 各含变体
- 用户注册/登录(JWT + bcrypt),首个注册用户为管理员
- 管理后台 /admin 动态管理分类和变体
- 脚本市场支持按分类筛选
- CodeMirror 语言模式根据分类名称自动切换
- 结果页展示该分类下所有变体的运行命令
- source 命令变体用于 Shell 类继承环境变量

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

41 lines
963 B
Go

package handler
import (
"errors"
"fmt"
"net/http"
"github.com/gin-gonic/gin"
"gitea.kmux.cn/zhilv/scriptforge/internal/service"
)
func GetRawScript(svc *service.ScriptService) gin.HandlerFunc {
return func(c *gin.Context) {
id := c.Param("id")
script, err := svc.GetByID(id)
if errors.Is(err, service.ErrNotFound) {
c.String(http.StatusNotFound, "script not found or expired\n")
return
}
if err != nil {
c.String(http.StatusInternalServerError, "internal error\n")
return
}
// Use default variant for MIME/extension
variant, verr := svc.GetDefaultVariant(script.CategoryID)
mime := "text/plain"
ext := ".sh"
if verr == nil {
mime = variant.MIMEType
ext = variant.Extension
}
c.Header("Content-Type", mime+"; charset=utf-8")
c.Header("Content-Disposition", fmt.Sprintf(`attachment; filename="script%s"`, ext))
c.Header("X-Content-Type-Options", "nosniff")
c.String(http.StatusOK, script.Content)
}
}