From 07e2ef879c4bc4d929dc808bc1da037f7bf03e4e Mon Sep 17 00:00:00 2001 From: Jojo Ortiz Date: Thu, 5 Oct 2023 15:05:17 -0700 Subject: [PATCH] add /file_exists/ route to check if file exists --- pykoi/application.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pykoi/application.py b/pykoi/application.py index bc69c51..44dd8f0 100644 --- a/pykoi/application.py +++ b/pykoi/application.py @@ -731,6 +731,18 @@ async def get_components( ] ) + @app.get("/file_exists/") + async def check_file_exists( + file_name: str, + user: Union[None, UserInDB] = Depends(self.get_auth_dependency()), + ): + try: + file_path = f"{os.getcwd()}/{file_name}" + file_exists = os.path.exists(file_path) + return {"log": f"Check if {file_name} exists succeeded.", "file_exists": file_exists, "status": "200"} + except Exception as ex: + return {"log": f"Check if {file_name} exists failed: {ex}", "status": "500"} + def create_data_route(id: str, data_source: Any): """ Create data route for the application.