diff --git a/shortcuts/whiteboard/whiteboard_query.go b/shortcuts/whiteboard/whiteboard_query.go index e650ecb45..4b9520564 100644 --- a/shortcuts/whiteboard/whiteboard_query.go +++ b/shortcuts/whiteboard/whiteboard_query.go @@ -167,7 +167,8 @@ type exportResp struct { } `json:"data"` } -// exportWhiteboardSvg exports a whiteboard as SVG and writes it to stdout or a file. +// exportWhiteboardSvg exports a whiteboard as SVG and writes the result to stdout or a file. +// It requests the SVG export for the given whiteboard token and saves the decoded content when an output path is provided. func exportWhiteboardSvg(runtime *common.RuntimeContext, wbToken, outDir string) error { reqBody := exportReq{ExportType: "svg"} req := &larkcore.ApiReq{ @@ -238,6 +239,10 @@ func exportWhiteboardSvg(runtime *common.RuntimeContext, wbToken, outDir string) return nil } +// exportWhiteboardPreview downloads a whiteboard preview image and saves it as a PNG file. +// +// It reports the saved file path and image size on success. +// Returns an error if the API request fails, the response is rejected, or the file cannot be saved. func exportWhiteboardPreview(ctx context.Context, runtime *common.RuntimeContext, wbToken, outDir string) error { req := &larkcore.ApiReq{ HttpMethod: http.MethodGet, @@ -439,6 +444,9 @@ func exportWhiteboardRaw(runtime *common.RuntimeContext, wbToken, outDir string) return nil } +// saveOutputFile writes exported content to a file or directory and returns the final path and written size. +// If outPath is a directory, it creates a file named whiteboard_. If outPath is a file path, +// it adjusts the file extension to ext, validates the path, and respects the overwrite flag. func saveOutputFile(outPath, ext, token string, runtime *common.RuntimeContext, data io.Reader) (string, int64, error) { // Step 1: Get final output path info, err := runtime.FileIO().Stat(outPath) diff --git a/shortcuts/whiteboard/whiteboard_update.go b/shortcuts/whiteboard/whiteboard_update.go index 2afcf752b..fa5eefb9d 100644 --- a/shortcuts/whiteboard/whiteboard_update.go +++ b/shortcuts/whiteboard/whiteboard_update.go @@ -44,6 +44,11 @@ var wbUpdateFlags = []common.Flag{ {Name: "input_format", Desc: "format of input data: raw | plantuml | mermaid | svg. Default is raw.", Required: false}, } +// wbUpdateValidate validates the whiteboard update command arguments. +// +// It checks the whiteboard token and idempotent token for dangerous control +// characters, enforces a minimum length for a non-empty idempotent token, and +// ensures the input format is one of raw, plantuml, mermaid, or svg. func wbUpdateValidate(ctx context.Context, runtime *common.RuntimeContext) error { // 检查 token 是否包含控制字符(空字符串下自动跳过了) if err := common.RejectDangerousCharsTyped("--whiteboard-token", runtime.Str("whiteboard-token")); err != nil { @@ -74,6 +79,8 @@ func getFormat(runtime *common.RuntimeContext) string { return format } +// wbUpdateDryRun describes the HTTP request used to update a whiteboard. +// It returns a failure description when source is missing or cannot be parsed. func wbUpdateDryRun(ctx context.Context, runtime *common.RuntimeContext) *common.DryRunAPI { // 读取输入内容 input := runtime.Str("source") @@ -112,6 +119,10 @@ func wbUpdateDryRun(ctx context.Context, runtime *common.RuntimeContext) *common return desc } +// wbUpdateExecute updates a whiteboard from the supplied source input. +// It requires --source and dispatches to the raw node update path for raw input +// or the diagram import path for PlantUML, Mermaid, and SVG input. +// It returns an error if the source is missing or the input format is unsupported. func wbUpdateExecute(ctx context.Context, runtime *common.RuntimeContext) error { token := runtime.Str("whiteboard-token") overwrite := runtime.Bool("overwrite")