From 1578db3467a98ad138a45602afa3ed16d1a67aec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E5=BF=B5?= Date: Fri, 7 Aug 2026 16:52:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(api):=20PhoneCallOut=20=E6=9A=B4=E9=9C=B2?= =?UTF-8?q?=20record=5Fmedia=5Fhash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude --- yunke-server/app/api/schemas.py | 2 ++ yunke-server/tests/test_api_calls.py | 39 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/yunke-server/app/api/schemas.py b/yunke-server/app/api/schemas.py index 0c1bd30..9942d5a 100644 --- a/yunke-server/app/api/schemas.py +++ b/yunke-server/app/api/schemas.py @@ -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 diff --git a/yunke-server/tests/test_api_calls.py b/yunke-server/tests/test_api_calls.py index eaf93e2..cdae684 100644 --- a/yunke-server/tests/test_api_calls.py +++ b/yunke-server/tests/test_api_calls.py @@ -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