feat(api): PhoneCallOut 暴露 record_media_hash

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
浅念
2026-08-07 16:52:41 +08:00
parent b59e3cd9fe
commit 1578db3467
2 changed files with 41 additions and 0 deletions
+2
View File
@@ -217,6 +217,8 @@ class PhoneCallOut(BaseModel):
# OSS URL of the call recording — surfaced so the Calls view can offer a
# "播放录音" action when present.
record_file: str | None = None
# sha256 media_hash of the localized recording (NULL until downloaded).
record_media_hash: str | None = None
raw_json: dict[str, Any] | None = None
+39
View File
@@ -252,3 +252,42 @@ async def test_record_file_serializes(make_client):
# c1/c2 have no record_file set -> None.
assert by_id["c1"]["record_file"] is None
assert by_id["c2"]["record_file"] is None
async def test_record_media_hash_serializes(make_client):
"""``record_media_hash`` (sha256 of the localized recording) round-trips so
the frontend can detect already-downloaded files — present when set, None
until the sync pass localizes the recording.
"""
async def seed(session: AsyncSession) -> None:
await _seed(session)
session.add(
PhoneCall(
call_id="c_hash",
channel="phone_call",
user_id="u1",
user_id_name="Alice",
start_call_time=8000,
call_duration=10,
call_status=1,
incoming_call=0,
record_media_hash="abc123",
)
)
await session.commit()
client = await make_client(seed)
r = await client.get("/api/calls", params={"user_id": "u1", "start": 8000})
assert r.status_code == 200
body = r.json()
assert body["total"] == 1
assert body["items"][0]["call_id"] == "c_hash"
assert body["items"][0]["record_media_hash"] == "abc123"
# Rows without an explicit hash serialize as JSON null.
r_all = await client.get("/api/calls")
by_id = {it["call_id"]: it for it in r_all.json()["items"]}
assert by_id["c1"]["record_media_hash"] is None
assert by_id["c2"]["record_media_hash"] is None
assert by_id["c3"]["record_media_hash"] is None