初始提交: ScriptForge 脚本快速转运行链接服务
Some checks failed
Release / build-and-release (push) Failing after 1m31s
Some checks failed
Release / build-and-release (push) Failing after 1m31s
- Go 后端 (Gin + GORM + SQLite) 提供 API 和纯文本脚本服务 - Vite + React + TypeScript + Tailwind 前端 - 单二进制部署 (Go embed 前端静态文件) - Gitea Actions CI/CD: 打标签自动构建多平台 Release - 支持 bash/zsh/sh/fish/python3/node/ruby/php 8种运行环境 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
41
backend/internal/handler/raw.go
Normal file
41
backend/internal/handler/raw.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"gitea.kmux.cn/zhilv/scriptforge/internal/config"
|
||||
"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
|
||||
}
|
||||
|
||||
rt, _ := config.GetRuntime(script.Runtime)
|
||||
mime := rt.MIMEType
|
||||
ext := rt.Extension
|
||||
if mime == "" {
|
||||
mime = "text/plain"
|
||||
ext = ".sh"
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user