Store workflow definitions as table rows and drop YAML
This commit is contained in:
@@ -4,14 +4,11 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"g.fc.run/ai/byre/internal/api"
|
||||
"g.fc.run/ai/byre/internal/workflow"
|
||||
)
|
||||
|
||||
const maxWorkflowFileBytes = 1 << 20
|
||||
const maxWorkflowBytes = 1 << 20
|
||||
|
||||
func (s *Server) ListWorkflows(w http.ResponseWriter, r *http.Request) {
|
||||
workflows, err := s.store.ListWorkflows(r.Context())
|
||||
@@ -23,38 +20,25 @@ func (s *Server) ListWorkflows(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *Server) GetWorkflow(w http.ResponseWriter, r *http.Request, name string) {
|
||||
accept := r.Header.Get("Accept")
|
||||
if strings.Contains(accept, "application/json") && !strings.Contains(accept, "yaml") {
|
||||
def, err := s.store.GetWorkflow(r.Context(), name)
|
||||
if err != nil {
|
||||
writeStoreError(w, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, def)
|
||||
return
|
||||
}
|
||||
file, err := s.agents.WorkflowFile(r.Context(), name)
|
||||
def, err := s.store.GetWorkflow(r.Context(), name)
|
||||
if err != nil {
|
||||
writeAgentError(w, err)
|
||||
writeStoreError(w, err)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/yaml")
|
||||
w.Header().Set("Content-Disposition", "attachment; filename*=UTF-8''"+url.PathEscape(workflow.Filename(name)))
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(file)
|
||||
writeJSON(w, http.StatusOK, def)
|
||||
}
|
||||
|
||||
func (s *Server) PutWorkflow(w http.ResponseWriter, r *http.Request, name string, params api.PutWorkflowParams) {
|
||||
file, err := io.ReadAll(http.MaxBytesReader(w, r.Body, maxWorkflowFileBytes))
|
||||
body, err := io.ReadAll(http.MaxBytesReader(w, r.Body, maxWorkflowBytes))
|
||||
if err != nil {
|
||||
writeError(w, http.StatusBadRequest, fmt.Errorf("read workflow file: %w", err))
|
||||
writeError(w, http.StatusBadRequest, fmt.Errorf("read workflow: %w", err))
|
||||
return
|
||||
}
|
||||
from := ""
|
||||
if params.From != nil {
|
||||
from = *params.From
|
||||
}
|
||||
summary, err := s.agents.SaveWorkflow(r.Context(), name, from, file, actor(r))
|
||||
summary, err := s.agents.SaveWorkflow(r.Context(), name, from, body, actor(r))
|
||||
if err != nil {
|
||||
writeAgentError(w, err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user