pup-py commited on
Commit
a91e922
·
1 Parent(s): 2d82f50
Files changed (1) hide show
  1. main.py +3 -4
main.py CHANGED
@@ -8,7 +8,7 @@ import pandas as pd
8
 
9
  ROOT = Path("/home/user")
10
  app = FastAPI()
11
- app.mount(path="/", app=StaticFiles(directory=ROOT), name="HOME")
12
 
13
 
14
  @app.middleware("http")
@@ -16,7 +16,7 @@ async def file_system(request: Request, call_next):
16
  url = request.url
17
  if url.path.endswith("/"):
18
  return HTMLResponse(
19
- content=files_in_folder(url.path) #.lstrip("/"))
20
  )
21
  response = await call_next(request)
22
  return response
@@ -26,7 +26,6 @@ def files_in_folder(path: str):
26
  """List files to render as file index."""
27
 
28
  folder = ROOT / path
29
- # print(folder)
30
  path_glob = folder.glob("*")
31
  res = pd.DataFrame(
32
  [("..", "", "", True)]
@@ -44,7 +43,7 @@ def files_in_folder(path: str):
44
  ).sort_values(["folder"], ascending=False)
45
 
46
  res["path"] = res.apply(
47
- lambda x: f"<a href=/{path}{x.path}{'/' if x.folder else ''}>{x.path}</a>",
48
  axis=1,
49
  )
50
 
 
8
 
9
  ROOT = Path("/home/user")
10
  app = FastAPI()
11
+ app.mount(path="/files", app=StaticFiles(directory=ROOT), name="HOME")
12
 
13
 
14
  @app.middleware("http")
 
16
  url = request.url
17
  if url.path.endswith("/"):
18
  return HTMLResponse(
19
+ content=files_in_folder(url.path.lstrip("/files"))
20
  )
21
  response = await call_next(request)
22
  return response
 
26
  """List files to render as file index."""
27
 
28
  folder = ROOT / path
 
29
  path_glob = folder.glob("*")
30
  res = pd.DataFrame(
31
  [("..", "", "", True)]
 
43
  ).sort_values(["folder"], ascending=False)
44
 
45
  res["path"] = res.apply(
46
+ lambda x: f"<a href=/files/{path}{x.path}{'/' if x.folder else ''}>{x.path}</a>",
47
  axis=1,
48
  )
49