From 0c6057de2814e1386dce55f3a6146075c432d781 Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Fri, 17 Apr 2026 10:51:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=86=85=E5=AE=B9=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=98=BE=E7=A4=BA=EF=BC=88=E6=9C=89=E6=95=88?= =?UTF-8?q?=E8=A1=8C=E6=95=B0/=E6=80=BB=E5=AD=97=E6=95=B0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xian_favor/api.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/xian_favor/api.py b/xian_favor/api.py index 169b1cb..aaaf752 100644 --- a/xian_favor/api.py +++ b/xian_favor/api.py @@ -26,6 +26,10 @@ def list_items(): offset=int(request.args.get('offset', 0)) ) + # 为每个条目添加内容统计 + for item in items: + item['content_stats'] = calculate_content_stats(item) + # 获取符合条件的总数(用于分页) total = db.count_items( type=request.args.get('type'), @@ -77,9 +81,33 @@ def get_item(item_id): # 获取邮件发送历史 email_logs = db.get_email_logs(item_id) item['email_logs'] = email_logs + # 添加内容统计 + item['content_stats'] = calculate_content_stats(item) return jsonify({'success': True, 'data': item}) +def calculate_content_stats(item): + """计算内容统计:有效行数、总字数""" + # 合计所有文本内容 + all_text = '' + if item.get('content'): + all_text += item['content'] + '\n' + if item.get('note'): + all_text += item['note'] + '\n' + + if not all_text.strip(): + return {'lines': 0, 'chars': 0} + + # 有效行数(去除空行) + lines = [line for line in all_text.split('\n') if line.strip()] + line_count = len(lines) + + # 总字数(去除空格后的字符数) + char_count = len(all_text.replace(' ', '').replace('\n', '').replace('\t', '').strip()) + + return {'lines': line_count, 'chars': char_count} + + @app.route('/api/items/', methods=['PUT']) def update_item(item_id): """更新条目""" @@ -1280,6 +1308,8 @@ function renderItems(items) { ${formatShortDate(item.created_at)}${item.updated_at && item.updated_at !== item.created_at ? '→' + formatShortDate(item.updated_at) : ''} + ${item.content_stats && (item.content_stats.lines > 0 || item.content_stats.chars > 0) ? + `[${item.content_stats.lines}行/${item.content_stats.chars}字]` : ''}

${item.url ? truncate(item.url, 50) : item.content ? truncate(item.content, 50) : item.note ? truncate(item.note, 50) : ''} @@ -1547,6 +1577,11 @@ async function showDetail(id) { let html = `

类型: ${getTypeLabel(item.type)}
`; + // 显示内容统计 + if (item.content_stats && (item.content_stats.lines > 0 || item.content_stats.chars > 0)) { + html += `
统计: ${item.content_stats.lines} 有效行 / ${item.content_stats.chars} 字
`; + } + if (item.url) { html += `
URL: ${item.url}
`; }