修复家长给设备留言问题

This commit is contained in:
HycJack
2026-05-10 20:45:11 +08:00
parent 8305bfcf2c
commit 847755c56a
3 changed files with 15 additions and 5 deletions

View File

@@ -4,11 +4,11 @@ import json
from collections.abc import Mapping
from pathlib import Path
from typing import Any
from services.offline_audio_cache import offline_audio_cache
from fastapi import HTTPException
from services.database_service_base import DatabaseServiceBase
from banban.service.message_audio_storage import MessageAudioStorageService, MessageAudioStorageError
from banban.service.binding import BindingService
try:
from banban.dao.im import ImDAO, DeviceIdentity, ConversationMessageCreateResult
from banban.schemas.im import (
@@ -19,6 +19,9 @@ try:
except ModuleNotFoundError:
from banban.dao.im import ImDAO, DeviceIdentity, ConversationMessageCreateResult
from banban.schemas.im import ChildConversationMessageItem, DeviceMessageCreateRequest, ParentChildMessageCreateRequest
from handlers.audio_file_handler import message_audio_storage_service
from utils.logger import session_logger
PARENT_PARTICIPANT_TYPE = 1
@@ -286,6 +289,14 @@ class ImService(DatabaseServiceBase):
child_id=child_id,
payload=payload,
)
binding_service = BindingService()
device = await binding_service.get_current_binding(parent_user_id)
try:
audio_url = await message_audio_storage_service.get_audio_url(stored_audio.file_key)
except Exception:
session_logger.error(device.device_id, "audio", f"failed to get audio url: {stored_audio.file_key}", exc_info=True)
audio_url = stored_audio.file_key
await offline_audio_cache.add_audio_url(device.device_id, f"{audio_url}")
except Exception:
try:
await self.audio_storage.delete_audio(stored_audio.file_key)