AI辅助4K视频制作全流程:从Higgsfield提示词到侏罗纪主题成品
2026/7/22 6:48:56
# 1. 导入依赖和路由fromfastapiimportFastAPIfromfastapi.middleware.corsimportCORSMiddlewarefromfastapi.staticfilesimportStaticFilesfromfastapi.responsesimportFileResponsefromapp.routers.file_routerimportrouterasfile_routerfromapp.routers.zxbj_routerimportrouteraszxbj_routerfromapp.routers.zxyl_routerimportrouteraszxyl_routerfromapp.routers.zshd_routerimportrouteraszshd_routerfromapp.configimportPORT,BASE_DIRimportos# 2. 创建 FastAPI 实例app=FastAPI(title="WDZT Document Management System",version="1.0.0")# 3. 配置 CORS(跨域资源共享)app.add_middleware(CORSMiddleware,allow_origins=["*"],allow_credentials=True,allow_methods=["*"],allow_headers=["*"],)# 4. 注册路由app.include_router(file_router,prefix="/api")app.include_router(zxbj_router,prefix="/api")app.include_router(zxyl_router,prefix="/api")app.include_router(zshd_router,prefix="/api")# 5. 挂载静态文件(前端页面)static_dir=os.path.join(BASE_DIR,"static")ifos.path.exists(static_dir):#FastAPI的挂载方法,将指定路径与静态文件目录关联;这段代码的核心目的是:让FastAPI能够提供静态文件服务,使得前端可以通过/static路径访问项目中的静态资源(如CSS、JS、图片等)。app.mount("/static",StaticFiles(directory=static_dir),name="static")@app.get("/")asyncdefroot():index_path=os.path.join(static_dir,"index.html")ifos.path.exists(index_path):returnFileResponse(index_path)return{"message":"WDZT Document Management System API"}#用户访问:/view/123 → 触发 FastAPI 路由。#后端响应:返回 static/index.html(静态入口文件)。#前端加载:浏览器加载 index.html,执行前端框架代码。#路由解析:前端从 URL 中提取 fileId=123,调用 API 获取对应文档数据。#动态渲染:前端根据数据渲染页面(如显示文档标题、内容等)。@app.get("/view/{fileId}")asyncdefview_page(fileId:str):index_path=os.path.join(static_dir,"index.html")ifos.path.exists(index_path):returnFileResponse(index_path)return{"message":"Page not found"}@app.get("/edit/{fileId}")asyncdefedit_page(fileId:str):index_path=os.path.join(static_dir,"index.html")ifos.path.exists(index_path):returnFileResponse(index_path)return{"message":"Page not found"}@app.get("/assets/{rest_of_path:path}")asyncdefassets(rest_of_path:str):asset_path=os.path.join(static_dir,"assets",rest_of_path)ifos.path.exists(asset_path):returnFileResponse(asset_path)returnFileResponse(os.path.join(static_dir,"index.html"))@app.get("/jssdk/{rest_of_path:path}")asyncdefjssdk(rest_of_path:str):jssdk_path=os.path.join(static_dir,"jssdk",rest_of_path)ifos.path.exists(jssdk_path):returnFileResponse(jssdk_path)returnFileResponse(os.path.join(static_dir,"index.html"))@app.get("/src/{rest_of_path:path}")asyncdefsrc_files(rest_of_path:str):src_path=os.path.join(static_dir,"src",rest_of_path)ifos.path.exists(src_path):returnFileResponse(src_path)returnFileResponse(os.path.join(static_dir,"index.html"))# 6. 启动服务if__name__=="__main__":importuvicornimportwebbrowserimportthreadingimporttimedefopen_browser():time.sleep(2)webbrowser.open(f"http://10.229.12.41:{PORT}")threading.Thread(target=open_browser,daemon=True).start()uvicorn.run(app,host="0.0.0.0",port=PORT)importos BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))FILE_STORE_PATH=os.path.join(os.path.dirname(os.path.dirname(BASE_DIR)),"wdzt_demo","filestore")WDZT_CONFIG={"ak":"AK20260630VIGWZM","sk":"SKphhpzupwammqjj","host":"http://10.217.19.253/open","server_api":"http://10.229.12.41:8000"}PORT=8000待完善。。。。。。