Add memory feature: diary viewer with calendar

- Backend API for memory dates and detail
- Frontend memory modal with calendar component
- Click date to view diary
- Highlight dates with diary entries
This commit is contained in:
2026-04-01 21:49:47 +08:00
parent 0c0466e378
commit 357b82ede6
4 changed files with 673 additions and 8 deletions

View File

@@ -8,5 +8,7 @@ urlpatterns = [
path('lobsters/', views.lobster_list, name='lobster-list'),
path('lobsters/<int:lobster_id>/', views.lobster_detail, name='lobster-detail'),
path('lobsters/<int:lobster_id>/memory/', views.lobster_memory, name='lobster-memory'),
path('lobsters/<int:lobster_id>/memory/dates/', views.lobster_memory_dates, name='lobster-memory-dates'),
path('lobsters/<int:lobster_id>/memory/<str:date>/', views.lobster_memory_detail, name='lobster-memory-detail'),
path('tools/', views.tools_list, name='tools-list'),
]

View File

@@ -5,6 +5,8 @@ from rest_framework.decorators import api_view
from rest_framework.response import Response
from datetime import datetime
import os
from pathlib import Path
import re
# 龙虾配置
LOBSTERS = [
@@ -65,3 +67,49 @@ def tools_list(request):
}
]
return Response(tools)
@api_view(['GET'])
def lobster_memory_dates(request, lobster_id):
"""获取龙虾有日记的日期列表"""
# 获取龙虾工作区
lobster_map = {
1: 'flying-hero',
2: 'daotong',
3: 'coder',
4: 'web',
5: 'physics',
6: 'watcher',
}
lobster_name = lobster_map.get(lobster_id)
if not lobster_name:
return Response({'error': '龙虾不存在'}, status=404)
# 记忆文件目录
memory_dir = Path(f'/home/node/.openclaw/workspace/flying-hero/memory')
# 获取所有日记文件
dates = []
if memory_dir.exists():
for file in memory_dir.glob('*.md'):
# 提取日期 (YYYY-MM-DD.md)
match = re.match(r'(\d{4}-\d{2}-\d{2})\.md', file.name)
if match:
dates.append(match.group(1))
dates.sort(reverse=True)
return Response({'dates': dates})
@api_view(['GET'])
def lobster_memory_detail(request, lobster_id, date):
"""获取指定日期的日记内容"""
memory_file = Path(f'/home/node/.openclaw/workspace/flying-hero/memory/{date}.md')
if not memory_file.exists():
return Response({'error': '该日期没有日记'}, status=404)
content = memory_file.read_text(encoding='utf-8')
return Response({
'date': date,
'content': content
})