1TSnakers commited on
Commit
3bbc765
·
verified ·
1 Parent(s): 3b49a1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -17
app.py CHANGED
@@ -11,35 +11,26 @@ STATUS_FILE = os.path.join(DATA_DIR, "status.json")
11
  INDEX_FILE = os.path.join(DATA_DIR, "index.json")
12
 
13
 
14
- EXCLUDE = {
15
- ".git",
16
- "__pycache__",
17
- ".gitattributes",
18
- "README.md",
19
- "Dockerfile",
20
- "requirements.txt",
21
- }
22
-
23
- def list_files(path="."):
24
  result = {}
25
 
26
  for item in os.listdir(path):
27
- if item in EXCLUDE:
28
  continue
29
 
30
  full = os.path.join(path, item)
31
 
32
  if os.path.isdir(full):
33
- sub = list_files(full)
34
  if sub:
35
  result[item] = sub
36
  else:
37
- result[item] = {
38
- "size": os.path.getsize(full)
39
- }
40
 
41
  return result
42
 
 
43
  @app.on_event("startup")
44
  def startup():
45
  if not os.path.exists(INDEX_FILE):
@@ -67,9 +58,9 @@ def get_chunk(chunk: int):
67
  path = os.path.join(DATA_DIR, f"chunk_{chunk}.json")
68
  if os.path.exists(path):
69
  return FileResponse(path, media_type="application/json")
70
- return JSONResponse({"error": "chunk not found"}, status_code=404)
71
 
72
 
73
  @app.get("/files")
74
  def files():
75
- return list_files(".")
 
11
  INDEX_FILE = os.path.join(DATA_DIR, "index.json")
12
 
13
 
14
+ def safe_files(path="."):
15
+ ignore = {"__pycache__", ".git"}
 
 
 
 
 
 
 
 
16
  result = {}
17
 
18
  for item in os.listdir(path):
19
+ if item in ignore:
20
  continue
21
 
22
  full = os.path.join(path, item)
23
 
24
  if os.path.isdir(full):
25
+ sub = safe_files(full)
26
  if sub:
27
  result[item] = sub
28
  else:
29
+ result[item] = {"size": os.path.getsize(full)}
 
 
30
 
31
  return result
32
 
33
+
34
  @app.on_event("startup")
35
  def startup():
36
  if not os.path.exists(INDEX_FILE):
 
58
  path = os.path.join(DATA_DIR, f"chunk_{chunk}.json")
59
  if os.path.exists(path):
60
  return FileResponse(path, media_type="application/json")
61
+ return JSONResponse({"error": "not found"}, status_code=404)
62
 
63
 
64
  @app.get("/files")
65
  def files():
66
+ return safe_files(".")