### GET /open-apis/doc/v2/{docToken}/content Source: https://github.com/wsine/feishu2md/wiki/如何手动验证工作流 Retrieves the content of a Feishu document. Requires a `tenant_access_token` and the document's `docToken`. ```APIDOC ## GET /open-apis/doc/v2/{docToken}/content ### Description Retrieves the content of a Feishu document. Requires a `tenant_access_token` and the document's `docToken`. ### Method GET ### Endpoint https://open.feishu.cn/open-apis/doc/v2//content ### Parameters #### Query Parameters - **Authorization** (string) - Required - The authorization token in the format 'Bearer '. ### Request Example ```bash curl -XGET -H 'Authorization: Bearer ' 'https://open.feishu.cn/open-apis/doc/v2//content' ``` ### Response (Response structure depends on the document content and API version. Refer to Feishu API documentation for specific details.) ``` -------------------------------- ### Get App Access Token Source: https://github.com/wsine/feishu2md/wiki/如何手动验证工作流 Use this cURL command to obtain an application access token. Replace placeholders with your actual app ID and app secret. The output includes the access token, tenant access token, and expiration time. ```bash curl -XPOST -H "Content-type: application/json" -d '{ "app_id": "", "app_secret": "" }' 'https://open.feishu.cn/open-apis/auth/v3/app_access_token/internal' ``` ```json { "code": 0, "msg": "success", "app_access_token": "t-abcdefghijkl0123456789", "tenant_access_token": "t-mnopqrstuvwxyz00000", "expire": 7200 } ``` -------------------------------- ### Parse Document Content with ParseDocxContent Source: https://context7.com/wsine/feishu2md/llms.txt Converts Feishu document blocks into Markdown text. This example demonstrates how to integrate with the lute library for post-processing and formatting. ```go package main import ( "context" "fmt" "strings" "github.com/88250/lute" "github.com/Wsine/feishu2md/core" ) func main() { client := core.NewClient("cli_xxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxx") ctx := context.Background() config := core.OutputConfig{ ImageDir: "static", UseHTMLTags: false, } parser := core.NewParser(config) // 获取并解析文档 docx, blocks, err := client.GetDocxContent(ctx, "doxcnxxxxxxxxxx") if err != nil { panic(err) } markdown := parser.ParseDocxContent(docx, blocks) // 替换图片 token 为本地路径 for _, imgToken := range parser.ImgTokens { localPath, _ := client.DownloadImage(ctx, imgToken, config.ImageDir) markdown = strings.Replace(markdown, imgToken, localPath, 1) } // 使用 lute 格式化 Markdown(自动添加空格) engine := lute.New(func(l *lute.Lute) { l.RenderOptions.AutoSpace = true }) result := engine.FormatStr("md", markdown) fmt.Println(result) } ``` -------------------------------- ### Web Service API: GET / Source: https://context7.com/wsine/feishu2md/llms.txt Provides the homepage for the feishu2md Web Service. Users can input a Feishu document URL and click a button to download the converted Markdown file. ```APIDOC ## GET / ### Description Provides the homepage for the feishu2md Web Service. Users can input a Feishu document URL and click a button to download the converted Markdown file. ### Method GET ### Endpoint / ### Parameters N/A ### Request Example ```bash # Access the homepage via a web browser or curl curl http://127.0.0.1:8080/ ``` ### Response #### Success Response (200) Returns an HTML page with an input field for the document URL and a download button. #### Response Example (HTML content for the web page) ``` -------------------------------- ### Docker Compose Configuration Source: https://github.com/wsine/feishu2md/blob/main/README.md Defines a Docker Compose setup for running the feishu2md service. It specifies the image, environment variables for authentication, and port mapping. This is useful for containerized deployments. ```yaml # docker-compose.yml version: '3' services: feishu2md: image: wwwsine/feishu2md environment: FEISHU_APP_ID: FEISHU_APP_SECRET: GIN_MODE: release ports: - "8080:8080" ``` -------------------------------- ### Web Service API: GET /download Source: https://context7.com/wsine/feishu2md/llms.txt Endpoint to download and convert Feishu documents. Accepts a document URL via query parameter. Returns a .md file for documents without images, or a .zip archive containing the .md file and images for documents with images. ```APIDOC ## GET /download ### Description Endpoint to download and convert Feishu documents. Accepts a document URL via query parameter. Returns a .md file for documents without images, or a .zip archive containing the .md file and images for documents with images. ### Method GET ### Endpoint /download ### Parameters #### Query Parameters - **url** (string) - Required - The URL of the Feishu document. This URL must be URL-encoded. ### Request Example ```bash # Download a document without images (returns .md file) curl -o document.md "http://127.0.0.1:8080/download?url=https%3A%2F%2Fexample.feishu.cn%2Fdocx%2Fdoxcnxxxxxxxxxx" # Download a document with images (returns .zip file) curl -o document.zip "http://127.0.0.1:8080/download?url=https%3A%2F%2Fexample.feishu.cn%2Fdocx%2Fdoxcnxxxxxxxxxx" ``` ### Request Example (Python) ```python import urllib.parse import requests doc_url = "https://example.feishu.cn/docx/doxcnxxxxxxxxxx" encoded_url = urllib.parse.quote(doc_url, safe='') response = requests.get(f"http://127.0.0.1:8080/download?url={encoded_url}") # Check Content-Disposition header to determine file type if 'zip' in response.headers.get('Content-Disposition', ''): with open('document.zip', 'wb') as f: f.write(response.content) else: with open('document.md', 'wb') as f: f.write(response.content) ``` ### Response #### Success Response - **Content-Type**: `application/octet-stream` (for .zip) or `text/markdown` (for .md). - **Content-Disposition**: Header indicating the filename (e.g., `attachment; filename="document.zip"`). #### Response Example (Binary content of a .md file or a .zip archive) ``` -------------------------------- ### Get Feishu Document Content Source: https://github.com/wsine/feishu2md/wiki/如何手动验证工作流 This cURL command retrieves the content of a Feishu document. Ensure you replace the docToken with your document's token and the bearer token with the tenant access token obtained previously. The output can help diagnose issues. ```bash curl -XGET -H 'Authorization: Bearer ' 'https://open.feishu.cn/open-apis/doc/v2//content' ``` -------------------------------- ### Create a Parser Instance with NewParser Source: https://context7.com/wsine/feishu2md/llms.txt Initializes a parser with specific output configurations, such as image directory and HTML tag usage. Use this to prepare the environment before fetching and parsing document content. ```go package main import ( "context" "fmt" "github.com/Wsine/feishu2md/core" ) func main() { client := core.NewClient("cli_xxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxx") ctx := context.Background() // 创建输出配置 config := core.OutputConfig{ ImageDir: "static", // 图片保存目录 TitleAsFilename: true, // 使用标题作为文件名 UseHTMLTags: false, // 使用 Markdown 语法而非 HTML 标签 SkipImgDownload: false, // 不跳过图片下载 } // 创建解析器 parser := core.NewParser(config) // 获取文档内容并解析 docx, blocks, _ := client.GetDocxContent(ctx, "doxcnxxxxxxxxxx") markdown := parser.ParseDocxContent(docx, blocks) fmt.Println(markdown) // 获取文档中的图片 token 列表 fmt.Printf("图片数量: %d\n", len(parser.ImgTokens)) for _, token := range parser.ImgTokens { fmt.Printf("图片 Token: %s\n", token) } } ``` -------------------------------- ### Manage Configuration with Config Struct Source: https://context7.com/wsine/feishu2md/llms.txt Demonstrates initializing, writing, and reading configuration settings for the feishu2md core package. ```go package main import ( "fmt" "github.com/Wsine/feishu2md/core" ) func main() { // 创建新配置 config := core.NewConfig("cli_xxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxx") // 配置结构 fmt.Printf("App ID: %s\n", config.Feishu.AppId) fmt.Printf("App Secret: %s\n", config.Feishu.AppSecret) fmt.Printf("图片目录: %s\n", config.Output.ImageDir) // 默认: static fmt.Printf("标题作为文件名: %v\n", config.Output.TitleAsFilename) // 默认: false fmt.Printf("使用HTML标签: %v\n", config.Output.UseHTMLTags) // 默认: false fmt.Printf("跳过图片下载: %v\n", config.Output.SkipImgDownload) // 默认: false // 获取配置文件路径 configPath, _ := core.GetConfigFilePath() fmt.Printf("配置文件路径: %s\n", configPath) // 写入配置文件 err := config.WriteConfig2File(configPath) if err != nil { panic(err) } // 读取配置文件 loadedConfig, err := core.ReadConfigFromFile(configPath) if err != nil { panic(err) } fmt.Printf("已加载 App ID: %s\n", loadedConfig.Feishu.AppId) } ``` -------------------------------- ### Feishu2md Download Command Help Source: https://github.com/wsine/feishu2md/blob/main/README.md Displays help for the 'download' (or 'dl') command, outlining options for specifying output directory, dumping API responses, and batch downloading. Use this to understand download parameters. ```bash $ feishu2md dl -h NAME: feishu2md download - Download feishu/larksuite document to markdown file USAGE: feishu2md download [command options] OPTIONS: --output value, -o value Specify the output directory for the markdown files (default: "./") --dump Dump json response of the OPEN API (default: false) --batch Download all documents under a folder (default: false) --wiki Download all documents within the wiki. (default: false) --help, -h show help (default: false) ``` -------------------------------- ### Initialize Feishu Client in Go Source: https://context7.com/wsine/feishu2md/llms.txt Use the core package to instantiate a client with built-in rate limiting and timeout handling for API interactions. ```go package main import ( "context" "fmt" "github.com/Wsine/feishu2md/core" ) func main() { // 创建客户端 client := core.NewClient( "cli_xxxxxxxxxxxx", // App ID "xxxxxxxxxxxxxxxxxxxxxxxx", // App Secret ) ctx := context.Background() // 使用客户端获取文档内容 docx, blocks, err := client.GetDocxContent(ctx, "doxcnxxxxxxxxxx") if err != nil { panic(err) } fmt.Printf("文档标题: %s\n", docx.Title) fmt.Printf("块数量: %d\n", len(blocks)) } ``` -------------------------------- ### Deploy and Access Web Service Source: https://context7.com/wsine/feishu2md/llms.txt Run the service via Docker and interact with the web interface or API endpoints. ```bash # 启动 Web 服务 docker run -it --rm -p 8080:8080 \ -e FEISHU_APP_ID=cli_xxxxxxxxxxxx \ -e FEISHU_APP_SECRET=xxxxxxxxxxxxxxxxxxxxxxxx \ -e GIN_MODE=release \ wwwsine/feishu2md # 访问首页 curl http://127.0.0.1:8080/ # 返回 HTML 页面,包含文档链接输入框和下载按钮 ``` -------------------------------- ### Feishu2md Config Command Help Source: https://github.com/wsine/feishu2md/blob/main/README.md Shows help for the 'config' command, detailing how to set application ID and secret for the OPEN API. These are required for authentication. ```bash $ feishu2md config -h NAME: feishu2md config - Read config file or set field(s) if provided USAGE: feishu2md config [command options] [arguments...] OPTIONS: --appId value Set app id for the OPEN API --appSecret value Set app secret for the OPEN API --help, -h show help (default: false) ``` -------------------------------- ### Feishu2md CLI Help Source: https://github.com/wsine/feishu2md/blob/main/README.md Displays general help information for the feishu2md command-line tool. Use this to understand available commands and global options. ```bash $ feishu2md -h NAME: feishu2md - Download feishu/larksuite document to markdown file USAGE: feishu2md [global options] command [command options] [arguments...] VERSION: v2-0e25fa5 COMMANDS: config Read config file or set field(s) if provided download, dl Download feishu/larksuite document to markdown file help, h Shows a list of commands or help for one command GLOBAL OPTIONS: --help, -h show help (default: false) --version, -v print the version (default: false) ``` -------------------------------- ### Manage Configuration via CLI Source: https://context7.com/wsine/feishu2md/llms.txt Use the config command to set or view App ID and App Secret credentials stored in the system configuration directory. ```bash # 首次配置:设置 App ID 和 App Secret feishu2md config --appId cli_xxxxxxxxxxxx --appSecret xxxxxxxxxxxxxxxxxxxxxxxx # 输出示例: # Configuration file on: /Users/username/Library/Application Support/feishu2md/config.json # { # "feishu": { # "app_id": "cli_xxxxxxxxxxxx", # "app_secret": "xxxxxxxxxxxxxxxxxxxxxxxx" # }, # "output": { # "image_dir": "static", # "title_as_filename": false, # "use_html_tags": false, # "skip_img_download": false # } # } # 查看当前配置(不带参数) feishu2md config # 仅更新 App ID feishu2md config --appId cli_newappid # 仅更新 App Secret feishu2md config --appSecret newsecretvalue ``` -------------------------------- ### Download Single Document via CLI Source: https://context7.com/wsine/feishu2md/llms.txt Download individual docx or wiki pages to Markdown. Use the --dump flag to export raw JSON responses for debugging. ```bash # 下载单个文档到当前目录 feishu2md dl "https://example.feishu.cn/docx/doxcnxxxxxxxxxx" # 输出示例: # Captured document token: doxcnxxxxxxxxxx # Downloaded markdown file to ./doxcnxxxxxxxxxx.md # 指定输出目录 feishu2md dl -o ./output "https://example.feishu.cn/docx/doxcnxxxxxxxxxx" # 下载 Wiki 页面 feishu2md dl "https://example.feishu.cn/wiki/wikcnxxxxxxxxxx" # 同时导出 API 响应的 JSON 数据(用于调试) feishu2md dl --dump "https://example.feishu.cn/docx/doxcnxxxxxxxxxx" # 输出示例: # Captured document token: doxcnxxxxxxxxxx # Dumped json response to ./doxcnxxxxxxxxxx.json # Downloaded markdown file to ./doxcnxxxxxxxxxx.md ``` -------------------------------- ### Batch Download Feishu Wiki Contents Source: https://github.com/wsine/feishu2md/blob/main/README.md Use this command to download all documents from a Feishu wiki. The wiki settings link is required, and the output directory can be specified with the -o flag. ```bash $ feishu2md dl --wiki -o output_directory "https://domain.feishu.cn/wiki/settings/123456789101112" ``` -------------------------------- ### DownloadImageRaw - Download Image as Bytes Source: https://context7.com/wsine/feishu2md/llms.txt Downloads an image and returns the raw byte data, useful for web services or direct binary manipulation. ```go package main import ( "context" "fmt" "github.com/Wsine/feishu2md/core" ) func main() { client := core.NewClient("cli_xxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxx") ctx := context.Background() imgToken := "boxcnxxxxxxxxxx" imgDir := "static" filename, rawData, err := client.DownloadImageRaw(ctx, imgToken, imgDir) if err != nil { fmt.Printf("下载图片失败: %v\n", err) return } fmt.Printf("文件名: %s\n", filename) // static/boxcnxxxxxxxxxx.png fmt.Printf("数据大小: %d bytes\n", len(rawData)) // 可以直接写入 ZIP 或其他用途 // zipWriter.Write(rawData) } ``` -------------------------------- ### Export Knowledge Base via CLI Source: https://context7.com/wsine/feishu2md/llms.txt Export an entire wiki knowledge base using the --wiki flag, which preserves the hierarchy and supports concurrent processing. ```bash # 导出整个知识库 feishu2md dl --wiki "https://example.feishu.cn/wiki/settings/7123456789012345678" # 输出示例: # Downloaded markdown file to ./知识库名称/章节1/文档1.md # Downloaded markdown file to ./知识库名称/章节1/文档2.md # Downloaded markdown file to ./知识库名称/章节2/子章节/文档3.md # 指定输出目录 feishu2md dl --wiki -o ./wiki-backup "https://example.feishu.cn/wiki/settings/7123456789012345678" # 同时导出 JSON 数据 feishu2md dl --wiki --dump -o ./wiki-export "https://example.feishu.cn/wiki/settings/7123456789012345678" ``` -------------------------------- ### Download Documents via Web API Source: https://context7.com/wsine/feishu2md/llms.txt Use the /download endpoint to retrieve converted Markdown or ZIP files. URLs must be properly encoded. ```bash # 下载不含图片的文档(返回 .md 文件) curl -o document.md "http://127.0.0.1:8080/download?url=https%3A%2F%2Fexample.feishu.cn%2Fdocx%2Fdoxcnxxxxxxxxxx" # 下载含图片的文档(返回 .zip 文件) curl -o document.zip "http://127.0.0.1:8080/download?url=https%3A%2F%2Fexample.feishu.cn%2Fdocx%2Fdoxcnxxxxxxxxxx" # URL 需要进行编码,以下是 Python 示例 import urllib.parse import requests doc_url = "https://example.feishu.cn/docx/doxcnxxxxxxxxxx" encoded_url = urllib.parse.quote(doc_url, safe='') response = requests.get(f"http://127.0.0.1:8080/download?url={encoded_url}") # 根据 Content-Type 判断返回类型并保存 if 'zip' in response.headers.get('Content-Disposition', ''): with open('document.zip', 'wb') as f: f.write(response.content) else: with open('document.md', 'wb') as f: f.write(response.content) ``` -------------------------------- ### Download Single Feishu Document Source: https://github.com/wsine/feishu2md/blob/main/README.md Use this command to download a single Feishu document as a Markdown file. Ensure you have obtained the document link through the sharing settings. ```bash $ feishu2md dl "https://domain.feishu.cn/docx/docxtoken" ``` -------------------------------- ### Generate Feishu2Md Configuration Source: https://github.com/wsine/feishu2md/blob/main/testdata/testdocx.1.md Execute this command to generate the configuration file for the Feishu2Md tool. The configuration file stores API credentials and image directory settings. ```bash feishu2md --config ``` -------------------------------- ### NewParser - Create Parser Source: https://context7.com/wsine/feishu2md/llms.txt Creates a document parser instance to convert Feishu document blocks to Markdown. Supports configuration for HTML tag formatting. ```APIDOC ## NewParser - Create Parser ### Description Creates a document parser instance to convert Feishu document blocks to Markdown. Supports configuration for HTML tag formatting. ### Method `NewParser(config OutputConfig) *Parser` ### Parameters #### Request Body - **config** (OutputConfig) - Required - Configuration for output settings. - **ImageDir** (string) - Optional - Directory to save images. - **TitleAsFilename** (bool) - Optional - Use title as filename. - **UseHTMLTags** (bool) - Optional - Use HTML tags for formatting instead of Markdown. - **SkipImgDownload** (bool) - Optional - Skip image download. ### Request Example ```go config := core.OutputConfig{ ImageDir: "static", TitleAsFilename: true, UseHTMLTags: false, SkipImgDownload: false, } parser := core.NewParser(config) ``` ### Response - **Parser** (*Parser) - The created parser instance. ``` -------------------------------- ### Batch Download Folders via CLI Source: https://context7.com/wsine/feishu2md/llms.txt Recursively download all documents within a folder while maintaining directory structure and supporting concurrent downloads. ```bash # 批量下载文件夹内所有文档 feishu2md dl --batch "https://example.feishu.cn/drive/folder/fldcnxxxxxxxxxx" # 输出示例: # Captured folder token: fldcnxxxxxxxxxx # Downloaded markdown file to ./子文件夹/文档1.md # Downloaded markdown file to ./子文件夹/文档2.md # Downloaded markdown file to ./另一个文件夹/文档3.md # 指定输出目录的批量下载 feishu2md dl --batch -o ./docs "https://example.feishu.cn/drive/folder/fldcnxxxxxxxxxx" # 批量下载并导出 JSON feishu2md dl --batch --dump -o ./backup "https://example.feishu.cn/drive/folder/fldcnxxxxxxxxxx" ``` -------------------------------- ### GetWikiNodeInfo - Retrieve Wiki Node Details Source: https://context7.com/wsine/feishu2md/llms.txt Retrieves detailed information about a specific wiki node, such as its type and object token. ```go package main import ( "context" "fmt" "github.com/Wsine/feishu2md/core" ) func main() { client := core.NewClient("cli_xxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxx") ctx := context.Background() // 获取 Wiki 节点信息 node, err := client.GetWikiNodeInfo(ctx, "wikcnxxxxxxxxxx") if err != nil { fmt.Printf("获取节点信息失败: %v\n", err) return } fmt.Printf("节点类型: %s\n", node.ObjType) // 如 "docx" fmt.Printf("对象令牌: %s\n", node.ObjToken) // 实际文档的 token fmt.Printf("节点标题: %s\n", node.Title) } ``` -------------------------------- ### CLI: Single Document Download Source: https://context7.com/wsine/feishu2md/llms.txt Downloads a single Feishu document and converts it to Markdown. Supports direct download of docx and wiki pages, with automatic image handling and local download. ```APIDOC ## feishu2md download (dl) ### Description Downloads a single Feishu document and converts it to Markdown. Supports direct download of docx and wiki pages, with automatic image handling and local download. ### Method CLI Command ### Endpoint N/A ### Parameters #### Path Parameters - **URL** (string) - Required - The URL of the Feishu document (docx or wiki). #### Query Parameters - **-o, --output** (string) - Optional - Specifies the output directory for the downloaded file. - **--dump** (boolean) - Optional - Exports the raw API response JSON data. ### Request Example ```bash # Download to current directory feishu2md dl "https://example.feishu.cn/docx/doxcnxxxxxxxxxx" # Specify output directory feishu2md dl -o ./output "https://example.feishu.cn/docx/doxcnxxxxxxxxxx" # Download Wiki page feishu2md dl "https://example.feishu.cn/wiki/wikcnxxxxxxxxxx" # Download and dump JSON response feishu2md dl --dump "https://example.feishu.cn/docx/doxcnxxxxxxxxxx" ``` ### Response #### Success Response Markdown file saved locally, and optionally JSON response. #### Response Example ``` Captured document token: doxcnxxxxxxxxxx Downloaded markdown file to ./doxcnxxxxxxxxxx.md ``` ``` Captured document token: doxcnxxxxxxxxxx Dumped json response to ./doxcnxxxxxxxxxx.json Downloaded markdown file to ./doxcnxxxxxxxxxx.md ``` ``` -------------------------------- ### Deploy feishu2md with Docker Source: https://context7.com/wsine/feishu2md/llms.txt Provides configuration for Docker Compose and commands for managing the containerized service. ```yaml # docker-compose.yml version: '3' services: feishu2md: image: wwwsine/feishu2md environment: FEISHU_APP_ID: cli_xxxxxxxxxxxx FEISHU_APP_SECRET: xxxxxxxxxxxxxxxxxxxxxxxx GIN_MODE: release ports: - "8080:8080" restart: unless-stopped ``` ```bash # 启动服务 docker compose up -d # 查看日志 docker compose logs -f feishu2md # 停止服务 docker compose down # 直接使用 docker run docker run -d --name feishu2md \ -p 8080:8080 \ -e FEISHU_APP_ID=cli_xxxxxxxxxxxx \ -e FEISHU_APP_SECRET=xxxxxxxxxxxxxxxxxxxxxxxx \ -e GIN_MODE=release \ --restart unless-stopped \ wwwsine/feishu2md ``` -------------------------------- ### CLI: Folder Batch Download Source: https://context7.com/wsine/feishu2md/llms.txt Batch downloads all documents within a Feishu Drive folder. Recursively traverses the folder structure, maintains directory hierarchy, and supports concurrent downloads. ```APIDOC ## feishu2md download --batch ### Description Batch downloads all documents within a Feishu Drive folder. Recursively traverses the folder structure, maintains directory hierarchy, and supports concurrent downloads. ### Method CLI Command ### Endpoint N/A ### Parameters #### Path Parameters - **URL** (string) - Required - The URL of the Feishu Drive folder. #### Query Parameters - **--batch** (boolean) - Required - Enables batch download mode for folders. - **-o, --output** (string) - Optional - Specifies the base output directory for downloaded files. - **--dump** (boolean) - Optional - Exports the raw API response JSON data for each document. ### Request Example ```bash # Batch download folder contents to current directory feishu2md dl --batch "https://example.feishu.cn/drive/folder/fldcnxxxxxxxxxx" # Batch download to a specified output directory feishu2md dl --batch -o ./docs "https://example.feishu.cn/drive/folder/fldcnxxxxxxxxxx" # Batch download and dump JSON responses feishu2md dl --batch --dump -o ./backup "https://example.feishu.cn/drive/folder/fldcnxxxxxxxxxx" ``` ### Response #### Success Response Markdown files saved locally, preserving folder structure. Optionally, JSON responses are also saved. #### Response Example ``` Captured folder token: fldcnxxxxxxxxxx Downloaded markdown file to ./子文件夹/文档1.md Downloaded markdown file to ./子文件夹/文档2.md Downloaded markdown file to ./另一个文件夹/文档3.md ``` ``` -------------------------------- ### DownloadImage - Download Image to File Source: https://context7.com/wsine/feishu2md/llms.txt Downloads an image from a document to the local file system, saving it with its original extension. ```go package main import ( "context" "fmt" "github.com/Wsine/feishu2md/core" ) func main() { client := core.NewClient("cli_xxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxx") ctx := context.Background() // 下载图片到指定目录 imgToken := "boxcnxxxxxxxxxx" outDir := "./static" localPath, err := client.DownloadImage(ctx, imgToken, outDir) if err != nil { fmt.Printf("下载图片失败: %v\n", err) return } fmt.Printf("图片已保存到: %s\n", localPath) // 输出示例: 图片已保存到: ./static/boxcnxxxxxxxxxx.png } ``` -------------------------------- ### Batch Download Feishu Folder Contents Source: https://github.com/wsine/feishu2md/blob/main/README.md This command allows for batch downloading all documents within a specified Feishu folder. Obtain the folder link through sharing settings. The output directory can be specified using the -o flag. ```bash $ feishu2md dl --batch -o output_directory "https://domain.feishu.cn/drive/folder/foldertoken" ``` -------------------------------- ### GetWikiNodeList - List Wiki Nodes Source: https://context7.com/wsine/feishu2md/llms.txt Retrieves a list of nodes within a wiki space, supporting both root and child node retrieval with automatic pagination. ```go package main import ( "context" "fmt" "github.com/Wsine/feishu2md/core" ) func main() { client := core.NewClient("cli_xxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxx") ctx := context.Background() spaceID := "7123456789012345678" // 获取根节点列表(parentNodeToken 为 nil) nodes, err := client.GetWikiNodeList(ctx, spaceID, nil) if err != nil { fmt.Printf("获取节点列表失败: %v\n", err) return } for _, node := range nodes { fmt.Printf("节点标题: %s\n", node.Title) fmt.Printf("节点类型: %s\n", node.ObjType) fmt.Printf("节点令牌: %s\n", node.NodeToken) fmt.Printf("有子节点: %v\n", node.HasChild) fmt.Println("---") } // 获取子节点列表 if len(nodes) > 0 && nodes[0].HasChild { parentToken := nodes[0].NodeToken childNodes, _ := client.GetWikiNodeList(ctx, spaceID, &parentToken) for _, child := range childNodes { fmt.Printf(" 子节点: %s\n", child.Title) } } } ``` -------------------------------- ### CLI: Configuration Management Source: https://context7.com/wsine/feishu2md/llms.txt Manages feishu2md configuration, including setting Feishu App ID and App Secret, and output options. The configuration is stored in a file within the user's configuration directory. ```APIDOC ## feishu2md config ### Description Manages feishu2md configuration, including setting Feishu App ID and App Secret, and output options. The configuration is stored in a file within the user's configuration directory. ### Method CLI Command ### Endpoint N/A ### Parameters #### Command Options - **--appId** (string) - Optional - Sets the Feishu App ID. - **--appSecret** (string) - Optional - Sets the Feishu App Secret. ### Request Example ```bash # Initial configuration feishu2md config --appId cli_xxxxxxxxxxxx --appSecret xxxxxxxxxxxxxxxxxxxxxxxx # View current configuration feishu2md config # Update App ID only feishu2md config --appId cli_newappid # Update App Secret only feishu2md config --appSecret newsecretvalue ``` ### Response #### Success Response Configuration file path and content are displayed. #### Response Example ```json # Configuration file on: /Users/username/Library/Application Support/feishu2md/config.json { "feishu": { "app_id": "cli_xxxxxxxxxxxx", "app_secret": "xxxxxxxxxxxxxxxxxxxxxxxx" }, "output": { "image_dir": "static", "title_as_filename": false, "use_html_tags": false, "skip_img_download": false } } ``` ``` -------------------------------- ### DownloadImageRaw Source: https://context7.com/wsine/feishu2md/llms.txt Downloads an image and returns the raw byte data. ```APIDOC ## DownloadImageRaw ### Description Downloads an image and returns the raw binary data, suitable for programmatic processing. ### Method GET ### Parameters #### Query Parameters - **img_token** (string) - Required - The token of the image. - **img_dir** (string) - Required - The directory context for the image. ### Response #### Success Response (200) - **filename** (string) - The generated filename. - **rawData** (bytes) - The binary content of the image. ``` -------------------------------- ### Download Feishu Document to Markdown Source: https://github.com/wsine/feishu2md/blob/main/testdata/testdocx.1.md Use the Feishu2Md tool to download and convert a Feishu document to Markdown. Ensure you have configured the tool with your Feishu App ID and App Secret. ```bash feishu2md [一日一技:飞书文档转换为 Markdown](https://oaztcemx3k.feishu.cn/docs/doccnrOvzeQ8BSnfsXj8jwJHC3c#) ``` -------------------------------- ### GetWikiNodeInfo Source: https://context7.com/wsine/feishu2md/llms.txt Retrieves detailed information about a specific node in a Feishu Wiki. ```APIDOC ## GetWikiNodeInfo ### Description Retrieves detailed information about a specific node in a knowledge base, including node type and object token. ### Method GET ### Parameters #### Path Parameters - **node_token** (string) - Required - The unique token of the wiki node. ### Response #### Success Response (200) - **node** (object) - Node details including ObjType, ObjToken, and Title ``` -------------------------------- ### POST /open-apis/auth/v3/app_access_token/internal Source: https://github.com/wsine/feishu2md/wiki/如何手动验证工作流 Obtains an application access token for internal Feishu API calls. Requires `app_id` and `app_secret`. ```APIDOC ## POST /open-apis/auth/v3/app_access_token/internal ### Description Obtains an application access token for internal Feishu API calls. Requires `app_id` and `app_secret`. ### Method POST ### Endpoint https://open.feishu.cn/open-apis/auth/v3/app_access_token/internal ### Parameters #### Request Body - **app_id** (string) - Required - Your application's unique identifier. - **app_secret** (string) - Required - Your application's secret key. ### Request Example ```json { "app_id": "", "app_secret": "" } ``` ### Response #### Success Response (200) - **code** (integer) - Indicates the result of the operation. 0 for success. - **msg** (string) - The message returned by the server. - **app_access_token** (string) - The application access token. - **tenant_access_token** (string) - The tenant access token. - **expire** (integer) - The expiration time of the token in seconds. #### Response Example ```json { "code": 0, "msg": "success", "app_access_token": "t-abcdefghijkl0123456789", "tenant_access_token": "t-mnopqrstuvwxyz00000", "expire": 7200 } ``` ``` -------------------------------- ### CLI: Knowledge Base Export Source: https://context7.com/wsine/feishu2md/llms.txt Exports an entire Feishu knowledge base (wiki). Maintains the hierarchical structure of the knowledge base and downloads all docx-type document nodes concurrently. ```APIDOC ## feishu2md download --wiki ### Description Exports an entire Feishu knowledge base (wiki). Maintains the hierarchical structure of the knowledge base and downloads all docx-type document nodes concurrently. ### Method CLI Command ### Endpoint N/A ### Parameters #### Path Parameters - **URL** (string) - Required - The URL of the Feishu knowledge base (wiki settings page). #### Query Parameters - **--wiki** (boolean) - Required - Enables knowledge base export mode. - **-o, --output** (string) - Optional - Specifies the base output directory for the exported knowledge base. - **--dump** (boolean) - Optional - Exports the raw API response JSON data for each document. ### Request Example ```bash # Export entire knowledge base to current directory feishu2md dl --wiki "https://example.feishu.cn/wiki/settings/7123456789012345678" # Export to a specified output directory feishu2md dl --wiki -o ./wiki-backup "https://example.feishu.cn/wiki/settings/7123456789012345678" # Export and dump JSON data feishu2md dl --wiki --dump -o ./wiki-export "https://example.feishu.cn/wiki/settings/7123456789012345678" ``` ### Response #### Success Response Markdown files saved locally, preserving the knowledge base structure. Optionally, JSON responses are also saved. #### Response Example ``` Downloaded markdown file to ./知识库名称/章节1/文档1.md Downloaded markdown file to ./知识库名称/章节1/文档2.md Downloaded markdown file to ./知识库名称/章节2/子章节/文档3.md ``` ``` -------------------------------- ### GetWikiNodeList Source: https://context7.com/wsine/feishu2md/llms.txt Retrieves a list of nodes within a Feishu Wiki space. ```APIDOC ## GetWikiNodeList ### Description Retrieves a list of nodes under a specific wiki space, supporting root or parent-child hierarchy navigation. ### Method GET ### Parameters #### Query Parameters - **space_id** (string) - Required - The ID of the wiki space. - **parent_node_token** (string) - Optional - The token of the parent node to list children. ``` -------------------------------- ### GetDriveFolderFileList - List Drive Files Source: https://context7.com/wsine/feishu2md/llms.txt Retrieves a list of files and subfolders within a Feishu Drive folder, with automatic pagination support. ```go package main import ( "context" "fmt" "github.com/Wsine/feishu2md/core" ) func main() { client := core.NewClient("cli_xxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxx") ctx := context.Background() folderToken := "fldcnxxxxxxxxxx" files, err := client.GetDriveFolderFileList(ctx, nil, &folderToken) if err != nil { fmt.Printf("获取文件列表失败: %v\n", err) return } for _, file := range files { fmt.Printf("名称: %s\n", file.Name) fmt.Printf("类型: %s\n", file.Type) // folder, docx, doc 等 fmt.Printf("Token: %s\n", file.Token) fmt.Printf("URL: %s\n", file.URL) fmt.Println("---") } } ``` -------------------------------- ### Core API: NewClient Source: https://context7.com/wsine/feishu2md/llms.txt Creates a Feishu API client instance. The client includes built-in request timeout (60 seconds) and rate limiting (4 requests/second) for calling Feishu Open Platform APIs. ```APIDOC ## core.NewClient ### Description Creates a Feishu API client instance. The client includes built-in request timeout (60 seconds) and rate limiting (4 requests/second) for calling Feishu Open Platform APIs. ### Method Go Function ### Endpoint N/A ### Parameters #### Function Parameters - **appID** (string) - Required - Your Feishu application's App ID. - **appSecret** (string) - Required - Your Feishu application's App Secret. ### Request Example ```go package main import ( "context" "fmt" "github.com/Wsine/feishu2md/core" ) func main() { // Create client client := core.NewClient( "cli_xxxxxxxxxxxx", // App ID "xxxxxxxxxxxxxxxxxxxxxxxx", // App Secret ) ctx := context.Background() // Use client to get document content docx, blocks, err := client.GetDocxContent(ctx, "doxcnxxxxxxxxxx") if err != nil { panic(err) } fmt.Printf("Document Title: %s\n", docx.Title) fmt.Printf("Number of Blocks: %d\n", len(blocks)) } ``` ### Response #### Success Response A `core.Client` instance configured with the provided credentials and settings. #### Response Example (No direct output, but the `client` variable holds the initialized client object.) ``` -------------------------------- ### Validate Wiki URLs Source: https://context7.com/wsine/feishu2md/llms.txt Extracts the space ID and URL prefix from a Feishu wiki settings URL. ```go package main import ( "fmt" "github.com/Wsine/feishu2md/utils" ) func main() { prefixURL, spaceID, err := utils.ValidateWikiURL( "https://example.feishu.cn/wiki/settings/7123456789012345678") if err != nil { fmt.Printf("链接无效: %v\n", err) return } fmt.Printf("URL 前缀: %s\n", prefixURL) fmt.Printf("知识库 ID: %s\n", spaceID) // 输出: // URL 前缀: https://example.feishu.cn // 知识库 ID: 7123456789012345678 } ``` -------------------------------- ### DownloadImage Source: https://context7.com/wsine/feishu2md/llms.txt Downloads an image from a document to the local file system. ```APIDOC ## DownloadImage ### Description Downloads an image resource from a document to the local file system based on the image token. ### Method GET ### Parameters #### Query Parameters - **img_token** (string) - Required - The token of the image. - **out_dir** (string) - Required - The local directory path to save the image. ### Response #### Success Response (200) - **local_path** (string) - The path where the image was saved. ``` -------------------------------- ### GetDocxContent - Retrieve Document Content Source: https://context7.com/wsine/feishu2md/llms.txt Fetches the full content of a Feishu document, including metadata and block data. The method automatically handles pagination. ```go package main import ( "context" "fmt" "github.com/Wsine/feishu2md/core" ) func main() { client := core.NewClient("cli_xxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxx") ctx := context.Background() // 获取文档内容 docx, blocks, err := client.GetDocxContent(ctx, "doxcnxxxxxxxxxx") if err != nil { fmt.Printf("获取文档失败: %v\n", err) return } // 文档基本信息 fmt.Printf("文档 ID: %s\n", docx.DocumentID) fmt.Printf("文档标题: %s\n", docx.Title) fmt.Printf("修订版本: %d\n", docx.RevisionID) // 遍历文档块 for _, block := range blocks { fmt.Printf("块 ID: %s, 类型: %d\n", block.BlockID, block.BlockType) } } ``` -------------------------------- ### GetDriveFolderFileList Source: https://context7.com/wsine/feishu2md/llms.txt Retrieves a list of files and subfolders within a Feishu Drive folder. ```APIDOC ## GetDriveFolderFileList ### Description Retrieves all files and subfolders within a Feishu Drive folder, supporting automatic pagination. ### Method GET ### Parameters #### Query Parameters - **folder_token** (string) - Required - The token of the folder to list. ### Response #### Success Response (200) - **files** (array) - List of file objects containing Name, Type, Token, and URL ``` -------------------------------- ### Validate Folder URLs Source: https://context7.com/wsine/feishu2md/llms.txt Extracts the folder token from a Feishu drive folder URL for batch processing. ```go package main import ( "fmt" "github.com/Wsine/feishu2md/utils" ) func main() { folderToken, err := utils.ValidateFolderURL( "https://example.feishu.cn/drive/folder/fldcnxxxxxxxxxx") if err != nil { fmt.Printf("链接无效: %v\n", err) return } fmt.Printf("文件夹 Token: %s\n", folderToken) // 输出: 文件夹 Token: fldcnxxxxxxxxxx } ```