Files
zeekay 0c7efccf40 feat: Add new Dockerfiles and improve containerization
- Add main Dockerfile for production builds
- Add Dockerfile.runtime for secure code execution
- Add Dockerfile.runtime.fixed with improved configuration
- Include .dockerignore for build optimization
- Add integration documentation and publishing guides
- Update API and CLI components for better runtime support
- Enhance sandbox and container management features
2025-08-16 23:03:39 -05:00

60 lines
1.1 KiB
Go

// Copyright 2025 Hanzo Industries Inc.
// SPDX-License-Identifier: AGPL-3.0
package fs
import (
"fmt"
"net/http"
"os"
"strings"
"github.com/gin-gonic/gin"
)
func ReplaceInFiles(c *gin.Context) {
var req ReplaceRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("invalid request body: %w", err))
return
}
results := make([]ReplaceResult, 0, len(req.Files))
for _, filePath := range req.Files {
content, err := os.ReadFile(filePath)
if err != nil {
results = append(results, ReplaceResult{
File: filePath,
Success: false,
Error: err.Error(),
})
continue
}
newValue := ""
if req.NewValue != nil {
newValue = *req.NewValue
}
newContent := strings.ReplaceAll(string(content), req.Pattern, newValue)
err = os.WriteFile(filePath, []byte(newContent), 0644)
if err != nil {
results = append(results, ReplaceResult{
File: filePath,
Success: false,
Error: err.Error(),
})
continue
}
results = append(results, ReplaceResult{
File: filePath,
Success: true,
})
}
c.JSON(http.StatusOK, results)
}