fix: 图片可直接通过url访问
This commit is contained in:
@@ -186,21 +186,6 @@ async def get_web_config() -> InfoOut:
|
||||
return InfoOut(data={"WebConfig": data})
|
||||
|
||||
|
||||
@router.post(
|
||||
"/get/materials", summary="获取材料URL", response_model=InfoOut, status_code=200
|
||||
)
|
||||
async def get_materials(
|
||||
materials: GetMaterialsIn = Body(..., description="材料ID")
|
||||
) -> InfoOut:
|
||||
try:
|
||||
data = await Config.get_materials(materials.dropId)
|
||||
except Exception as e:
|
||||
return InfoOut(
|
||||
code=500, status="error", message=f"{type(e).__name__}: {str(e)}", data={}
|
||||
)
|
||||
return InfoOut(data={"FileUrl": data})
|
||||
|
||||
|
||||
@router.post(
|
||||
"/get/overview", summary="信息总览", response_model=InfoOut, status_code=200
|
||||
)
|
||||
|
||||
@@ -1742,12 +1742,6 @@ class AppConfig(GlobalConfig):
|
||||
|
||||
return stage_data
|
||||
|
||||
async def get_materials(self, dropId):
|
||||
"""获取材料URL"""
|
||||
if dropId not in MATERIALS_MAP:
|
||||
raise ValueError(f"未知的材料ID: {dropId}")
|
||||
return f"file:///{quote((Path.cwd() / f"res/images/materials/{dropId}.png").as_posix())}"
|
||||
|
||||
async def get_script_combox(self):
|
||||
"""获取脚本下拉框信息"""
|
||||
|
||||
|
||||
@@ -67,10 +67,6 @@ class GetStageIn(BaseModel):
|
||||
)
|
||||
|
||||
|
||||
class GetMaterialsIn(BaseModel):
|
||||
dropId: str = Field(..., description="材料ID")
|
||||
|
||||
|
||||
class GlobalConfig_Function(BaseModel):
|
||||
HistoryRetentionTime: Optional[Literal[7, 15, 30, 60, 90, 180, 365, 0]] = Field(
|
||||
None, description="历史记录保留时间, 0表示永久保存"
|
||||
|
||||
7
main.py
7
main.py
@@ -69,6 +69,7 @@ def main():
|
||||
import asyncio
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
@asynccontextmanager
|
||||
@@ -131,6 +132,12 @@ def main():
|
||||
app.include_router(history_router)
|
||||
app.include_router(setting_router)
|
||||
|
||||
app.mount(
|
||||
"/api/res/materials",
|
||||
StaticFiles(directory=str(Path.cwd() / "res/images/materials")),
|
||||
name="materials",
|
||||
)
|
||||
|
||||
async def run_server():
|
||||
|
||||
config = uvicorn.Config(
|
||||
|
||||
Reference in New Issue
Block a user