Skip to content

Commit

Permalink
📃 docs: 新增描述
Browse files Browse the repository at this point in the history
  • Loading branch information
kalicyh committed Aug 11, 2024
1 parent 37362d1 commit 967bed2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 32 deletions.
51 changes: 31 additions & 20 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@
from .crud import update_version_info, update_version_filename, get_info
from .database import SessionLocal

app = FastAPI()
description = """
github地址:[kalicyh/knowledge_server](https://github.com/kalicyh/knowledge_server)
"""

app = FastAPI(
title="智库管理系统",
description=description,
version="1.7.9",
license_info={
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html",
},
)

app.add_middleware(
CORSMiddleware,
Expand All @@ -19,16 +31,19 @@
allow_headers=["*"], # 允许所有头部
)

app.mount("/dist", StaticFiles(directory="dist"), name="dist")
UPLOAD_DIR = Path("./file")
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)

app.include_router(talking_points_router, prefix="/talking_points")
app.include_router(numbers_router, prefix="/numbers")
class TagModel(BaseModel):
tag: str

@app.get("/")
app.mount("/dist", StaticFiles(directory="dist"), name="dist")

@app.get("/", tags=["前端页面"], description="UI界面")
def root():
return FileResponse('dist/index.html')

@app.get("/info")
@app.get("/info", tags=["信息"], description="返回前端版本,后端版本,前端软件名")
async def get_infos():
db = SessionLocal()
info = get_info(db)
Expand All @@ -40,35 +55,31 @@ async def get_infos():
"client_filename": info.client_filename
})

# 文件存储路径
UPLOAD_DIR = Path("./file")
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)

class TagModel(BaseModel):
tag: str

@app.post("/store-tag/")
async def store_tag(tag: TagModel):
@app.post("/backend-tag/", tags=["信息"], description="更新后端版本接口")
async def backend_tag(tag: TagModel):
tag = tag.tag
db = SessionLocal()
update_version_info(db, tag, "client")
update_version_info(db, tag, "backend")
db.close()
return {"message": "Tag stored successfully"}

@app.post("/upload-file/")
async def upload_file(tag: str, file: UploadFile = File(...)):
@app.post("/client-file-tag/", tags=["信息"], description="更新前端版本及上传软件接口")
async def client_file_tag(tag: str, file: UploadFile = File(...)):
db = SessionLocal()
update_version_info(db, tag, "backend")
update_version_info(db, tag, "client")
update_version_filename(db, file.filename+"_"+tag)
db.close()
file_path = UPLOAD_DIR / f"{file.filename}_{tag}"
with file_path.open("wb") as buffer:
buffer.write(await file.read())
return {"message": "File uploaded successfully"}

@app.get("/download-file/{filename}")
@app.get("/client-file/{filename}", tags=["信息"], description="前端软件下载接口")
async def download_file(filename: str):
file_path = UPLOAD_DIR / filename
if file_path.exists():
return FileResponse(path=file_path, media_type='application/octet-stream', filename=filename)
return {"error": "File not found"}

app.include_router(talking_points_router, prefix="/talking_points")
app.include_router(numbers_router, prefix="/numbers")
10 changes: 5 additions & 5 deletions api/routes/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

upload_progress = {}

