2026-03-17 13:17:02 +08:00

114 lines
5.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django.urls import path, include
from rest_framework.routers import DefaultRouter
from . import views
from drf_yasg import openapi
websocket_schema = openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
'websocket_url': openapi.Schema(
type=openapi.TYPE_STRING,
description='WebSocket连接地址',
example='ws://your-domain/ws/device/{user_id}/'
),
'message_format': openapi.Schema(
type=openapi.TYPE_OBJECT,
description='消息格式',
properties={
'type': openapi.Schema(
type=openapi.TYPE_STRING,
description='消息类型',
enum=['chat_message', 'weather', 'sing', 'dance', 'touch', 'flow_light', 'conversation_status', 'factory_reset']
),
'message': openapi.Schema(
type=openapi.TYPE_OBJECT,
description='消息内容根据type不同有不同的格式',
oneOf=[
openapi.Schema(
type=openapi.TYPE_STRING,
description='文本消息内容'
),
openapi.Schema(
type=openapi.TYPE_OBJECT,
description='天气消息',
properties={
'city': openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
'name': openapi.Schema(type=openapi.TYPE_STRING),
'id': openapi.Schema(type=openapi.TYPE_STRING),
'adm1': openapi.Schema(type=openapi.TYPE_STRING),
'adm2': openapi.Schema(type=openapi.TYPE_STRING)
}
),
'weather': openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
'code': openapi.Schema(type=openapi.TYPE_STRING),
'updateTime': openapi.Schema(type=openapi.TYPE_STRING),
'fxLink': openapi.Schema(type=openapi.TYPE_STRING),
'now': openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
'temp': openapi.Schema(type=openapi.TYPE_STRING),
'text': openapi.Schema(type=openapi.TYPE_STRING),
'icon': openapi.Schema(type=openapi.TYPE_STRING)
}
)
}
)
}
),
openapi.Schema(
type=openapi.TYPE_OBJECT,
description='唱歌消息',
properties={
'song': openapi.Schema(type=openapi.TYPE_STRING),
'artist': openapi.Schema(type=openapi.TYPE_STRING),
'duration': openapi.Schema(type=openapi.TYPE_STRING)
}
),
openapi.Schema(
type=openapi.TYPE_OBJECT,
description='跳舞消息',
properties={
'dance': openapi.Schema(type=openapi.TYPE_STRING),
'style': openapi.Schema(type=openapi.TYPE_STRING),
'duration': openapi.Schema(type=openapi.TYPE_STRING)
}
),
openapi.Schema(
type=openapi.TYPE_OBJECT,
description='恢复出厂设置消息',
properties={
'confirm': openapi.Schema(type=openapi.TYPE_BOOLEAN, description='确认恢复出厂设置'),
'backup': openapi.Schema(type=openapi.TYPE_BOOLEAN, description='是否备份用户数据'),
'reset_type': openapi.Schema(type=openapi.TYPE_STRING, description='重置类型full(完全重置)/partial(部分重置)', enum=['full', 'partial'])
}
)
]
),
'user_id': openapi.Schema(
type=openapi.TYPE_STRING,
description='用户ID'
)
},
required=['type', 'message', 'user_id']
)
}
)
router = DefaultRouter()
# 设备相关路由
router.register(r'device-types', views.DeviceTypeViewSet, basename='device-type')
router.register(r'device-batches', views.DeviceBatchViewSet, basename='device-batch')
router.register(r'devices', views.DeviceViewSet, basename='device')
router.register(r'user-devices', views.UserDeviceViewSet, basename='user-device')
# 原有路由
router.register(r'messages', views.MessageViewSet, basename='message')
router.register(r'rtc-token', views.VolcEngineTokenViewSet, basename='volcengine-token')
urlpatterns = [
path('send_message_to_user/<str:user_id>/', views.send_message_to_user, name='send_message_to_user'),
path('', include(router.urls)),
]