Release 2.7.0: executable handbooks and native user-site workflows
This commit is contained in:
1 parent
aa0c4d0f55
commit
d9aef957f7
562 files changed
+21064
-20387
No files matched your search
@@ -2,10 +2,12 @@
|
||||
package artifact
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/marqdo/marqdo/plugins/web/internal/render"
|
||||
@@ -94,9 +96,17 @@ func ParseFrontmatter(src string) (meta map[string]string, body string) {
|
||||
// RenderNodes renders the existing five-column View schema recursively. Container
|
||||
// value cells hold more View rows; markdown leaves hold ordinary Markdown text.
|
||||
func RenderNodes(nodes any) (string, error) {
|
||||
return RenderNodesWithResources(nodes, nil)
|
||||
}
|
||||
|
||||
// ResourceRenderer resolves a typed Resource at the request boundary.
|
||||
// Ordinary View construction remains pure; a nil renderer never starts IO.
|
||||
type ResourceRenderer func(map[string]any) (string, error)
|
||||
|
||||
func RenderNodesWithResources(nodes any, resources ResourceRenderer) (string, error) {
|
||||
var b strings.Builder
|
||||
b.WriteString(`<style>` + LayoutCSS + `</style><div class="mq-view">`)
|
||||
if err := renderNodes(&b, nodes, 0); err != nil {
|
||||
if err := renderNodes(&b, nodes, 0, resources); err != nil {
|
||||
return "", err
|
||||
}
|
||||
b.WriteString(`</div>`)
|
||||
@@ -105,7 +115,7 @@ func RenderNodes(nodes any) (string, error) {
|
||||
|
||||
// Fixed runtime geometry, shared by offline previews and served Documents.
|
||||
// Authors choose row/column instead of embedding CSS or HTML in content cells.
|
||||
const LayoutCSS = `.mq-view{max-width:72rem;margin:auto;padding:1.5rem;line-height:1.6;font-family:system-ui,sans-serif}.mq-view *{box-sizing:border-box}.mq-view .mq-row{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,16rem),1fr));gap:1.5rem}.mq-view .mq-column{display:flex;flex-direction:column;gap:1.5rem}.mq-view .mq-node{min-width:0}.mq-view nav,.mq-view footer{padding-block:1rem}.mq-view footer{border-top:1px solid #d5dce5}.mq-view a{color:#2457a7}.mq-view img{max-width:100%;height:auto}.mq-view pre{overflow:auto}`
|
||||
const LayoutCSS = `.mq-view{max-width:72rem;margin:auto;padding:1.5rem;line-height:1.6;font-family:system-ui,sans-serif}.mq-view *{box-sizing:border-box}.mq-view .mq-row{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,16rem),1fr));gap:1.5rem}.mq-view .mq-column{display:flex;flex-direction:column;gap:1.5rem}.mq-view .mq-node{min-width:0;overflow-wrap:anywhere}.mq-view nav,.mq-view footer{padding-block:1rem}.mq-view footer{border-top:1px solid #d5dce5}.mq-view a{color:#2457a7}.mq-view img{max-width:100%;height:auto}.mq-view pre{overflow:auto}.mq-view input,.mq-view textarea,.mq-view select{max-width:100%;font:inherit}.mq-view textarea{width:100%}`
|
||||
|
||||
// Preserve typed value cells when normalizing column tables. General AsRows
|
||||
// treats @ cells as text, which would stringify nested component tables.
|
||||
@@ -148,7 +158,85 @@ func viewRows(nodes any) ([]any, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func renderNodes(b *strings.Builder, nodes any, depth int) error {
|
||||
func containerTag(kind string) (string, string) {
|
||||
switch kind {
|
||||
case "row", "横排":
|
||||
return "div", " mq-row"
|
||||
case "column", "纵排":
|
||||
return "div", " mq-column"
|
||||
case "nav", "导航":
|
||||
return "nav", ""
|
||||
case "header", "页头":
|
||||
return "header", ""
|
||||
case "footer", "页脚":
|
||||
return "footer", ""
|
||||
case "section", "区域":
|
||||
return "section", ""
|
||||
case "aside", "侧栏":
|
||||
return "aside", ""
|
||||
case "form", "表单":
|
||||
return "form", ""
|
||||
case "list", "列表":
|
||||
return "ul", ""
|
||||
case "item", "列表项":
|
||||
return "li", ""
|
||||
case "select", "选择":
|
||||
return "select", ""
|
||||
}
|
||||
return "", ""
|
||||
}
|
||||
|
||||
// FindSlot selects one declared View region without resolving any Resources.
|
||||
// Container traversal is identical to rendering and never descends into a
|
||||
// Resource's private map as if it were another View table.
|
||||
func FindSlot(nodes any, slot string) (any, bool, error) {
|
||||
var selected []any
|
||||
var walk func(any, int) error
|
||||
walk = func(nodes any, depth int) error {
|
||||
if depth > 64 {
|
||||
return fmt.Errorf("View: nesting exceeds 64 levels")
|
||||
}
|
||||
rows, err := viewRows(nodes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, value := range rows {
|
||||
row, ok := value.(map[string]any)
|
||||
if !ok {
|
||||
return fmt.Errorf("View slot: expected a row map")
|
||||
}
|
||||
if first(row, "slot", "槽") == slot {
|
||||
selected = append(selected, row)
|
||||
}
|
||||
kind := strings.ToLower(first(row, "type", "类型"))
|
||||
if tag, _ := containerTag(kind); tag != "" {
|
||||
children := row["value"]
|
||||
if children == nil {
|
||||
children = row["值"]
|
||||
}
|
||||
if children == nil {
|
||||
return fmt.Errorf("View %s: missing child rows", kind)
|
||||
}
|
||||
if err := walk(children, depth+1); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if err := walk(nodes, 0); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if len(selected) > 1 {
|
||||
return nil, false, fmt.Errorf("View slot %q is ambiguous", slot)
|
||||
}
|
||||
if len(selected) == 0 {
|
||||
return nil, false, nil
|
||||
}
|
||||
return selected, true, nil
|
||||
}
|
||||
|
||||
func renderNodes(b *strings.Builder, nodes any, depth int, resources ResourceRenderer) error {
|
||||
if depth > 64 {
|
||||
return fmt.Errorf("View: nesting exceeds 64 levels")
|
||||
}
|
||||
@@ -165,6 +253,10 @@ func renderNodes(b *strings.Builder, nodes any, depth int) error {
|
||||
slot := first(row, "slot", "槽")
|
||||
val := first(row, "value", "值")
|
||||
attrs := first(row, "attrs", "属性")
|
||||
attributes, err := renderAttributes(row)
|
||||
if err != nil {
|
||||
return fmt.Errorf("View row %d: %w", i+1, err)
|
||||
}
|
||||
style := first(row, "style", "样式")
|
||||
class := "mq-node"
|
||||
if style != "" {
|
||||
@@ -173,25 +265,8 @@ func renderNodes(b *strings.Builder, nodes any, depth int) error {
|
||||
if slot != "" {
|
||||
class += " slot-" + html.EscapeString(slot)
|
||||
}
|
||||
tag := ""
|
||||
switch ty {
|
||||
case "row", "横排":
|
||||
tag = "div"
|
||||
class += " mq-row"
|
||||
case "column", "纵排":
|
||||
tag = "div"
|
||||
class += " mq-column"
|
||||
case "nav", "导航":
|
||||
tag = "nav"
|
||||
case "header", "页头":
|
||||
tag = "header"
|
||||
case "footer", "页脚":
|
||||
tag = "footer"
|
||||
case "section", "区域":
|
||||
tag = "section"
|
||||
case "aside", "侧栏":
|
||||
tag = "aside"
|
||||
}
|
||||
tag, geometry := containerTag(ty)
|
||||
class += geometry
|
||||
if tag != "" {
|
||||
children := row["value"]
|
||||
if children == nil {
|
||||
@@ -200,23 +275,72 @@ func renderNodes(b *strings.Builder, nodes any, depth int) error {
|
||||
if children == nil {
|
||||
return fmt.Errorf("View row %d (%s): missing child rows in value", i+1, ty)
|
||||
}
|
||||
b.WriteString(`<` + tag + ` class="` + class + `">`)
|
||||
if err := renderNodes(b, children, depth+1); err != nil {
|
||||
b.WriteString(`<` + tag + ` class="` + class + `"` + attributes + `>`)
|
||||
if err := renderNodes(b, children, depth+1, resources); err != nil {
|
||||
return fmt.Errorf("View %s/%s: %w", ty, slot, err)
|
||||
}
|
||||
b.WriteString(`</` + tag + `>`)
|
||||
continue
|
||||
}
|
||||
switch ty {
|
||||
case "resource", "资源":
|
||||
value := row["value"]
|
||||
if value == nil {
|
||||
value = row["值"]
|
||||
}
|
||||
resource, ok := value.(map[string]any)
|
||||
if !ok || first(resource, "_type") == "" {
|
||||
return fmt.Errorf("View row %d: resource value must be a typed Resource", i+1)
|
||||
}
|
||||
if first(resource, "_type") == "document_head" {
|
||||
if _, err := ParseDocumentHead(resource); err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
if resources == nil {
|
||||
return fmt.Errorf("View row %d: resource requires an explicit request renderer", i+1)
|
||||
}
|
||||
fragment, err := resources(resource)
|
||||
if err != nil {
|
||||
return fmt.Errorf("View resource %s: %w", slot, err)
|
||||
}
|
||||
b.WriteString(`<section class="` + class + `"` + attributes + `>` + fragment + `</section>`)
|
||||
case "markdown", "正文":
|
||||
b.WriteString(`<div class="` + class + `">` + render.MarkdownToHTML(val) + `</div>`)
|
||||
b.WriteString(`<div class="` + class + `"` + attributes + `>` + render.MarkdownToHTML(val) + `</div>`)
|
||||
case "title", "标题":
|
||||
b.WriteString(`<h1 class="` + class + `">` + inline(val) + `</h1>`)
|
||||
b.WriteString(`<h1 class="` + class + `"` + attributes + `>` + inline(val) + `</h1>`)
|
||||
case "link", "链接":
|
||||
if attrs == "" {
|
||||
attrs = "#"
|
||||
if !hasAttributeMap(row) {
|
||||
if attrs == "" {
|
||||
attrs = "#"
|
||||
}
|
||||
attributes = ` href="` + html.EscapeString(attrs) + `"`
|
||||
}
|
||||
b.WriteString(`<a class="` + class + `"` + attributes + `>` + inline(val) + `</a>`)
|
||||
case "input", "输入":
|
||||
b.WriteString(`<input class="` + class + `"` + attributes + ` value="` + html.EscapeString(val) + `">`)
|
||||
case "button", "按钮", "textarea", "多行输入", "label", "标签", "pre", "预格式", "option", "选项":
|
||||
tags := map[string]string{"button": "button", "按钮": "button", "textarea": "textarea", "多行输入": "textarea", "label": "label", "标签": "label", "pre": "pre", "预格式": "pre", "option": "option", "选项": "option"}
|
||||
tag := tags[ty]
|
||||
b.WriteString(`<` + tag + ` class="` + class + `"` + attributes + `>` + html.EscapeString(val) + `</` + tag + `>`)
|
||||
case "script", "脚本", "stylesheet", "样式表":
|
||||
url := strings.ToLower(strings.TrimSpace(val))
|
||||
if url == "" || strings.ContainsAny(url, "\r\n\t") || strings.HasPrefix(url, "javascript:") || strings.HasPrefix(url, "vbscript:") {
|
||||
return fmt.Errorf("View row %d: resource requires a nonempty non-script URL", i+1)
|
||||
}
|
||||
if attrs, ok := attributeValue(row).(map[string]any); ok {
|
||||
for _, reserved := range []string{"href", "src", "rel"} {
|
||||
if _, exists := attrs[reserved]; exists {
|
||||
return fmt.Errorf("View row %d: resource URL and relation belong to its kind/value, not attrs.%s", i+1, reserved)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ty == "script" || ty == "脚本" {
|
||||
b.WriteString(`<script src="` + html.EscapeString(val) + `"` + attributes + `></script>`)
|
||||
} else {
|
||||
b.WriteString(`<link rel="stylesheet" href="` + html.EscapeString(val) + `"` + attributes + `>`)
|
||||
}
|
||||
b.WriteString(`<a class="` + class + `" href="` + html.EscapeString(attrs) + `">` + inline(val) + `</a>`)
|
||||
case "html", "原文":
|
||||
b.WriteString(`<div class="` + class + `">` + val + `</div>`)
|
||||
default:
|
||||
@@ -228,31 +352,137 @@ func renderNodes(b *strings.Builder, nodes any, depth int) error {
|
||||
case []any, map[string]any:
|
||||
return fmt.Errorf("View row %d: unknown structural type %q", i+1, ty)
|
||||
}
|
||||
b.WriteString(`<p class="` + class + `">` + inline(val) + `</p>`)
|
||||
b.WriteString(`<p class="` + class + `"` + attributes + `>` + inline(val) + `</p>`)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Attribute records keep controls in the same five-column View schema.
|
||||
// Legacy link rows may still carry a plain href string. Names and scalar values
|
||||
// are checked before emission; handlers and inline style remain explicit escapes.
|
||||
func attributeValue(row map[string]any) any {
|
||||
if value, ok := row["attrs"]; ok && value != nil {
|
||||
return value
|
||||
}
|
||||
return row["属性"]
|
||||
}
|
||||
|
||||
func hasAttributeMap(row map[string]any) bool {
|
||||
_, ok := attributeValue(row).(map[string]any)
|
||||
return ok
|
||||
}
|
||||
|
||||
func renderAttributes(row map[string]any) (string, error) {
|
||||
value := attributeValue(row)
|
||||
if value == nil || value == "" {
|
||||
return "", nil
|
||||
}
|
||||
attrs, ok := value.(map[string]any)
|
||||
if !ok {
|
||||
if _, legacy := value.(string); legacy {
|
||||
return "", nil
|
||||
}
|
||||
return "", fmt.Errorf("attrs must be a scalar attribute record or legacy link URL")
|
||||
}
|
||||
allowed := map[string]bool{
|
||||
"id": true, "title": true, "role": true, "name": true, "type": true,
|
||||
"href": true, "src": true, "action": true, "method": true, "enctype": true,
|
||||
"placeholder": true, "for": true, "rows": true, "cols": true, "size": true,
|
||||
"min": true, "max": true, "step": true, "minlength": true, "maxlength": true,
|
||||
"pattern": true, "autocomplete": true, "target": true, "rel": true,
|
||||
"tabindex": true, "download": true, "accept": true, "alt": true,
|
||||
"integrity": true, "crossorigin": true, "media": true, "referrerpolicy": true,
|
||||
}
|
||||
booleans := map[string]bool{"hidden": true, "disabled": true, "required": true, "readonly": true, "checked": true, "selected": true, "multiple": true, "autofocus": true, "async": true, "defer": true, "nomodule": true}
|
||||
keys := make([]string, 0, len(attrs))
|
||||
for name := range attrs {
|
||||
keys = append(keys, name)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
var out strings.Builder
|
||||
for _, name := range keys {
|
||||
if !(allowed[name] || booleans[name] || validCustomAttribute(name)) {
|
||||
return "", fmt.Errorf("unsupported attribute %q; use attrs data/aria keys for client state", name)
|
||||
}
|
||||
v := attrs[name]
|
||||
if v == nil {
|
||||
continue
|
||||
}
|
||||
if booleans[name] {
|
||||
flag, ok := v.(bool)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("attribute %s requires a boolean", name)
|
||||
}
|
||||
if flag {
|
||||
out.WriteString(" " + name)
|
||||
}
|
||||
continue
|
||||
}
|
||||
switch v.(type) {
|
||||
case string, bool, float64, int, int64, json.Number:
|
||||
default:
|
||||
return "", fmt.Errorf("attribute %s requires a scalar value", name)
|
||||
}
|
||||
text := fmt.Sprint(v)
|
||||
if name == "href" || name == "src" || name == "action" {
|
||||
url := strings.ToLower(strings.TrimSpace(text))
|
||||
if strings.HasPrefix(url, "javascript:") || strings.HasPrefix(url, "vbscript:") {
|
||||
return "", fmt.Errorf("attribute %s cannot execute a script URL", name)
|
||||
}
|
||||
}
|
||||
out.WriteString(" " + name + `="` + html.EscapeString(text) + `"`)
|
||||
}
|
||||
return out.String(), nil
|
||||
}
|
||||
|
||||
func validCustomAttribute(name string) bool {
|
||||
if !(strings.HasPrefix(name, "data-") || strings.HasPrefix(name, "aria-")) {
|
||||
return false
|
||||
}
|
||||
if strings.HasSuffix(name, "-") {
|
||||
return false
|
||||
}
|
||||
for _, char := range name {
|
||||
if !(char >= 'a' && char <= 'z' || char >= '0' && char <= '9' || char == '-' || char == '_') {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// RenderFile explicitly opts a Document into startup-time component assembly.
|
||||
// Documents without view: main retain their existing Markdown/data-source path.
|
||||
func RenderFile(f ArtifactFile, run func(string, map[string]any) (any, error)) (string, bool, error) {
|
||||
// AssembleView runs the existing startup entry once and retains typed rows.
|
||||
// Request resources are deliberately not resolved during assembly.
|
||||
func AssembleView(f ArtifactFile, run func(string, map[string]any) (any, error)) (any, bool, error) {
|
||||
view := metaString(f.Meta, "view", "视图")
|
||||
if view == "" {
|
||||
return MarkdownHTML(f.Body), false, nil
|
||||
return nil, false, nil
|
||||
}
|
||||
if view != "main" {
|
||||
return "", false, fmt.Errorf("%s: view/视图 must be main", f.Rel)
|
||||
return nil, false, fmt.Errorf("%s: view/视图 must be main", f.Rel)
|
||||
}
|
||||
if metaString(f.Meta, "data_source", "数据源") != "" {
|
||||
return "", false, fmt.Errorf("%s: view main is startup assembly; use an ordinary Document for automatic data_source binding", f.Rel)
|
||||
return nil, false, fmt.Errorf("%s: view main is startup assembly; use an ordinary Document for automatic data_source binding", f.Rel)
|
||||
}
|
||||
nodes, err := run(f.Path, nil)
|
||||
if err != nil {
|
||||
return "", false, fmt.Errorf("%s: view main: %w", f.Rel, err)
|
||||
return nil, false, fmt.Errorf("%s: view main: %w", f.Rel, err)
|
||||
}
|
||||
if nodes == nil {
|
||||
return "", false, fmt.Errorf("%s: view main must return View rows", f.Rel)
|
||||
return nil, false, fmt.Errorf("%s: view main must return View rows", f.Rel)
|
||||
}
|
||||
return nodes, true, nil
|
||||
}
|
||||
|
||||
func RenderFile(f ArtifactFile, run func(string, map[string]any) (any, error)) (string, bool, error) {
|
||||
nodes, structured, err := AssembleView(f, run)
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
if !structured {
|
||||
return MarkdownHTML(f.Body), false, nil
|
||||
}
|
||||
html, err := RenderNodes(nodes)
|
||||
if err != nil {
|
||||
@@ -285,8 +515,12 @@ func RenderHTMLPage(title, innerHTML string) string {
|
||||
if t == "" {
|
||||
t = "Marqdo"
|
||||
}
|
||||
return "<!DOCTYPE html><html><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>" + t +
|
||||
"</title></head><body class=\"mq-document\"><main>" + innerHTML + "</main></body></html>"
|
||||
return renderHTMLPageWithHead("<title>"+t+"</title>", innerHTML)
|
||||
}
|
||||
|
||||
func renderHTMLPageWithHead(head, innerHTML string) string {
|
||||
return "<!DOCTYPE html><html><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">" + head +
|
||||
"</head><body class=\"mq-document\"><main>" + innerHTML + "</main></body></html>"
|
||||
}
|
||||
|
||||
// MarkdownHTML exposes render helper.
|
||||
@@ -385,6 +619,7 @@ func SystemRoutes() []map[string]any {
|
||||
return []map[string]any{
|
||||
{"method": "GET", "path": "/_part/*", "kind": "system"},
|
||||
{"method": "GET|POST", "path": "/_form/*", "kind": "system"},
|
||||
{"method": "POST", "path": "/_md", "kind": "system"},
|
||||
{"method": "POST", "path": "/_runtime/tasks", "kind": "system"},
|
||||
{"method": "GET", "path": "/_runtime/tasks/{id}", "kind": "system"},
|
||||
{"method": "POST", "path": "/_runtime/tasks/{id}/cancel", "kind": "system"},
|
||||
@@ -392,55 +627,85 @@ func SystemRoutes() []map[string]any {
|
||||
}
|
||||
}
|
||||
|
||||
// InspectBag builds {declared, system} from an app bag and/or scanned files.
|
||||
// InspectBag reads declarations only. A prepared app's actual handler inventory
|
||||
// is generated by httpx.InspectApp through the same registrar as NewHandler.
|
||||
func InspectBag(app map[string]any, declared []ArtifactFile) map[string]any {
|
||||
var dec []map[string]any
|
||||
for _, a := range declared {
|
||||
dec = append(dec, map[string]any{
|
||||
"method": a.Method,
|
||||
"path": a.Route,
|
||||
"kind": a.Kind,
|
||||
"file": a.Rel,
|
||||
})
|
||||
entries := map[string]map[string]any{}
|
||||
add := func(row map[string]any) {
|
||||
path := first(row, "path")
|
||||
method := first(row, "method")
|
||||
if method == "" {
|
||||
method = "GET"
|
||||
}
|
||||
if path == "" {
|
||||
return
|
||||
}
|
||||
key := method + " " + path
|
||||
if _, exists := entries[key]; !exists {
|
||||
entries[key] = row
|
||||
}
|
||||
}
|
||||
for _, file := range declared {
|
||||
add(map[string]any{"method": file.Method, "path": file.Route, "kind": file.Kind, "file": file.Rel})
|
||||
}
|
||||
if app != nil {
|
||||
switch rows := app["artifact_declared"].(type) {
|
||||
case []map[string]any:
|
||||
for _, row := range rows {
|
||||
add(row)
|
||||
}
|
||||
case []any:
|
||||
for _, value := range rows {
|
||||
if row, ok := value.(map[string]any); ok {
|
||||
add(row)
|
||||
}
|
||||
}
|
||||
}
|
||||
if app["page"] != nil {
|
||||
add(map[string]any{"method": "GET", "path": "/", "kind": "document"})
|
||||
}
|
||||
if routes, ok := app["routes"].(map[string]any); ok {
|
||||
for path := range routes {
|
||||
dec = append(dec, map[string]any{"method": "GET", "path": path, "kind": "declared"})
|
||||
add(map[string]any{"method": "GET", "path": path, "kind": "document"})
|
||||
}
|
||||
}
|
||||
if inv, ok := app["invoke_routes"].(map[string]any); ok {
|
||||
for key, v := range inv {
|
||||
row := map[string]any{"path": key, "kind": "endpoint"}
|
||||
if m, ok := v.(map[string]any); ok {
|
||||
if c, ok := m["class"].(string); ok && c != "" {
|
||||
row["class"] = c
|
||||
for _, group := range []string{"artifact_routes", "invoke_routes"} {
|
||||
if routes, ok := app[group].(map[string]any); ok {
|
||||
for key, value := range routes {
|
||||
spec, _ := value.(map[string]any)
|
||||
method, path := first(spec, "method"), first(spec, "path")
|
||||
if parts := strings.SplitN(key, " ", 2); len(parts) == 2 {
|
||||
if method == "" {
|
||||
method = parts[0]
|
||||
}
|
||||
if path == "" {
|
||||
path = parts[1]
|
||||
}
|
||||
} else if path == "" {
|
||||
path = key
|
||||
}
|
||||
if method, ok := m["method"].(string); ok && method != "" {
|
||||
row["method"] = method
|
||||
if method == "" {
|
||||
method = "GET"
|
||||
}
|
||||
if fn, ok := m["fn"].(string); ok && fn != "" {
|
||||
row["fn"] = fn
|
||||
row := map[string]any{"method": method, "path": path, "kind": "endpoint"}
|
||||
for _, name := range []string{"file", "class", "fn"} {
|
||||
if value := first(spec, name); value != "" {
|
||||
row[name] = value
|
||||
}
|
||||
}
|
||||
add(row)
|
||||
}
|
||||
dec = append(dec, row)
|
||||
}
|
||||
}
|
||||
if art, ok := app["artifact_routes"].(map[string]any); ok {
|
||||
for key, v := range art {
|
||||
m, _ := v.(map[string]any)
|
||||
dec = append(dec, map[string]any{
|
||||
"path": key,
|
||||
"kind": "endpoint",
|
||||
"method": fmt.Sprint(m["method"]),
|
||||
"file": fmt.Sprint(m["file"]),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return map[string]any{
|
||||
"_type": "web_inspection",
|
||||
"declared": dec,
|
||||
"system": SystemRoutes(),
|
||||
keys := make([]string, 0, len(entries))
|
||||
for key := range entries {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
rows := make([]map[string]any, 0, len(keys))
|
||||
for _, key := range keys {
|
||||
rows = append(rows, entries[key])
|
||||
}
|
||||
return map[string]any{"_type": "web_inspection", "scope": "metadata", "declared": rows, "system": SystemRoutes()}
|
||||
}
|
||||
Reference in new issue
Block a user