@router.post("/upload")
@router.post("/upload", tags=["号码接口"], description="号码新增接口")
async def upload_file(file: UploadFile = File(...), background_tasks: BackgroundTasks = BackgroundTasks()):
upload_id = str(uuid.uuid4())
upload_progress[upload_id] = {'progress': 0}
Expand All @@ -23,7 +23,7 @@ async def upload_file(file: UploadFile = File(...), background_tasks: Background

return {"upload_id": upload_id, "message": "Upload started"}

@router.post("/overwrite_upload")
@router.post("/overwrite_upload", tags=["号码接口"], description="号码覆盖接口")
async def overwrite_upload_file(file: UploadFile = File(...), background_tasks: BackgroundTasks = BackgroundTasks()):
upload_id = str(uuid.uuid4())
upload_progress[upload_id] = {'progress': 0}
Expand All @@ -46,7 +46,7 @@ async def overwrite_upload_file(file: UploadFile = File(...), background_tasks:

return {"upload_id": upload_id, "message": "Overwrite upload started"}

@router.get("/progress/{upload_id}")
@router.get("/progress/{upload_id}", tags=["号码接口"], description="号码上传进度接口")
async def get_progress(upload_id: str):
progress = upload_progress.get(upload_id)
if not progress:
Expand Down Expand Up @@ -109,7 +109,7 @@ def process_file(file_buffer: BytesIO, upload_id: str):
finally:
db.close()

@router.get("/data")
@router.get("/data", tags=["号码接口"], description="获取号码接口")
async def get_data():
db = SessionLocal()
numbers = get_numbers(db)
Expand All @@ -127,7 +127,7 @@ async def get_data():
]
})

@router.get("/info")
@router.get("/info", tags=["号码接口"], description="获取号码信息接口")
async def get_numbers_infos():
db = SessionLocal()
info_number = get_numbers_info(db)
Expand Down
14 changes: 7 additions & 7 deletions api/routes/talking_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

upload_progress = {}

@router.post("/upload")
@router.post("/upload", tags=["语料接口"], description="语料新增接口")
async def upload_file(file: UploadFile = File(...), background_tasks: BackgroundTasks = BackgroundTasks()):
upload_id = str(uuid.uuid4())
upload_progress[upload_id] = {'progress': 0} # Initialize progress
Expand All @@ -25,7 +25,7 @@ async def upload_file(file: UploadFile = File(...), background_tasks: Background

return {"upload_id": upload_id, "message": "Upload started"}

@router.post("/overwrite_upload")
@router.post("/overwrite_upload", tags=["语料接口"], description="语料覆盖接口")
async def overwrite_upload_file(file: UploadFile = File(...), background_tasks: BackgroundTasks = BackgroundTasks()):
upload_id = str(uuid.uuid4())
upload_progress[upload_id] = {'progress': 0} # Initialize progress
Expand All @@ -48,7 +48,7 @@ async def overwrite_upload_file(file: UploadFile = File(...), background_tasks:

return {"upload_id": upload_id, "message": "Overwrite upload started"}

@router.get("/progress/{upload_id}")
@router.get("/progress/{upload_id}", tags=["语料接口"], description="语料上传进度接口")
async def get_progress(upload_id: str):
progress = upload_progress.get(upload_id)
if not progress:
Expand Down Expand Up @@ -115,7 +115,7 @@ def process_file(file_buffer: BytesIO, upload_id: str):
finally:
db.close()

@router.get("/data")
@router.get("/data", tags=["语料接口"], description="获取语料接口")
async def get_data():
db = SessionLocal()
records = get_records(db)
Expand All @@ -135,7 +135,7 @@ async def get_data():
]
})

@router.get("/info")
@router.get("/info", tags=["语料接口"], description="语料信息接口")
async def get_infos():
db = SessionLocal()
info_record = get_info(db)
Expand All @@ -162,7 +162,7 @@ class FilterRequest(BaseModel):
month: Optional[str] = None
name: Optional[str] = None

@router.post("/filter")
@router.post("/filter", tags=["语料接口"], description="筛选接口")
async def get_filter_data(filter_request: FilterRequest) -> Dict[str, Any]:
db = SessionLocal() # 创建数据库会话
try:
Expand Down Expand Up @@ -201,7 +201,7 @@ async def get_filter_data(filter_request: FilterRequest) -> Dict[str, Any]:
class NameRequest(BaseModel):
name: str

@router.post("/get-details-by-name")
@router.post("/get-details-by-name", tags=["语料接口"], description="搜索产品接口")
async def get_details_by_name(name_request: NameRequest) -> Dict[str, Any]:
db = SessionLocal()
try:
Expand Down

0 comments on commit 967bed2

Please sign in to comment.