Last active
December 15, 2020 21:44
-
-
Save gwbischof/26aedaec7cf997bde2b1cd0def757612 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This serves a directory of static files. | |
It also tells you what files are available for a run. | |
""" | |
from fastapi import FastAPI | |
from fastapi.staticfiles import StaticFiles | |
import os | |
directory = os.environ["THUMBNAIL_DIRECTORY"] | |
os.makedirs(directory, exist_ok=True) | |
app = FastAPI() | |
@app.get("/{uid}") | |
async def get_files(uid: str): | |
run_directory = os.path.join(directory, uid) | |
if os.path.exists(run_directory): | |
return [f for f in os.listdir(run_directory) | |
if os.path.isfile(os.path.join(run_directory, f))] | |
else: | |
return [] | |
print("SERVING STATIC FILES:", directory) | |
app.mount('', StaticFiles(directory=directory)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment