feat(chat): support public channel chat

This commit is contained in:
MingxuanGame
2025-08-16 05:29:16 +00:00
parent 9a5c2fde08
commit f992e4cc71
13 changed files with 925 additions and 3 deletions

39
app/dependencies/param.py Normal file
View File

@@ -0,0 +1,39 @@
from __future__ import annotations
from typing import Any
from fastapi import Request
from fastapi.exceptions import RequestValidationError
from pydantic import BaseModel, ValidationError
def BodyOrForm[T: BaseModel](model: type[T]):
async def dependency(
request: Request,
) -> T:
content_type = request.headers.get("content-type", "")
data: dict[str, Any] = {}
if "application/json" in content_type:
try:
data = await request.json()
except Exception:
raise RequestValidationError(
[
{
"loc": ("body",),
"msg": "Invalid JSON body",
"type": "value_error",
}
]
)
else:
form = await request.form()
data = dict(form)
try:
return model(**data)
except ValidationError as e:
raise RequestValidationError(e.errors())
return dependency