zeisel commited on
Commit
c459b63
·
verified ·
1 Parent(s): 86fb5e0

Delete controller.py

Browse files
Files changed (1) hide show
  1. controller.py +0 -63
controller.py DELETED
@@ -1,63 +0,0 @@
1
- import os
2
- import uvicorn
3
- import aiofiles
4
- from fastapi import FastAPI, HTTPException, File, UploadFile
5
- from fastapi.middleware.cors import CORSMiddleware
6
- from fastapi.responses import JSONResponse
7
-
8
- from typing import List
9
-
10
- import service
11
-
12
- uploadPath = "./data/latents/"
13
-
14
-
15
- app = FastAPI()
16
- # 配置 CORS 中间件
17
- app.add_middleware(
18
- CORSMiddleware,
19
- allow_origins=["http://localhost:5173"], # 允许的前端地址
20
- allow_credentials=True, # 是否允许发送 Cookie
21
- allow_methods=["*"], # 允许的 HTTP 方法(GET、POST、PUT 等)
22
- allow_headers=["*"], # 允许的请求头
23
- )
24
-
25
- # 定义根路径的 GET 请求处理函数
26
- @app.get("/")
27
- async def read_root():
28
- return {"message": "Hello, World!"}
29
-
30
- @app.get("/dataList/{datatype}")
31
- async def read_data(datatype):
32
- return service.getALlData()
33
-
34
-
35
-
36
-
37
-
38
- # 定义带路径参数的 GET 请求处理函数
39
- @app.get("/details/{name}")
40
- async def read_item(name: str = None):
41
- data = service.getListByName("integration_accuracy.csv", name)
42
- return data
43
-
44
- # 定义 POST 请求处理函数
45
- @app.post("/upload")
46
- async def upload_files(files:List[UploadFile] = File(...)):
47
- for file in files:
48
- save_path = os.path.join(uploadPath, file.filename)
49
- try:
50
- async with aiofiles.open(save_path, 'wb') as out_file:
51
- content = await file.read()
52
- await out_file.write(content)
53
- except Exception as e:
54
- return {"message": f"出现错误: {e}"}
55
- finally:
56
- # 关闭文件
57
- await file.close()
58
- return {"success":True, "message": f"文件 {file.filename} 已成功保存"}
59
-
60
- if __name__ == "__main__":
61
- # 从环境变量中读取端口,默认为 8000
62
- port = int(os.getenv("APP_PORT", 8000))
63
- uvicorn.run(app, host="127.0.0.1", port=port)