pup-py commited on
Commit
2d82f50
·
1 Parent(s): 9dc6849

container and ..

Browse files
Files changed (1) hide show
  1. main.py +17 -4
main.py CHANGED
@@ -6,7 +6,7 @@ from pathlib import Path
6
  import pandas as pd
7
 
8
 
9
- ROOT = Path(".")
10
  app = FastAPI()
11
  app.mount(path="/", app=StaticFiles(directory=ROOT), name="HOME")
12
 
@@ -15,17 +15,22 @@ app.mount(path="/", app=StaticFiles(directory=ROOT), name="HOME")
15
  async def file_system(request: Request, call_next):
16
  url = request.url
17
  if url.path.endswith("/"):
18
- return HTMLResponse(content=files_in_folder(url.path.lstrip("/")))
 
 
19
  response = await call_next(request)
20
  return response
21
 
22
 
23
  def files_in_folder(path: str):
24
  """List files to render as file index."""
 
25
  folder = ROOT / path
26
- print(folder)
27
  path_glob = folder.glob("*")
28
  res = pd.DataFrame(
 
 
29
  [
30
  (
31
  f.name,
@@ -42,8 +47,16 @@ def files_in_folder(path: str):
42
  lambda x: f"<a href=/{path}{x.path}{'/' if x.folder else ''}>{x.path}</a>",
43
  axis=1,
44
  )
45
- return f"<h1>{folder}</h1><br>" + to_html_datatable(
 
46
  df=res.drop(columns="folder"),
47
  classes="display compact",
48
  showIndex=False,
49
  )
 
 
 
 
 
 
 
 
6
  import pandas as pd
7
 
8
 
9
+ ROOT = Path("/home/user")
10
  app = FastAPI()
11
  app.mount(path="/", app=StaticFiles(directory=ROOT), name="HOME")
12
 
 
15
  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
23
 
24
 
25
  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)]
33
+ +
34
  [
35
  (
36
  f.name,
 
47
  lambda x: f"<a href=/{path}{x.path}{'/' if x.folder else ''}>{x.path}</a>",
48
  axis=1,
49
  )
50
+
51
+ table = to_html_datatable(
52
  df=res.drop(columns="folder"),
53
  classes="display compact",
54
  showIndex=False,
55
  )
56
+
57
+ return f"""
58
+ <div style="width:50%; margin: 0 auto;">
59
+ <h1>{folder}</h1><br>
60
+ {table}
61
+ </div>
62
+ """