feat: [wip] - Implement html node

This commit is contained in:
sujit
2024-11-18 20:55:44 +05:45
parent e3a595aeed
commit ecf9b68b63
2 changed files with 20 additions and 5 deletions

View File

@@ -198,7 +198,7 @@ func (tm *DAG) render(w http.ResponseWriter, request *http.Request) {
result := tm.ProcessTask(ctx, data)
if contentType, ok := result.Ctx.Value(consts.ContentType).(string); ok && contentType == consts.TypeHtml {
w.Header().Set(consts.ContentType, consts.TypeHtml)
data, err := jsonparser.GetString(result.Data, "content")
data, err := jsonparser.GetString(result.Data, "html_content")
if err != nil {
return
}
@@ -258,7 +258,7 @@ func (tm *DAG) taskRender(w http.ResponseWriter, r *http.Request) {
}
if contentType, ok := result.Ctx.Value(consts.ContentType).(string); ok && contentType == consts.TypeHtml {
w.Header().Set(consts.ContentType, consts.TypeHtml)
data, err := jsonparser.GetString(result.Data, "content")
data, err := jsonparser.GetString(result.Data, "html_content")
if err != nil {
return
}
@@ -278,8 +278,23 @@ func (tm *DAG) taskStatusHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, `{"message": "Invalid TaskID"}`, http.StatusNotFound)
return
}
result := make(map[string]TaskState)
for key, value := range manager.taskStates {
rs := jsonparser.Delete(value.Result.Data, "html_content")
state := TaskState{
NodeID: value.NodeID,
Status: value.Status,
UpdatedAt: value.UpdatedAt,
Result: Result{
Data: rs,
Error: value.Result.Error,
Status: value.Result.Status,
},
}
result[key] = state
}
w.Header().Set(consts.ContentType, consts.TypeJson)
json.NewEncoder(w).Encode(manager.taskStates)
json.NewEncoder(w).Encode(result)
}
func (tm *DAG) Start(addr string) {

View File

@@ -26,7 +26,7 @@ func Form(ctx context.Context, payload json.RawMessage) v2.Result {
}
ctx = context.WithValue(ctx, consts.ContentType, consts.TypeHtml)
data := map[string]any{
"content": rs,
"html_content": rs,
}
bt, _ = json.Marshal(data)
return v2.Result{Data: bt, Ctx: ctx}
@@ -79,7 +79,7 @@ func Result(ctx context.Context, payload json.RawMessage) v2.Result {
}
ctx = context.WithValue(ctx, consts.ContentType, consts.TypeHtml)
data := map[string]any{
"content": rs,
"html_content": rs,
}
bt, _ := json.Marshal(data)
return v2.Result{Data: bt, Ctx: ctx}