move claude-marketplace to ai-proj-helper
This commit is contained in:
104
plugins/feishu-plugin/check_docx_image.py
Normal file
104
plugins/feishu-plugin/check_docx_image.py
Normal file
@@ -0,0 +1,104 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
检查飞书云文档中的图片块状态
|
||||
"""
|
||||
|
||||
import requests
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
ZHIYUN_APP_ID = "cli_a9f29dca82b9dbef"
|
||||
ZHIYUN_APP_SECRET = "sDfhjG7QT1S4gfHiMVYSygmPQPN1R2Ho"
|
||||
BASE_URL = "https://open.feishu.cn/open-apis"
|
||||
|
||||
# 最近创建的测试文档
|
||||
DOCUMENT_ID = "Z53YdDpezob1NPx63sQcsrt8nzd"
|
||||
|
||||
|
||||
def get_token():
|
||||
url = f"{BASE_URL}/auth/v3/tenant_access_token/internal"
|
||||
response = requests.post(url, json={
|
||||
"app_id": ZHIYUN_APP_ID,
|
||||
"app_secret": ZHIYUN_APP_SECRET
|
||||
})
|
||||
data = response.json()
|
||||
if data.get("code") != 0:
|
||||
raise Exception(f"获取 token 失败: {data}")
|
||||
return data["tenant_access_token"]
|
||||
|
||||
|
||||
def get_document_blocks(document_id: str):
|
||||
"""获取文档所有块"""
|
||||
token = get_token()
|
||||
url = f"{BASE_URL}/docx/v1/documents/{document_id}/blocks"
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
|
||||
response = requests.get(url, headers=headers)
|
||||
data = response.json()
|
||||
|
||||
if data.get("code") != 0:
|
||||
raise Exception(f"获取块失败: {data}")
|
||||
|
||||
return data["data"].get("items", [])
|
||||
|
||||
|
||||
def main():
|
||||
print(f"\n检查文档: {DOCUMENT_ID}")
|
||||
print("=" * 60)
|
||||
|
||||
blocks = get_document_blocks(DOCUMENT_ID)
|
||||
|
||||
print(f"\n文档共有 {len(blocks)} 个块:\n")
|
||||
|
||||
for i, block in enumerate(blocks):
|
||||
block_type = block.get("block_type")
|
||||
block_id = block.get("block_id")
|
||||
|
||||
# 块类型映射
|
||||
type_names = {
|
||||
1: "page",
|
||||
2: "text",
|
||||
3: "heading1",
|
||||
4: "heading2",
|
||||
5: "heading3",
|
||||
12: "bullet",
|
||||
13: "ordered",
|
||||
14: "code",
|
||||
17: "todo",
|
||||
22: "divider",
|
||||
27: "image",
|
||||
}
|
||||
type_name = type_names.get(block_type, f"type_{block_type}")
|
||||
|
||||
print(f" [{i}] block_type={block_type} ({type_name}), block_id={block_id[:20]}...")
|
||||
|
||||
# 如果是图片块,显示详细信息
|
||||
if block_type == 27:
|
||||
image_data = block.get("image", {})
|
||||
print(f" image data: {image_data}")
|
||||
|
||||
# 检查图片是否有效
|
||||
file_token = image_data.get("token") or image_data.get("file_token")
|
||||
if file_token:
|
||||
print(f" file_token: {file_token}")
|
||||
# 尝试获取图片信息
|
||||
check_image_status(file_token)
|
||||
else:
|
||||
print(f" [WARN] 图片块没有 token!")
|
||||
|
||||
|
||||
def check_image_status(file_token: str):
|
||||
"""检查图片状态"""
|
||||
token = get_token()
|
||||
|
||||
# 尝试获取文件元信息
|
||||
url = f"{BASE_URL}/drive/v1/medias/{file_token}"
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
|
||||
response = requests.get(url, headers=headers)
|
||||
data = response.json()
|
||||
|
||||
print(f" 图片状态: code={data.get('code')}, msg={data.get('msg')}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user