feat: /api/history 支持按群过滤和增量拉取,更新 README API 文档

- /api/history 新增 chat、since、limit 参数
- README 新增 HTTP API 端点说明和联系人标签工具文档

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
ylytdeng
2026-04-09 11:43:41 +08:00
parent 7eb29b03e8
commit 69a2f44240
2 changed files with 39 additions and 1 deletions

View File

@@ -1905,9 +1905,31 @@ class Handler(BaseHTTPRequestHandler):
self.end_headers()
self.wfile.write(HTML_PAGE.encode('utf-8'))
elif self.path == '/api/history':
elif self.path.startswith('/api/history'):
parsed = urllib.parse.urlparse(self.path)
params = urllib.parse.parse_qs(parsed.query)
filter_chat = params.get('chat', [''])[0].strip().lower()
since_ts = 0
try:
since_ts = int(params.get('since', ['0'])[0])
except (ValueError, TypeError):
pass
limit_val = 500
try:
limit_val = min(int(params.get('limit', ['500'])[0]), 2000)
except (ValueError, TypeError):
pass
with messages_lock:
data = sorted(messages_log, key=lambda m: m.get('timestamp', 0))
if since_ts:
data = [m for m in data if m.get('timestamp', 0) > since_ts]
if filter_chat:
data = [m for m in data if filter_chat in m.get('chat', '').lower()
or filter_chat in m.get('username', '').lower()]
data = data[-limit_val:]
self.send_response(200)
self.send_header('Content-Type', 'application/json; charset=utf-8')
self.end_headers()