api-server / make /_clean_final2.py
XWX-AI's picture
fix(widget): DOCX图表fallback成数据表格根因修复 — widget渲染浏览器池+CDP有限超时+渲染硬超时+队列超时取消+BrowserPool补位bug+body-parser JSON兜底, bump v2.1.11
24a2ddf
Raw
History Blame Contribute Delete
2.9 kB
import re
with open('D:/workAI/OpenCode/WorkSpace/backend-service/server.js', 'r', encoding='utf-8') as f:
content = f.read()
# Remove all AXIS-DEBUG console.log lines (these are in generated HTML, run in browser)
# Match pattern: console.log('[AXIS-DEBUG]...');
# Handle both leading spaces and inline cases
content = re.sub(r" console\.log\('\[AXIS-DEBUG\].*?\);\n", "", content)
content = re.sub(r" console\.log\('\[AXIS-DEBUG\].*?\);\n", "", content)
content = re.sub(r" console\.log\('\[AXIS-DEBUG\].*?\);\n", "", content)
# Handle inline AXIS-DEBUG (e.g., if (x) { y; console.log('[AXIS-DEBUG]...'); })
content = re.sub(r"; console\.log\('\[AXIS-DEBUG\].*?'\);", "", content)
# Handle if with only AXIS-DEBUG: if (cond) console.log('[AXIS-DEBUG]...');
content = re.sub(r" if \(.*?\) console\.log\('\[AXIS-DEBUG\].*?\);\n", "", content)
# Remove _rawToFormatted dead code block
# Find the block from comment to the end of forEach
pattern = r" // .*?Build format map from chartData.*?\n var _rawToFormatted = \{\};.*?}\n\}\);\n\n // Build series elements"
content = re.sub(pattern, " // Build series elements", content, flags=re.DOTALL)
# Remove verbose PIE DATA logging
content = content.replace(
" if (chartType === 'pie' || chartType === 'donut') {\n console.log(`[WIDGET] renderChatGPTChart PIE DATA: data=${JSON.stringify(data)}, formattedData=${JSON.stringify(formattedData)}`);\n }",
""
)
# Remove verbose nameKey/valueKey logging
content = content.replace(
" if (nameKey) console.log(`[WIDGET] renderChatGPTChart: nameKey=${nameKey}, valueKey=${valueKey}`);",
""
)
# Remove duplicate COLORS
old_colors = """ const COLORS = [
'#339CFF', '#40C977', '#FF8549', '#FFD240',
'#339CFF', '#40C977', '#FF8549', '#FFD240',
'#339CFF', '#40C977', '#FF8549', '#FFD240',
];"""
new_colors = """ const COLORS = ['#339CFF', '#40C977', '#FF8549', '#FFD240'];"""
if old_colors in content:
content = content.replace(old_colors, new_colors)
# Remove dead baseWaitTime/sizeWaitTime/totalWaitTime
content = re.sub(r"\n const baseWaitTime = imgCount > 0.*?\n const sizeWaitTime = imgSizeMB.*?\n const totalWaitTime = Math\.min.*?\n", "\n", content)
# Remove redundant %%INJECTED_SCRIPTS%% placeholder
content = content.replace(".replace('%%INJECTED_SCRIPTS%%', '');", ";")
# Remove dead pieActualDataKey
content = content.replace("var pieActualDataKey = valueKey || chartSeries[0]?.dataKey || 'value';\n", "")
# Verify critical functions still present
if 'buildChatGPTChartHtml' in content and 'render_charts' in content and 'isAnimationActive: false' in content:
with open('D:/workAI/OpenCode/WorkSpace/backend-service/server.js', 'w', encoding='utf-8') as f:
f.write(content)
print("SUCCESS: All cleanup applied")
else:
print("ERROR: Critical content missing! NOT saving.")