(*parts: str)
| 816 | |
| 817 | |
| 818 | def resolve_theme_file(*parts: str): |
| 819 | theme_root = resolve_theme_root() |
| 820 | file_path = theme_root.joinpath(*parts).resolve() |
| 821 | # 防止通过 /assets/../ 读取主题目录外的文件。 |
| 822 | try: |
| 823 | file_path.relative_to(theme_root) |
| 824 | except ValueError: |
| 825 | raise HTTPException(status_code=404, detail="资源不存在") |
| 826 | if not file_path.is_file(): |
| 827 | raise HTTPException(status_code=404, detail="资源不存在") |
| 828 | return file_path |
| 829 | |
| 830 | |
| 831 | @app.get("/assets/{asset_path:path}", include_in_schema=False) |