mirror of
https://github.com/oarkflow/mq.git
synced 2025-10-13 06:33:39 +08:00
feat: [wip] - Implement html node
This commit is contained in:
@@ -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) {
|
||||
|
@@ -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}
|
||||
|
Reference in New Issue
Block a user