mirror of
https://github.com/hanzoai/runtime.git
synced 2026-10-30 18:23:13 +00:00
- 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
60 lines
1.1 KiB
Go
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)
|
|
}
|