跳到主要内容

腾讯文档

收藏0

腾讯文档(docs.qq.com)在线云文档操作:创建与编辑文档/表格/幻灯片/思维导图/流程图/智能表格/收集表,管理知识库空间与文件夹,读取搜索内容,文件导入导出与网页剪藏。灵栈搬运自 SkillHub tencent-docs v1.0.42。

让 AI 安装

Minsaroun最新版本 0.1.0更新于 2026-11-14下载 0 次

sidebar-pptx-generator/scripts/get_slide_info.sh

4.2 KB
1#!/bin/bash
2#
3# Inspect a Tencent Docs PPT and return compact JSON for LLM routing.
4#
5# Usage:
6# bash scripts/get_slide_info.sh <file_url_or_id> [--file-id]
7#
8# Output:
9# {"action":"write_design_md"|"proceed_next","reason":"...",...}
10#
11
12set -euo pipefail
13
14if [[ $# -lt 1 ]]; then
15 echo "ERROR:missing_argument"
16 exit 1
17fi
18
19INPUT="$1"
20FILE_KEY="file_url"
21[[ "${2:-}" == "--file-id" ]] && FILE_KEY="file_id"
22
23BASE_ARGS=$(jq -n --arg key "$FILE_KEY" --arg val "$INPUT" '{($key): $val}')
24
25INFO_RESULT=$(mcporter call "slide-mcp" "slide_get_info" --args "$BASE_ARGS" 2>&1) || {
26 echo "ERROR:slide_get_info_failed"
27 exit 1
28}
29
30SLIDE_COUNT=$(echo "$INFO_RESULT" | jq -r '.slide_count // 0')
31W_PT=$(echo "$INFO_RESULT" | jq -r '.w_pt // 0')
32H_PT=$(echo "$INFO_RESULT" | jq -r '.h_pt // 0')
33
34# ── Permission check ──
35# When slide_count=0 but dimensions are valid, it likely means we lack
36# VIEW permission rather than the document being truly empty.
37# Attempt to verify via tencent-docs check_access.
38if [[ "$SLIDE_COUNT" -eq 0 ]] && [[ "$W_PT" -gt 0 ]] && [[ "$H_PT" -gt 0 ]]; then
39 # Try to extract file_id from URL (last path segment)
40 FILE_ID=""
41 if [[ "$FILE_KEY" == "file_url" ]]; then
42 FILE_ID=$(echo "$INPUT" | sed -E 's|.*/([^/?#]+).*|\1|')
43 else
44 FILE_ID="$INPUT"
45 fi
46
47 if [[ -n "$FILE_ID" ]]; then
48 ACCESS_RESULT=$(mcporter call "tencent-docs" "check_access" --args "{\"file_id\":\"$FILE_ID\",\"actions\":[\"VIEW\"]}" 2>&1 || echo '{"granted_actions":[]}')
49 HAS_VIEW=$(echo "$ACCESS_RESULT" | jq -r '(.granted_actions // []) | map(select(. == "VIEW")) | length > 0' 2>/dev/null || echo "false")
50
51 if [[ "$HAS_VIEW" != "true" ]]; then
52 jq -n --arg reason "permission_denied" --argjson sc "$SLIDE_COUNT" --argjson w "$W_PT" --argjson h "$H_PT" --arg fid "$FILE_ID" \
53 '{action:"ask_user",reason:$reason,slide_count:$sc,w_pt:$w,h_pt:$h,file_id:$fid,hint:"当前账号无 VIEW 权限,请分享文档或下载到本地后重试"}'
54 exit 0
55 fi
56 fi
57fi
58
59if [[ "$SLIDE_COUNT" -eq 0 ]] || [[ "$W_PT" -eq 0 ]] || [[ "$H_PT" -eq 0 ]]; then
60 jq -n --arg reason "ppt_is_empty" --argjson sc "$SLIDE_COUNT" --argjson w "$W_PT" --argjson h "$H_PT" \
61 '{action:"write_design_md",reason:$reason,slide_count:$sc,w_pt:$w,h_pt:$h}'
62 exit 0
63fi
64
65CONTENT_PAGE_COUNT=0
66
67for i in $(seq 0 $((SLIDE_COUNT - 1))); do
68 PAGE_ARGS=$(echo "$BASE_ARGS" | jq --argjson idx "$i" '. + {page_index: $idx}')
69 PAGE_RESULT=$(mcporter call "slide-mcp" "slide_get_page_info" --args "$PAGE_ARGS" 2>&1) || continue
70
71 HAS_CONTENT=$(echo "$PAGE_RESULT" | jq '
72 [.shapes // [] | .[] | select((.text // "") | gsub("[\\s\\r\\n]"; "") != "")] | length > 0
73 ' 2>/dev/null || echo "false")
74
75 [[ "$HAS_CONTENT" == "true" ]] && CONTENT_PAGE_COUNT=$((CONTENT_PAGE_COUNT + 1))
76done
77
78if [[ "$CONTENT_PAGE_COUNT" -eq 0 ]]; then
79 jq -n --arg reason "ppt_content_is_empty" --argjson sc "$SLIDE_COUNT" --argjson w "$W_PT" --argjson h "$H_PT" --argjson cpc "$CONTENT_PAGE_COUNT" \
80 '{action:"write_design_md",reason:$reason,slide_count:$sc,w_pt:$w,h_pt:$h,content_page_count:$cpc}'
81 exit 0
82fi
83
84DESIGN_RESULT=$(mcporter call "slide-mcp" "slide_get_design" --args "$BASE_ARGS" 2>&1) || {
85 echo "ERROR:slide_get_design_failed"
86 exit 1
87}
88
89DESIGN_EXISTS=$(echo "$DESIGN_RESULT" | jq -r '.exists // false')
90DESIGN_MD=$(echo "$DESIGN_RESULT" | jq -r '.design_md // ""')
91
92if [[ "$DESIGN_EXISTS" == "false" ]] || [[ -z "$DESIGN_MD" ]] || [[ "$DESIGN_MD" == '""' ]]; then
93 jq -n --arg reason "design_is_empty" --argjson sc "$SLIDE_COUNT" --argjson w "$W_PT" --argjson h "$H_PT" --argjson cpc "$CONTENT_PAGE_COUNT" --argjson de "$DESIGN_EXISTS" \
94 '{action:"write_design_md",reason:$reason,slide_count:$sc,w_pt:$w,h_pt:$h,content_page_count:$cpc,design_exists:$de}'
95 exit 0
96fi
97
98DESIGN_MD_LEN=${#DESIGN_MD}
99UPDATED_AT=$(echo "$DESIGN_RESULT" | jq -r '.updated_at // "0"')
100
101jq -n --argjson sc "$SLIDE_COUNT" --argjson w "$W_PT" --argjson h "$H_PT" --argjson cpc "$CONTENT_PAGE_COUNT" --argjson de "$DESIGN_EXISTS" --argjson dml "$DESIGN_MD_LEN" --arg ua "$UPDATED_AT" \
102 '{action:"proceed_next",reason:"design_exists",slide_count:$sc,w_pt:$w,h_pt:$h,content_page_count:$cpc,design_exists:$de,design_md_length:$dml,updated_at:$ua}'

文件内容是平台检查时读出的文本,只供查看。平台不会运行包里的任何脚本或程序。