|
|
@@ -1,32 +1,32 @@
|
|
|
-from pathlib import Path
|
|
|
-# import magic
|
|
|
-from fastapi import FastAPI, BackgroundTasks
|
|
|
-from starlette.responses import FileResponse
|
|
|
-# http://127.0.0.1:8000/
|
|
|
-# http://127.0.0.1:8000/docs
|
|
|
-# http://127.0.0.1:8000/redoc
|
|
|
-# http://127.0.0.1:8000/openapi.json
|
|
|
-app = FastAPI()
|
|
|
-
|
|
|
-data_path = Path("data")
|
|
|
-
|
|
|
-
|
|
|
-def write_notification(email: str, message=""):
|
|
|
- with open("log.txt", mode="w") as email_file:
|
|
|
- content = f"notification for {email}: {message}"
|
|
|
- email_file.write(content)
|
|
|
-
|
|
|
-
|
|
|
-@app.get("/")
|
|
|
-async def root():
|
|
|
- return {"ontologies": [file_path.name for file_path in data_path.glob("*")]}
|
|
|
-
|
|
|
-
|
|
|
-@app.get("/{name}")
|
|
|
-async def ontology(name: str, background_tasks: BackgroundTasks):
|
|
|
- file_path = data_path / Path(name)
|
|
|
- # mime = magic.Magic(mime=True)
|
|
|
- # media_type = mime.from_file(file_path)
|
|
|
- media_type = "text/xml"
|
|
|
- background_tasks.add_task(write_notification, name, message="some notification")
|
|
|
- return FileResponse(file_path, filename=file_path.name, media_type=media_type)
|
|
|
+from pathlib import Path
|
|
|
+# import magic
|
|
|
+from fastapi import FastAPI, BackgroundTasks
|
|
|
+from starlette.responses import FileResponse
|
|
|
+# http://127.0.0.1:8000/
|
|
|
+# http://127.0.0.1:8000/docs
|
|
|
+# http://127.0.0.1:8000/redoc
|
|
|
+# http://127.0.0.1:8000/openapi.json
|
|
|
+app = FastAPI()
|
|
|
+
|
|
|
+data_path = Path("data")
|
|
|
+
|
|
|
+
|
|
|
+def write_notification(name: str):
|
|
|
+ with open("access.log", mode="w") as log_file:
|
|
|
+ log_file.write(f"Accessed: {name}")
|
|
|
+
|
|
|
+
|
|
|
+@app.get("/")
|
|
|
+async def root():
|
|
|
+ ontologies = [file_path.name for file_path in data_path.glob("*")]
|
|
|
+ return {"ontologies": ontologies}
|
|
|
+
|
|
|
+
|
|
|
+@app.get("/{name}")
|
|
|
+async def ontology(name: str, background_tasks: BackgroundTasks):
|
|
|
+ file_path = data_path / Path(name)
|
|
|
+ # mime = magic.Magic(mime=True)
|
|
|
+ # media_type = mime.from_file(file_path)
|
|
|
+ media_type = "text/xml"
|
|
|
+ background_tasks.add_task(write_notification, name)
|
|
|
+ return FileResponse(file_path, filename=file_path.name, media_type=media_type)
|