diff --git a/simple_server.py b/simple_server.py
index 656e957..1da740e 100644
--- a/simple_server.py
+++ b/simple_server.py
@@ -18,24 +18,38 @@ app.mount("/static", StaticFiles(directory="static"), name="static")
@app.get("/files", response_class=HTMLResponse)
async def list_files():
- files_html = ""
+ db_files_info = []
for root, _, files in os.walk(DIRECTORY):
for file in files:
- file_path = os.path.join(root, file)
- relative_path = os.path.relpath(file_path, DIRECTORY)
- try:
- file_size = os.path.getsize(file_path)
- # convert to GB
- file_size = file_size / (1024 * 1024 * 1024)
- files_html += f"""
-
- {relative_path} ({file_size:.3f} GB)
- Download
-
-
- """
- except Exception as e:
- files_html += f"Error accessing {relative_path}: {e}"
+ if file.endswith(".db"):
+ file_path = os.path.join(root, file)
+ relative_path = os.path.relpath(file_path, DIRECTORY)
+ try:
+ file_size = os.path.getsize(file_path)
+ creation_time = os.path.getctime(file_path)
+ db_files_info.append({
+ "relative_path": relative_path,
+ "file_size": file_size,
+ "creation_time": creation_time
+ })
+ except Exception as e:
+ # Log or handle error for specific file without breaking the list
+ print(f"Error accessing {file_path}: {e}")
+
+ # Sort files by creation time
+ db_files_info.sort(key=lambda x: x["creation_time"])
+
+ files_html = ""
+ for file_info in db_files_info:
+ # convert to GB
+ file_size_gb = file_info["file_size"] / (1024 * 1024 * 1024)
+ files_html += f"""
+
+ {file_info["relative_path"]} ({file_size_gb:.3f} GB)
+ Download
+
+
+ """
return f"""