|
|
@@ -1,4 +1,5 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
+# pip install fastapi uvicorn
|
|
|
|
|
|
from fastapi import FastAPI, HTTPException
|
|
|
from fastapi.responses import FileResponse
|
|
|
@@ -7,23 +8,18 @@ import os
|
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
-# 假设你的XML文件文件夹路径是 "xml_file"
|
|
|
-xml_folder_path = Path("/Users/jack/source/mySpace/mycode/my_project/spider_rss/xml_file")
|
|
|
+xml_folder_path = Path("/mnt/xml_file")
|
|
|
|
|
|
|
|
|
@app.get("/{filename}")
|
|
|
async def read_xml(filename: str):
|
|
|
- # 构建完整的文件路径
|
|
|
file_path = xml_folder_path / f"{filename}.xml"
|
|
|
|
|
|
- # 检查文件是否存在
|
|
|
if not file_path.is_file():
|
|
|
raise HTTPException(status_code=404, detail="File not found")
|
|
|
|
|
|
- # 返回文件响应
|
|
|
return FileResponse(file_path, media_type="application/xml")
|
|
|
|
|
|
-
|
|
|
if __name__ == "__main__":
|
|
|
import uvicorn
|
|
|
|