This commit is contained in:
Josh at WLTechBlog
2025-12-16 12:26:36 -07:00
parent 051b912122
commit 34a512e278
9 changed files with 2450 additions and 0 deletions

View File

@@ -4576,3 +4576,175 @@ func (c *Client) GetFormAccessibilityAudit(tabID, formSelector string, timeout i
return &result, nil
}
// DiviStructure represents the extracted Divi page structure
type DiviStructure struct {
URL string `json:"url"`
Sections []DiviSection `json:"sections"`
Metadata struct {
ExtractionDate string `json:"extraction_date"`
Accuracy string `json:"accuracy"`
Limitations string `json:"limitations"`
} `json:"metadata"`
}
// DiviSection represents a Divi section
type DiviSection struct {
Type string `json:"type"` // regular, specialty, fullwidth
HasParallax bool `json:"has_parallax"`
BackgroundColor string `json:"background_color"`
BackgroundImage string `json:"background_image"`
BackgroundStyle string `json:"background_style"`
Rows []DiviRow `json:"rows"`
CSSClasses []string `json:"css_classes"`
}
// DiviRow represents a Divi row
type DiviRow struct {
ColumnStructure string `json:"column_structure"` // e.g., "1_2,1_2" for two half columns
Columns []DiviColumn `json:"columns"`
CSSClasses []string `json:"css_classes"`
}
// DiviColumn represents a Divi column
type DiviColumn struct {
Type string `json:"type"` // e.g., "1_2", "1_3", "4_4"
Modules []DiviModule `json:"modules"`
CSSClasses []string `json:"css_classes"`
}
// DiviModule represents a Divi module
type DiviModule struct {
Type string `json:"type"` // text, image, button, blurb, etc.
Content string `json:"content"`
Attributes map[string]string `json:"attributes"`
CSSClasses []string `json:"css_classes"`
}
// DiviImage represents an extracted image
type DiviImage struct {
URL string `json:"url"`
Alt string `json:"alt"`
Title string `json:"title"`
Width int `json:"width"`
Height int `json:"height"`
Context string `json:"context"` // e.g., "section 0, row 0, column 0, module 2"
IsBackground bool `json:"is_background"`
}
// DiviContent represents extracted content
type DiviContent struct {
URL string `json:"url"`
Modules []DiviModule `json:"modules"`
Images []DiviImage `json:"images"`
Metadata struct {
ExtractionDate string `json:"extraction_date"`
TotalModules int `json:"total_modules"`
TotalImages int `json:"total_images"`
} `json:"metadata"`
}
// ExtractDiviStructure extracts Divi page structure from rendered HTML
func (c *Client) ExtractDiviStructure(tabID string, timeout int) (*DiviStructure, error) {
params := map[string]string{}
if tabID != "" {
params["tab"] = tabID
}
if timeout > 0 {
params["timeout"] = strconv.Itoa(timeout)
}
resp, err := c.SendCommand("extract-divi-structure", params)
if err != nil {
return nil, err
}
if !resp.Success {
return nil, fmt.Errorf("failed to extract Divi structure: %s", resp.Error)
}
var result DiviStructure
dataBytes, err := json.Marshal(resp.Data)
if err != nil {
return nil, fmt.Errorf("failed to marshal response data: %w", err)
}
err = json.Unmarshal(dataBytes, &result)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal Divi structure: %w", err)
}
return &result, nil
}
// ExtractDiviImages extracts all images from a Divi page
func (c *Client) ExtractDiviImages(tabID string, timeout int) ([]DiviImage, error) {
params := map[string]string{}
if tabID != "" {
params["tab"] = tabID
}
if timeout > 0 {
params["timeout"] = strconv.Itoa(timeout)
}
resp, err := c.SendCommand("extract-divi-images", params)
if err != nil {
return nil, err
}
if !resp.Success {
return nil, fmt.Errorf("failed to extract Divi images: %s", resp.Error)
}
var result []DiviImage
dataBytes, err := json.Marshal(resp.Data)
if err != nil {
return nil, fmt.Errorf("failed to marshal response data: %w", err)
}
err = json.Unmarshal(dataBytes, &result)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal Divi images: %w", err)
}
return result, nil
}
// ExtractDiviContent extracts text content and module data from Divi pages
func (c *Client) ExtractDiviContent(tabID string, timeout int) (*DiviContent, error) {
params := map[string]string{}
if tabID != "" {
params["tab"] = tabID
}
if timeout > 0 {
params["timeout"] = strconv.Itoa(timeout)
}
resp, err := c.SendCommand("extract-divi-content", params)
if err != nil {
return nil, err
}
if !resp.Success {
return nil, fmt.Errorf("failed to extract Divi content: %s", resp.Error)
}
var result DiviContent
dataBytes, err := json.Marshal(resp.Data)
if err != nil {
return nil, fmt.Errorf("failed to marshal response data: %w", err)
}
err = json.Unmarshal(dataBytes, &result)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal Divi content: %w", err)
}
return &result, nil
}