whiteboard

package
v1.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Copyright (c) 2026 Lark Technologies Pte. Ltd. SPDX-License-Identifier: MIT

Index

Constants

View Source
const (
	WhiteboardQueryAsImage = "image"
	WhiteboardQueryAsCode  = "code"
	WhiteboardQueryAsRaw   = "raw"
)
View Source
const (
	FormatRaw      = "raw"
	FormatPlantUML = "plantuml"
	FormatMermaid  = "mermaid"
)
View Source
const WhiteboardUpdateDescription = "" /* 137-byte string literal not displayed */

Variables

View Source
var SyntaxTypeExtensionMap = map[SyntaxType]string{
	SyntaxTypePlantUML: ".puml",
	SyntaxTypeMermaid:  ".mmd",
}
View Source
var SyntaxTypeNameMap = map[SyntaxType]string{
	SyntaxTypePlantUML: "plantuml",
	SyntaxTypeMermaid:  "mermaid",
}
View Source
var WhiteboardQuery = common.Shortcut{
	Service:     "whiteboard",
	Command:     "+query",
	Description: "Query a existing whiteboard, export it as preview image or raw nodes structure.",
	Risk:        "read",
	Scopes:      []string{"board:whiteboard:node:read"},
	AuthTypes:   []string{"user", "bot"},
	Flags: []common.Flag{
		{Name: "whiteboard-token", Desc: "whiteboard token of the whiteboard. You will need read permission to download preview image.", Required: true},
		{Name: "output_as", Desc: "output whiteboard as: image | code | raw.", Required: true},
		{Name: "output", Desc: "output directory. It is required when output as image. If not specified when --output_as code/raw, it will output directly.", Required: false},
		{Name: "overwrite", Desc: "overwrite existing file if it exists", Required: false, Type: "bool"},
	},
	HasFormat: true,
	Validate: func(ctx context.Context, runtime *common.RuntimeContext) error {

		token := runtime.Str("whiteboard-token")
		if err := validate.RejectControlChars(token, "whiteboard-token"); err != nil {
			return err
		}
		out := runtime.Str("output")
		if out != "" {
			if err := runtime.ValidatePath(out); err != nil {
				return output.ErrValidation("invalid output path: %s", err)
			}
		}
		if out == "" && runtime.Str("output_as") == WhiteboardQueryAsImage {
			return output.ErrValidation("need a output directory to query whiteboard as image")
		}

		as := runtime.Str("output_as")
		if as != WhiteboardQueryAsImage && as != WhiteboardQueryAsCode && as != WhiteboardQueryAsRaw {
			return common.FlagErrorf("--output_as flag must be one of: image | code | raw")
		}
		return nil
	},
	DryRun: func(ctx context.Context, runtime *common.RuntimeContext) *common.DryRunAPI {
		as := runtime.Str("output_as")
		token := runtime.Str("whiteboard-token")
		switch as {
		case WhiteboardQueryAsImage:
			return common.NewDryRunAPI().
				GET(fmt.Sprintf("/open-apis/board/v1/whiteboards/%s/download_as_image", common.MaskToken(url.PathEscape(token)))).
				Desc("Export preview image of given whiteboard")
		case WhiteboardQueryAsCode:
			return common.NewDryRunAPI().
				GET(fmt.Sprintf("/open-apis/board/v1/whiteboards/%s/nodes", common.MaskToken(url.PathEscape(token)))).
				Desc("Extract Mermaid/Plantuml code from given whiteboard")
		case WhiteboardQueryAsRaw:
			return common.NewDryRunAPI().
				GET(fmt.Sprintf("/open-apis/board/v1/whiteboards/%s/nodes", common.MaskToken(url.PathEscape(token)))).
				Desc("Extract raw nodes structure from given whiteboard")
		default:
			return common.NewDryRunAPI().Desc("invalid --output_as flag, must be one of: image | code | raw")
		}
	},
	Execute: func(ctx context.Context, runtime *common.RuntimeContext) error {

		token := runtime.Str("whiteboard-token")
		outDir := runtime.Str("output")
		as := runtime.Str("output_as")
		switch as {
		case WhiteboardQueryAsImage:
			return exportWhiteboardPreview(ctx, runtime, token, outDir)
		case WhiteboardQueryAsCode:
			return exportWhiteboardCode(runtime, token, outDir)
		case WhiteboardQueryAsRaw:
			return exportWhiteboardRaw(runtime, token, outDir)
		default:
			return output.ErrValidation("--as flag must be one of: image | code | raw")
		}

	},
}
View Source
var WhiteboardUpdate = common.Shortcut{
	Service:     "whiteboard",
	Command:     "+update",
	Description: WhiteboardUpdateDescription,
	Risk:        "high-risk-write",
	Scopes:      wbUpdateScopes,
	AuthTypes:   wbUpdateAuthTypes,
	Flags:       wbUpdateFlags,
	HasFormat:   false,
	Validate:    wbUpdateValidate,
	DryRun:      wbUpdateDryRun,
	Execute:     wbUpdateExecute,
}
View Source
var WhiteboardUpdateOld = common.Shortcut{
	Service:     "docs",
	Command:     "+whiteboard-update",
	Description: WhiteboardUpdateDescription,
	Risk:        "high-risk-write",
	Scopes:      wbUpdateScopes,
	AuthTypes:   wbUpdateAuthTypes,
	Flags:       wbUpdateFlags,
	HasFormat:   false,
	Validate:    wbUpdateValidate,
	DryRun:      wbUpdateDryRun,
	Execute:     wbUpdateExecute,
}

WhiteboardUpdateOld 向前兼容历史版本 Doc 域下的更新命令

Functions

func Shortcuts

func Shortcuts() []common.Shortcut

Shortcuts returns all whiteboard shortcuts.

Types

type SyntaxType added in v1.0.8

type SyntaxType int
const (
	SyntaxTypePlantUML SyntaxType = 1
	SyntaxTypeMermaid  SyntaxType = 2
)

func (SyntaxType) ExtensionName added in v1.0.8

func (s SyntaxType) ExtensionName() string

func (SyntaxType) IsValid added in v1.0.8

func (s SyntaxType) IsValid() bool

func (SyntaxType) String added in v1.0.8

func (s SyntaxType) String() string

type WbCliOutput

type WbCliOutput struct {
	Code     int `json:"code"`
	Data     WbCliOutputData
	RawNodes []interface{} `json:"nodes"` // 从 whiteboard-cli -t openapi 输出的原始请求格式
}

type WbCliOutputData

type WbCliOutputData struct {
	To     string `json:"to"`
	Result struct {
		Nodes []interface{} `json:"nodes"`
	} `json:"result"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL